2022-04-05 08:07:03 +00:00
|
|
|
"""
|
|
|
|
script for regularly sending updates on shares and news based on user interval
|
|
|
|
"""
|
|
|
|
__author__ = "Florian Kellermann, Linus Eickhoff"
|
|
|
|
__date__ = "05.04.2022"
|
|
|
|
__version__ = "0.0.1"
|
2022-04-05 10:38:20 +00:00
|
|
|
__license__ = "None"
|
|
|
|
|
2022-04-05 12:00:33 +00:00
|
|
|
from shares.share_fetcher import get_share_price
|
|
|
|
import time
|
2022-04-05 13:07:06 +00:00
|
|
|
import datetime
|
2022-04-05 12:00:33 +00:00
|
|
|
from bot import bot
|
|
|
|
import sys
|
2022-04-05 13:07:06 +00:00
|
|
|
from multiprocessing import Process
|
2022-04-05 12:00:33 +00:00
|
|
|
|
2022-04-05 10:38:20 +00:00
|
|
|
'''
|
|
|
|
* * * * * code
|
|
|
|
┬ ┬ ┬ ┬ ┬
|
|
|
|
│ │ │ │ │
|
2022-04-05 12:00:33 +00:00
|
|
|
│ │ │ │ └──── weekday (0->Monday, 7->Sunday)
|
2022-04-05 10:38:20 +00:00
|
|
|
│ │ │ └────── Month (1-12)
|
|
|
|
│ │ └──────── Day (1-31)
|
|
|
|
│ └────────── Hour (0-23)
|
|
|
|
└──────────── Minute (0-59)
|
|
|
|
|
|
|
|
example 0 8 * * * -> daily update at 8am
|
|
|
|
'''
|
2022-04-05 12:00:33 +00:00
|
|
|
|
2022-04-05 12:12:12 +00:00
|
|
|
user_ids = []
|
|
|
|
user_crontab = []
|
|
|
|
|
2022-04-05 12:00:33 +00:00
|
|
|
def main_loop():
|
|
|
|
""" main loop for regularly sending updates
|
|
|
|
:raises: none
|
|
|
|
|
|
|
|
:rtype: none
|
|
|
|
"""
|
|
|
|
|
2022-04-05 13:07:06 +00:00
|
|
|
current_time_datetime = datetime.datetime.now()
|
|
|
|
|
|
|
|
print(time.ctime()) # Debug
|
|
|
|
|
2022-04-05 13:12:51 +00:00
|
|
|
p1 = Process(target= update_crontab, args=(current_time_datetime, ))
|
2022-04-05 13:07:06 +00:00
|
|
|
p1.start()
|
|
|
|
p3 = Process(target= update_based_on_crontab, args=(current_time_datetime, ) )
|
|
|
|
p3.daemon = True
|
|
|
|
p3.start()
|
|
|
|
p1.join()
|
|
|
|
p3.terminate()
|
|
|
|
p1.terminate()
|
|
|
|
|
|
|
|
|
|
|
|
def update_crontab(pCurrent_Time):
|
|
|
|
""" Updating crontab lists every hour
|
|
|
|
:type pCurrent_Time: time when starting crontab update
|
|
|
|
:param pCurrent_Time: datetime
|
|
|
|
|
|
|
|
:raises: none
|
|
|
|
|
|
|
|
:rtype: none
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Update user info now
|
|
|
|
|
|
|
|
print('in update_crontab')
|
|
|
|
|
|
|
|
user_ids.clear() # Example for me (Florian Kellermann)
|
|
|
|
user_crontab.clear()
|
|
|
|
user_ids.append(1770205310)
|
|
|
|
user_crontab.append("0 8 * * *")
|
|
|
|
|
|
|
|
while True:
|
|
|
|
time_difference = datetime.datetime.now() - pCurrent_Time
|
|
|
|
if float(str(time_difference).split(':')[0]) >=1:
|
|
|
|
update_crontab(datetime.datetime.now())
|
2022-04-05 13:12:51 +00:00
|
|
|
break
|
2022-04-05 13:07:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def update_based_on_crontab(pCurrent_Time):
|
|
|
|
current_time_ctime = time.ctime()
|
|
|
|
for i in range(len(user_crontab)):
|
|
|
|
print('tbd')
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep(60)
|
|
|
|
|
2022-04-05 12:12:12 +00:00
|
|
|
|
2022-04-05 12:00:33 +00:00
|
|
|
|
|
|
|
def send_to_user(pText, pUser_id = 1770205310):
|
|
|
|
|
|
|
|
""" Send message to user
|
|
|
|
:type pText: string
|
|
|
|
:param pText: Text to send to user
|
|
|
|
|
|
|
|
:type pUser_id: int
|
|
|
|
:param pUser_id: user to send to. per default me (Florian Kellermann)
|
|
|
|
|
|
|
|
:raises: none
|
|
|
|
|
|
|
|
:rtype: none
|
|
|
|
"""
|
|
|
|
bot.send_message(chat_id=pUser_id, text=pText)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print('This script shall not be run directly. Starting main_loop for debugging purposes.')
|
|
|
|
try:
|
|
|
|
main_loop()
|
|
|
|
sys.exit(-1)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("Ending")
|
|
|
|
sys.exit(-1)
|