42 lines
1.2 KiB
Python
Executable File
42 lines
1.2 KiB
Python
Executable File
import asyncio
|
|
import sys
|
|
import threading
|
|
import time
|
|
|
|
from src.discord_helper import run_discord, discord_client, 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" \
|
|
f"Email: {item.mail}\n" \
|
|
f"First Name: {item.first_name}\n" \
|
|
f"Last Name: {item.last_name}\n"
|
|
|
|
|
|
async 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")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|