Removed all hard coded links #189

Merged
FlorianKellermann merged 1 commits from bot into main 2022-05-12 16:20:39 +00:00
2 changed files with 16 additions and 16 deletions

View File

@ -32,7 +32,7 @@ load_dotenv(dotenv_path='.env') # load environment variables
bot_version = "3.0.1" # version of bot bot_version = "3.0.1" # version of bot
# create api handler # create api handler
api_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env vars. api_handler = API_Handler(str(os.getenv("API_URL")), str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env vars.
print("Webserver Token: " + str(api_handler.token)) print("Webserver Token: " + str(api_handler.token))
bot = telebot.TeleBot(os.getenv('BOT_API_KEY')) bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
@ -50,7 +50,7 @@ def send_start(message):
""" """
bot.reply_to(message, "Welcome to this share bot project. \ bot.reply_to(message, "Welcome to this share bot project. \
\nType /help to get information on what this bot can do. \ \nType /help to get information on what this bot can do. \
\nAlso see https://gruppe1.testsites.info \ \nAlso see " + os.getenv("WEBSITE_URL") + " \
to start configuring your bot") to start configuring your bot")
@ -78,7 +78,7 @@ def send_help(message):
:rtype: none :rtype: none
""" """
bot.reply_to(message, bot.reply_to(message,
"/id or /auth get your user id\n/shares get update on interesting shares\n/setAdmin set admin rights of user (ADMIN)\n/users see all users. (ADMIN)\n/me get my user info\n/news get top article for each keyword.\n/allnews get all news (last 7 days)\n/keywords get all your keywords\n/addkeyword add a keyword\n/removekeyword remove a keyword\n/transactions get all transactions\n/newtransaction create new transaction\n/share get price of specific share\n/portfolio see own stock portfolio\n/removeshare removes share from portfolio\n/interval get update interval\n/setinterval set update interval\n For further details see https://gruppe1.testsites.info") "/id or /auth get your user id\n/shares get update on interesting shares\n/setAdmin set admin rights of user (ADMIN)\n/users see all users. (ADMIN)\n/me get my user info\n/news get top article for each keyword.\n/allnews get all news (last 7 days)\n/keywords get all your keywords\n/addkeyword add a keyword\n/removekeyword remove a keyword\n/transactions get all transactions\n/newtransaction create new transaction\n/share get price of specific share\n/portfolio see own stock portfolio\n/removeshare removes share from portfolio\n/interval get update interval\n/setinterval set update interval\n For further details see " + os.getenv("WEBSITE_URL"))
@bot.message_handler(commands=['users', 'Users']) # /users -> sending all users @bot.message_handler(commands=['users', 'Users']) # /users -> sending all users
@ -170,7 +170,7 @@ def send_user(message):
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
user_data = api_handler.get_user(user_id) user_data = api_handler.get_user(user_id)
if not user_data or user_data == None: # true if user is not registered if not user_data or user_data == None: # true if user is not registered
bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info") bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on " + os.getenv("WEBSITE_URL"))
return return
username = user_data['username'] username = user_data['username']
email = user_data['email'] email = user_data['email']
@ -190,7 +190,7 @@ def send_id(message):
:rtype: none :rtype: none
""" """
answer = 'Your ID/Authentication Code is: [' + str(message.from_user.id) + ']. Enter this code in the settings on https://gruppe1.testsites.info to get updates on your shares.' answer = 'Your ID/Authentication Code is: [' + str(message.from_user.id) + ']. Enter this code in the settings on ' + os.getenv("WEBSITE_URL") + ' to get updates on your shares.'
bot.reply_to(message, answer) bot.reply_to(message, answer)
@ -219,7 +219,7 @@ def update_for_user(message):
my_portfolio = p_my_handler.get_user_portfolio(p_user_id) my_portfolio = p_my_handler.get_user_portfolio(p_user_id)
if my_portfolio == None: # true if user is not registered if my_portfolio == None: # true if user is not registered
bot.send_message(chat_id=p_user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') bot.send_message(chat_id=p_user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL"))
return return
my_user = p_my_handler.get_user(p_user_id) my_user = p_my_handler.get_user(p_user_id)
@ -240,7 +240,7 @@ def update_for_user(message):
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {amounts}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR' my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {amounts}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2") bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2")
else: else:
send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id) send_to_user("No shares found for your account. Check " + os.getenv("WEBSITE_URL") + " to change your settings and add shares.", pUser_id=p_user_id)
def send_to_user(pText, pUser_id): def send_to_user(pText, pUser_id):
@ -294,7 +294,7 @@ def send_all_news(message):
keywords = api_handler.get_user_keywords(user_id) # get keywords of user keywords = api_handler.get_user_keywords(user_id) # get keywords of user
if keywords == None: # true if user is not registered if keywords == None: # true if user is not registered
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL"))
return return
if not keywords: # true if user is registered but does not have any keywords if not keywords: # true if user is registered but does not have any keywords
@ -330,7 +330,7 @@ def send_news(message):
keywords = api_handler.get_user_keywords(user_id) # get keywords of user keywords = api_handler.get_user_keywords(user_id) # get keywords of user
if keywords == None: # true if user is not registered if keywords == None: # true if user is not registered
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL"))
return return
if not keywords: # true if user is registered but does not have any keywords if not keywords: # true if user is registered but does not have any keywords
@ -417,7 +417,7 @@ def send_keywords(message):
keywords = api_handler.get_user_keywords(user_id) # get keywords of user keywords = api_handler.get_user_keywords(user_id) # get keywords of user
if keywords == None: # true if user is not registered if keywords == None: # true if user is not registered
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL"))
return return
if not keywords: # true if user is registered but does not have any keywords if not keywords: # true if user is registered but does not have any keywords
@ -513,7 +513,7 @@ def send_interval(message):
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
user_data = api_handler.get_user(user_id) # get cron interval of user (stored in user data) user_data = api_handler.get_user(user_id) # get cron interval of user (stored in user data)
if user_data == None: # true if user is not registered in DB if user_data == None: # true if user is not registered in DB
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval') bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL") + ' and set an interval with /setinterval')
return return
else: # send interval else: # send interval
interval = str(user_data['cron']) # get cron from user data interval = str(user_data['cron']) # get cron from user data
@ -538,7 +538,7 @@ def send_transactions(message):
transactions = api_handler.get_user_transactions(user_id) # get transactions of user transactions = api_handler.get_user_transactions(user_id) # get transactions of user
if transactions == None: # true if user does not exist if transactions == None: # true if user does not exist
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL"))
return return
if not transactions: # true if user has no transactions if not transactions: # true if user has no transactions
@ -571,9 +571,9 @@ def send_shares(message):
shares = api_handler.get_user_shares(user_id) # get shares of user shares = api_handler.get_user_shares(user_id) # get shares of user
if shares == None: # true if user does not exist if shares == None: # true if user does not exist
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL"))
elif not shares: # true if user has no shares elif not shares: # true if user has no shares
bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on ' + os.getenv("WEBSITE_URL"))
else: else:
for element in shares: for element in shares:
bot.send_message(chat_id=user_id, text=share_fetcher.get_share_information_markdown(element), parse_mode="MARKDOWNV2") bot.send_message(chat_id=user_id, text=share_fetcher.get_share_information_markdown(element), parse_mode="MARKDOWNV2")

View File

@ -46,7 +46,7 @@ def start_updater():
print("Bot updates started") print("Bot updates started")
my_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) my_handler = API_Handler(os.getenv("API_URL"), str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD")))
update_crontab(my_handler) update_crontab(my_handler)
@ -149,7 +149,7 @@ def update_for_user(p_user_id, p_my_handler):
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(share_amounts[i])}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR' my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(share_amounts[i])}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2") bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2")
else: else:
send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id) send_to_user("No shares found for your account. Check " + os.getenv("WEBSITE_URL") + " to change your settings and add shares.", pUser_id=p_user_id)
if len(shares) != 0: # Send updates on watchlist shares if existing if len(shares) != 0: # Send updates on watchlist shares if existing
send_to_user("Your watchlist shares:", pUser_id=p_user_id) send_to_user("Your watchlist shares:", pUser_id=p_user_id)