forked from Chrisischris/trade-notifier-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (34 loc) · 1.19 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
from botUser import BotUser
from discord import Webhook, RequestsWebhookAdapter
from const import BOT_USER_PATH
import asyncio
import os
def main():
botUser = loadBotUser()
asyncio.get_event_loop().run_until_complete(botUser.stream_account_activity())
def getNewBotUser():
accountID = input("Enter your TDA Account ID: ")
webhookURL = input("Enter your webhook url: ")
apiKey = input("Enter your TDA API Key: ")
webhook = Webhook.from_url(webhookURL, adapter=RequestsWebhookAdapter())
botUser = BotUser(webhook, accountID, apiKey)
saveBotUser(botUser)
return botUser
def loadBotUser():
if os.path.exists(BOT_USER_PATH):
botUserFile = open(BOT_USER_PATH, 'r')
info = botUserFile.read().split(',')
webhook = Webhook.from_url(info[0], adapter=RequestsWebhookAdapter())
botUser = BotUser(webhook, info[1], info[2])
botUserFile.close()
else:
botUser = getNewBotUser()
return botUser
def saveBotUser(botUser):
os.makedirs(os.path.dirname(BOT_USER_PATH), exist_ok=True)
botUserFile = open(BOT_USER_PATH, 'w+')
botUserFile.write(botUser.webhook.url + ',' + botUser.accountID + ',' + botUser.apiKey + ',')
botUserFile.close()
return
if __name__ == "__main__":
main()