From 238595b1d3f681d867f4cd46c0f0f51d010e500d Mon Sep 17 00:00:00 2001 From: Aaditya Date: Fri, 23 Jul 2021 10:18:50 +0530 Subject: [PATCH] Message changes and added new commands --- .../fetch_ipo_details.cpython-39.pyc | Bin 4680 -> 5382 bytes tasks/__pycache__/notify.cpython-39.pyc | Bin 1699 -> 1701 bytes tasks/fetch_ipo_details.py | 71 +++++++++++------- tasks/notify.py | 10 +-- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/tasks/__pycache__/fetch_ipo_details.cpython-39.pyc b/tasks/__pycache__/fetch_ipo_details.cpython-39.pyc index 21f287862d34b4723d501f6852242cb05b67bea8..d30d6c99f9d61e6e19ae8148546ee8974547e54d 100644 GIT binary patch delta 1960 zcmZ`)O>7%Q6yDkOde>{mNz)(dq@?4-DWpx~qymY$AfdLRR87-L6ro0iu};c0wjva0E2JJ^Bo0-75ByXJE){nU9JnDQ#KBj%BK1rG@n&o%5P?_oX=dJ=H*em| z_xbz6^}|_rV8GGfS3mpvyLU!E%KkB!f>9Eh0WB&ZkwZUi+|;TGGPZ(9>K3}8-7qRT zIY{vP_9kju%9iijDu|4e31zXlNeY_?X*ab8$%h)!U_2?uM0-P$+L=zJK~;s$oFxt{MX`xKWK!+PBfNQ9l{_=N_?m5|{ei*SR5Ra)kGkvDc9u!<_$debcWu(X*j zmbX@jx{)75Pzwv%ZdsFGHF4LNL-)iF#%u=8X1BDeUNuNkJT>OblUyT~m`mi2*bjAe z_P#x}W1N&@RSQS_nfUr-{0c;Wa{rSL@!1Mq4`aL*#y-KmS5s+6ly04A8nZZ1B`bGJ zgH__u%;G<{ef zLqqb@hfo1I`mpSa-%?|bFWUs=_JI$xCFCTGNRX?Kil0;89Pb!D4LYVDu2J?#XM4f0 zXfb*891Mw=A3C1wB;;!o?-?T-w_%cN zRdf?^9m=c`{g!@3Z=<%}Ld2-)>@YV-qEDWd9+mz%<_T`L^i8yhPHS&3w2hYDGIClw z!IKZHR)Uy04KS(DQfMnoDRc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36;HFr8f7qv9l3*G$20MqGxY3y*FMQ}7>vJma&s)X&xzm1j__j3^+oh#cZMz&#@3 z*pCG!B=_AasK_ho+lhn41$12;`~N?j31eLKI>Co(%l?v7)Sq@`UYvjAy^OoZ+NR^W z=v`Our@o$^!^3&RF*h}no+ZKk7t{ZcrT9bbqtaGAw@gRLp8k)jcmd2v@$5ylGWpfI zDQ59_32_0jf>=d7k3jD@rE+4VhIJm*KGrR%GgC7a^wM-n;)l|QN!xsc(1crD$wjG&C8_aA`6ahlixTtFQ*SZnq~;Z|040lGA(D)X94Pu;z}+`1=OUp0HO)QC;EYGUNcx$p3s}y6@|po0bJ%adJ^&L26O4UT!7O#3GOtx44QxevD5Bda{TWERdXEl&V)+l9^Ksu}67w HA)5&RPcBi) diff --git a/tasks/fetch_ipo_details.py b/tasks/fetch_ipo_details.py index 8db8fb3..0fe307d 100644 --- a/tasks/fetch_ipo_details.py +++ b/tasks/fetch_ipo_details.py @@ -10,11 +10,10 @@ def fetch_ipo_details(): # command description used in the "help" command commands = { '/start': 'Get used to the bot\n', - '/help': 'Lookup available commands \n', - 'Docs CompanyName ': 'Gives red herring prospectus and other documentation if issued for "Company Name" \n', - 'Subscribe CompanyName': ' allows you to get notifications regarding events in the IPOs ' - 'timeline \n', - '/Subscriptions': ' Show all companies you have subscribed to\n' + '/help': 'Lookup available commands \n', + '/notify': 'Opt for notifications on new IPOs\n', + '/list': 'List all IPOs\n', + '/contribute': 'Contribute to this project!\n' } # start the bot @@ -28,35 +27,18 @@ def send_welcome(message): if RedisConf.check_if_exists(redis_client, str(message.chat.id), REDIS_HASHES['users']) == 1: bot.send_message(message.chat.id, GREET_MESSAGE) bot.send_message(message.chat.id, "This is your first time using this bot!") - bot.send_message(message.chat.id, 'If you want to be notified whenever a new IPO is available, use the command `/notify`') + bot.send_message(message.chat.id, 'If you want to be notified whenever a new IPO is available, use the ' + 'command `/notify`') + bot.send_message(message.chat.id, '🖊 If you would like to see all IPOs, run the command /list') RedisConf.store_in_redis(redis_client, str(message.chat.id), str(message.chat.id), REDIS_HASHES['users']) command_help(message) else: print('{} is an existing user!'.format(message.chat.id)) bot.send_message(message.chat.id, '✋✋ Welcome Back! \n') - bot.send_message(message.chat.id, "To view commands: " + '/help \n Here are the current and upcoming IPOs') + bot.send_message(message.chat.id, "To view commands, run " + '/help') + bot.send_message(message.chat.id, '🖊 If you would like to see all IPOs, run the command /list') # bot.send_message(message.chat.id, IPOScraper.ipo_scraper()) - response, data = RedisConf.read_from_redis(r_client=redis_client, hash_name=REDIS_HASHES['current_ipo_details']) - if response == 1: - print('❌ Cannot fetch details from redis') - return - if not data: - print('❌ Cannot fetch details from redis') - return - - for i in range(len(data)): - item = data[i] - data_str = DATA_STR.format( - item['Issuer Company'], - item['Exchange'], - item['Open'], - item['Close'], - item['Lot Size'], - item['Issue Price (Rs)'], - item['Issue Price (Rs. Cr.)'] - ) - bot.send_message(message.chat.id, data_str) # this gives you the data. # Help @@ -105,7 +87,8 @@ def add_ipo(message): # logic # dummy message for testing bot.send_message(message.chat.id, - "you have subscribed to " + request) + "\n You will now recieve notifcations when events take place" + "you have subscribed to " + request) + "\n You will now recieve notifcations when events " \ + "take place " # if we cant do subscription then atleast we need to show the timeline for that IPO ,ill look into it" @bot.message_handler(commands=['Subscriptions']) @@ -125,6 +108,38 @@ def notify(message): RedisConf.store_in_redis(redis_client, str(message_id), str(message_id), REDIS_HASHES['notifications']) bot.send_message(message_id, 'Congratulations! 👏 You will now be notified whenever a new IPO is available!') + @bot.message_handler(commands=['list']) + def ipo_list(message): + response, data = RedisConf.read_from_redis(r_client=redis_client, hash_name=REDIS_HASHES['current_ipo_details']) + if response == 1: + print('❌ Cannot fetch details from redis') + return + if not data: + print('❌ Cannot fetch details from redis') + return + + for i in range(len(data)): + item = data[i] + data_str = DATA_STR.format( + item['Issuer Company'], + item['Exchange'], + item['Open'], + item['Close'], + item['Lot Size'], + item['Issue Price (Rs)'], + item['Issue Price (Rs. Cr.)'] + ) + bot.send_message(message.chat.id, data_str) + + @bot.message_handler(commands=['contribute']) + def contribute(message): + bot.send_message(message.chat.id, 'If you would like to contribute to this project, please visit this link: ' + 'https://github.com/aaditya2200/IPO-proj') + bot.send_message(message.chat.id, '📦 📦 We welcome all contributions! Please make sure to fork the repo and ' + 'make ' + 'changes, you can raise as pull request once everything is done.') + bot.send_message(message.chat.id, 'If there is anything we can change, let us know by sending an email. You ' + 'can find contact info in GitHub. 📧📨') print('👂 Listening for messages') bot.polling() diff --git a/tasks/notify.py b/tasks/notify.py index 5be0528..05d7953 100644 --- a/tasks/notify.py +++ b/tasks/notify.py @@ -3,9 +3,9 @@ """ from core.constants import REDIS_HASHES, DATA_STR -from scrapers.mybot import MyBot -from redis_conf import RedisConf from core.utils import return_as_datetime_object +from redis_conf import RedisConf +from scrapers.mybot import MyBot def notify(): @@ -43,9 +43,9 @@ def notify(): item['Issue Price (Rs. Cr.)'] ) for m_id in users_list: - if print_count == 0: - bot.send_message(m_id, '📈 Here are some IPOs that were listed today! If you want all listings,' - ' please run /start') + bot.send_message(m_id, '📈 Here are some IPOs that were listed today! If you want all listings,' + ' please run /start') + for m_id in users_list: bot.send_message(m_id, data_str) # print('✅ Notified {} users successfully'.format(len(users_list))) return