-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
164 lines (128 loc) · 5.83 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import classes
import startup
from apscheduler.schedulers.background import BackgroundScheduler
from dotenv import load_dotenv
load_dotenv('/.env') # Fetch the environment variables
options = ["1. User Management",
"2. Ticker Management",
"3. Alert Preferences",
"4. Generate Report"]
tickerOptions = [ "1. Add a ticker",
"2. Modify a ticker",
"3. Delete a ticker"]
user = startup.fetchUser()
communicator = classes.APICommunicator(user.tickers, user)
scheduler = BackgroundScheduler(timezone="America/Toronto")
scheduler.add_job(communicator.FetchSentiment, trigger='cron', hour='8,15', minute='30')
scheduler.add_job(communicator.FetchWSBList, trigger='cron', hour='8,15', minute='30')
scheduler.start()
# communicator.FetchSentiment() # Uncomment these to test instantly.
# communicator.FetchWSBList() # Uncomment these to test instantly.
app_running = True
while(app_running):
print("\nChoose from the following options: ")
for o in options:
print(o)
option = input("\nEnter your choice here or press f to disable Sentilert: ")
if option == "f":
option = input("\nAre you sure? This will disable alerts and sentiment checks (y/n): ")
if option == "y": app_running = False
# User Management
elif option == "1":
print("\nEnter you updated phone number and email address here.")
confirmed = False
while(not confirmed):
phone = input("\nPhone Number: ")
email = input("\nEmail Address: ")
user.userEmail = email
user.userPhoneNumber = phone
print("\nPlease confirm that these details are correct")
print(user)
option = input("\nConfirm (y/n): ")
if option == 'y':
user.UpdateUser()
confirmed = True
# Ticker Management
elif option == '2':
subMenu = True
while(subMenu):
print("\n")
for o in tickerOptions:
print(o)
option = input("\nEnter your choice here or press m to return to the main menu: ")
if option == "m":
subMenu = False
# Add a ticker
elif option == "1":
confirmed = False
while(not confirmed):
user.PrintTickers()
if len(user.tickers) > 10:
print("\nYou've exceeded the limit of tracked tickers. Please delete a ticker if you wish to add a new one\n")
break
symbol = input("\nTicker symbol: ")
lowerSentiment = input("\nLower sentiment tolerance: ")
upperSentiment = input("\nUpper sentiment tolerance: ")
WSBAlerts = input("\nEnable Wall Street Bets emergency notifications for this ticker? (y/n): ")
ticker = classes.TickerObserver(symbol, lowerSentiment, upperSentiment, WSBAlerts)
print("\nPlease confirm that these details are correct")
print(ticker)
option = input("\nConfirm (y/n): ")
if option == 'y':
ticker.SaveTicker()
user.AddTicker(ticker)
confirmed = True
# Modify a ticker
elif option == "2":
confirmed = False
while(not confirmed):
user.PrintTickers()
symbol = input("\nEnter the ticker symbol you wish to update: ")
lowerSentiment = input("\nLower sentiment tolerance: ")
upperSentiment = input("\nUpper sentiment tolerance: ")
WSBAlerts = input("\nEnable Wall Street Bets emergency notifications for this ticker? (y/n): ")
ticker = classes.TickerObserver(symbol, lowerSentiment, upperSentiment, WSBAlerts)
print("\nPlease confirm that these details are correct")
print(ticker)
option = input("\nConfirm (y/n): ")
if option == 'y':
ticker.ModifySentiment()
ticker.UpdateAlerts()
confirmed = True
# Delete a ticker
elif option == "3":
confirmed = False
while(not confirmed):
user.PrintTickers()
symbol = input("\nEnter the ticker symbol you wish to delete: ")
ticker = user.tickers[symbol]
print("\nPlease confirm that this is the ticker you wish to delete")
print(ticker)
option = input("\nConfirm (y/n): ")
if option == 'y':
user.DeleteTicker(ticker)
confirmed = True
# Alert Preferences
elif option == "3":
print("\nEnter your updated alert preferences here")
confirmed = False
while(not confirmed):
smsAlerts = input("\nRecieve SMS alerts? (y/n): ")
emailAlerts = input("\nRecieve email alerts? (y/n): ")
alertPreferences = {
'phone': smsAlerts,
'email': emailAlerts
}
user.alertPreferences = alertPreferences
print("\nPlease confirm that these details are correct")
print(user)
option = input("\nConfirm (y/n): ")
if option == 'y':
user.UpdateUser()
confirmed = True
# Generate a report
elif option == "4":
user.PrintTickers()
symbol = input("\nEnter the ticker symbol you wish to generate a report for: ")
ticker = user.tickers[symbol]
ticker.GenerateReport()