added discord helper.py

This commit is contained in:
2024-12-09 22:04:18 +01:00
parent a5b698f267
commit bb34ffebb6
3 changed files with 13 additions and 53 deletions
+5 -21
View File
@@ -1,19 +1,8 @@
import asyncio
import sys
import threading
import time
from src.discord_helper import run_discord, discord_client, send_message
from src.discord_helper import send_message
from src.mail.mail_confirmation import read_mails_and_find_confirmation_contacts
from src.pojo import ReserveResultPojo
def init_discord():
thread = threading.Thread(target=run_discord)
thread.start()
return thread
def create_message_from_item(item: ReserveResultPojo):
return f"Phone: {item.phone}\n" \
f"URL: {item.url}\n" \
@@ -22,20 +11,15 @@ def create_message_from_item(item: ReserveResultPojo):
f"Last Name: {item.last_name}\n"
async def main():
def main():
# initialize discord
_thread = init_discord()
print("init discord done")
# wait for discord to start up
# time.sleep(10)
_accepted_appointments = read_mails_and_find_confirmation_contacts()
if _accepted_appointments is not None and len(_accepted_appointments) > 0:
for item in _accepted_appointments:
asyncio.run_coroutine_threadsafe(send_message(create_message_from_item(item)), discord_client.loop)
_thread.join()
else:
raise Exception("Stop processing message")
for item in _accepted_appointments:
send_message(create_message_from_item(item))
if __name__ == '__main__':
asyncio.run(main())
main()