-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdin_stdout.py
More file actions
101 lines (67 loc) · 2.55 KB
/
stdin_stdout.py
File metadata and controls
101 lines (67 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import sys, re
import os
import csv
from bs4 import BeautifulSoup
import requests
sys.path.append(os.path.join(os.path.dirname(os.path.join(os.path.dirname(__file__)))))
# from File.FileManager import *
# regex = sys.argv[0]
# for line in sys.stdin:
# if re.search(regex, line):
# sys.stdout.write(line)
# count = 0
# for line in sys.stdin:
# count += 1
# print(count)
# a = input()
# for i in range(a):
# b, c = map(int, input().split(" "))
# print("Case: #{0}: {1}".format((i + 1), b + c))
print("Tab Delimited Stock Price")
def process(date, symbol, price):
print(date, symbol, price)
with open("tab_delimited_stock_prices.txt", 'r', encoding='utf8',newline='') as f:
tab_reader = csv.reader(f, delimiter="\t")
print("Tab Reader -> {0}".format(tab_reader))
for row in tab_reader:
date = row[0]
symbol = row[1]
closing_price = float(row[2])
process(date, symbol, closing_price)
print()
with open("colon_delimited_stock_prices.txt", "r", encoding='utf8', newline='') as f:
colon_reader = csv.DictReader(f, delimiter=':')
print("Colon Delimited -> {0}".format(colon_reader))
for dict_row in colon_reader:
date = dict_row["date"]
symbol = dict_row["symbol"]
closing_price = float(dict_row["closing_price"])
process(date, symbol, closing_price)
print()
todays_prices = {'AAPL': 90.91, 'MSFT': 41.68, 'FB': 64.5}
for price in todays_prices:
print(price)
with open("comma_delimited_stock_prices.txt", 'w', encoding="utf8", newline='') as f:
csv_writer = csv.writer(f, delimiter=',')
print("CSV-Writer -> {0}".format(csv_writer))
for stock, price in todays_prices.items():
csv_writer.writerow([stock, price])
url = (
"https://raw.githubsercontent.com/"
"joelgrus/data/master/getting-data.html"
)
print("URL -> {0}".format(url))
html = requests.get(url).text
print("HTML -> {0}".format(html))
soup = BeautifulSoup(requests.get(url).text, "html5lib")
print("Soup -> {0}".format(soup))
first_paragraph = soup.find("p")
first_paragraph_text = soup.find("p").get()
first_paragraph_words = soup.get_text().split()
# first_paragraph_words = soup.p.text.split()
print("First Paragraph -> {0}".format(first_paragraph))
print("First Paragraph Text -> {0}".format(first_paragraph_text))
print("First Paragraph words -> {0}".format(first_paragraph_words))
first_paragraph_id = soup.p['id']
first_paragraph_id2 = soup.p.get('id')
print("First Paragraph_id -> {0}\nFirst Paragraph_id2 -> {1}".format(first_paragraph_id, first_paragraph_id2))