-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
36 lines (29 loc) · 1.06 KB
/
test.py
File metadata and controls
36 lines (29 loc) · 1.06 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
import requests
import json
import config
from datetime import datetime
from win10toast import ToastNotifier
import time
import logging
import config
import os
logging.basicConfig(
level=logging.INFO,
handlers=[ logging.FileHandler(config.LOG_PATH), logging.StreamHandler() ],
format='%(asctime)s:%(levelname)s: %(message)s',
)
def get_price():
url = "https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/get-detail"
querystring = {"region":config.STOCK_REGION,"symbol":config.STOCK_SYMBOL}
headers = {
'x-rapidapi-host': "apidojo-yahoo-finance-v1.p.rapidapi.com",
'x-rapidapi-key': os.getenv('API_KEY')
}
response = requests.request("GET", url, headers=headers, params=querystring)
p = response.json()["financialData"]["currentPrice"]["raw"]
logging.info("Stock Price is {}".format(p))
return p
def notify(price):
toaster = ToastNotifier()
toaster.show_toast("{} Stock Price Changed!".format(config.STOCK_SYMBOL),"THE PRICE IS {}".format(price),icon_path=config.ICON_PATH,duration=15)
price = get_price()