-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_newsbot.py
46 lines (34 loc) · 1.57 KB
/
code_newsbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from EdgeGPT.EdgeUtils import ImageQuery, Query, Path, Cookie
from EdgeGPT.EdgeGPT import Chatbot, ConversationStyle
from datetime import datetime
from dotenv import load_dotenv
import telebot
import asyncio
import time
import json
import os
load_dotenv()
telegram_bot_username = os.getenv('telegram_bot_username')
cookies = json.loads(open("cookies.json", encoding="utf-8").read())
async def main():
bot_ai = await Chatbot.create(cookies = cookies)
bot_telegram = telebot.TeleBot(telegram_bot_username, parse_mode='MARKDOWN')
while True:
prompt = 'Give me top 5 news of the Netherlands for the past 24 hours, and explain each one in 2-3 sentences.'
if prompt.lower() != 'exit':
response = await bot_ai.ask(prompt = prompt, conversation_style = ConversationStyle.precise, simplify_response = True)
response = response['text'].replace('^1^', '')
response = response.split('Would you', 1)[0]
response = response.split('Is there', 1)[0]
time_response = datetime.now().strftime("%H:%M:%S")
conversation = f"{time_response} Response:\n\n{response}\n\n"
with open("news_nl.md", "a", encoding="utf-8") as file: file.write(conversation)
q=ImageQuery("Meerkats at a garden party in Devon", cookie_file = cookies)
Query.image_dirpath = Path("/output")
bot_telegram.send_message(chat_id = "@timesofnl", text = response)
else:
await bot_ai.close()
break
time.sleep(1200)
if __name__ == "__main__":
asyncio.run(main())