-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen.py
More file actions
56 lines (37 loc) · 1.07 KB
/
gen.py
File metadata and controls
56 lines (37 loc) · 1.07 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
import random
import time
import csv
from datetime import datetime
import yfinance as yf
import asyncio
def genFile():
fields = ["stock", "x", "y"]
with open ('stock.csv', 'w') as csv_data:
writer = csv.DictWriter(csv_data, fieldnames=fields)
writer.writeheader()
def generate(ticker):
fields = ["stock", "x", "y"]
stock = yf.Ticker(ticker)
price = float(stock.info['ask'])
now = datetime.now()
x = now.strftime("%H:%M:%S")
y = price
with open('stock.csv', 'a') as csv_data:
price = float(stock.info['ask'])
now = datetime.now()
writer = csv.DictWriter(csv_data, fieldnames=fields)
data = {
"stock": stock.info['symbol'],
"x": x,
"y": y
}
writer.writerow(data)
print(stock.info['symbol'], x, y)
x = now.strftime("%H:%M:%S")
y = price
if __name__ == "__main__":
try:
s = "MSFT"
generate(s)
except KeyboardInterrupt:
exit()