-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (59 loc) · 2.08 KB
/
main.py
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
import os
import requests
import datetime
from yahoo_fin import stock_info as si
API_KEY = os.environ['API_KEY']
LIMIT_NEWS = '100'
CLIENT_ID = os.getenv('CLIENT_ID')
PERM = '8'
Invite_URL = f'https://discord.com/api/oauth2/authorize?client_id={CLIENT_ID}&permissions={PERM}&scope=bot%20applications.commands'
def getPrice(ticker):
price = '0'
try:
price = si.get_live_price(ticker)
except:
pass
return price
def getDetails(ticker):
Detail_URL = f'https://api.polygon.io/v1/meta/symbols/{ticker}/company?&apiKey={API_KEY}'
Data = requests.get(Detail_URL).json()
Logo = ''
URL = ''
Description = ''
Name = ''
Industry = ''
Symbol = ''
try:
Logo = Data['logo']
URL = Data['url']
Description = Data['description']
Name = Data['name']
Industry = Data['industry']
Symbol = Data['symbol']
except:
pass
return Logo, URL, Description, Name, Industry, Symbol
def getNews(ticker):
today = datetime.datetime.utcnow().date()
yesterday = today - datetime.timedelta(days=3)
API_URL_NEWS = f'https://api.polygon.io/v2/reference/news?limit={LIMIT_NEWS}&order=descending&sort=published_utc&ticker={ticker}&published_utc.gte={yesterday}&apiKey={API_KEY}'
Data = requests.get(API_URL_NEWS).json()
List_Description = []
List_URL_Article = []
List_Title = []
List_Image_URL = []
for i in range(int(LIMIT_NEWS)):
try:
newsDes = Data['results'][i]['description']
newsURL = Data['results'][i]['article_url']
newsTitle = Data['results'][i]['title']
image = Data['results'][i]['image_url']
List_Description.append(newsDes)
List_URL_Article.append(newsURL)
List_Title.append(newsTitle)
List_Image_URL.append(image)
except:
pass
return List_Description, List_URL_Article, List_Title, List_Image_URL
def getChart(ticker):
pass