diff --git a/read_confirmation_emails.py b/read_confirmation_emails.py index 5c74cb8..d35fe37 100755 --- a/read_confirmation_emails.py +++ b/read_confirmation_emails.py @@ -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() diff --git a/src/discord_helper.py b/src/discord_helper.py index 213be35..f42876c 100644 --- a/src/discord_helper.py +++ b/src/discord_helper.py @@ -1,38 +1,14 @@ -# This example requires the 'message_content' intent. -import asyncio +import requests -import discord - -intents = discord.Intents.default() -intents.messages = True - -discord_client = discord.Client(intents=intents) +DISCORD_SERVER_URL = "http://127.0.0.1:9000/discord/send" -@discord_client.event -async def on_ready(): - print(f'We have logged in as {discord_client.user}') - # await send_message("我是机器人") - - -@discord_client.event -async def on_message(message): - pass - - -async def send_message(message): - print("will call send") - channel = discord_client.get_channel(1149373754053496866) - await channel.send(message) - - -def run_discord(): - _token = 'MTMxNTI5OTkxODk4MTg5MDExOQ.GKA6lA.wHM4fTFT1luVrptK4YxEtFn_WhUnavtIrla_TE' - discord_client.run(_token) +def send_message(message: str): + headers = {"Authorization": "Bearer 97e36f7e-340e-4c02-b329-9415faee38c3", "Content-Type": "application/json"} + message_data = {"message": message} + _res = requests.post(DISCORD_SERVER_URL, json=message_data, headers=headers) + print(_res.text) if __name__ == '__main__': - # loop = asyncio.get_event_loop() - # loop.run_until_complete(client.start()) - # client.start() - asyncio.run(run_discord()) + send_message('测试') diff --git a/src/person_name/.~contact_list_2024-09-26.xlsx b/src/person_name/.~contact_list_2024-09-26.xlsx deleted file mode 100644 index 4c491c6..0000000 Binary files a/src/person_name/.~contact_list_2024-09-26.xlsx and /dev/null differ