Last active
May 21, 2023 08:21
-
-
Save etrobot/26fa77be948968ab8142cf2368eb086f to your computer and use it in GitHub Desktop.
推特GPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import feedparser,markdown | |
import pandas as pd | |
import time | |
from datetime import datetime,timedelta | |
from dotenv import load_dotenv | |
from revChatGPT.V1 import Chatbot as ChatGPT | |
PROXY='http://127.0.0.1:7890' | |
load_dotenv(dotenv_path= '.env') | |
def getRss(user:str,hours:int=24): | |
url='https://rsshub.app/twitter/user/'+user | |
feeds=feedparser.parse(url) | |
df = pd.DataFrame(columns=['summary', 'published']) | |
for result in feeds['entries']: | |
if 'summary' not in result.keys() or result['summary'].startswith('Re @'): | |
continue | |
summary = result['summary'] | |
published = datetime.fromtimestamp(time.mktime(result['published_parsed'])) | |
df = df._append({'summary': summary, 'published': published},ignore_index=True) | |
df = df[(df['published'] >= datetime.now() - timedelta(hours=hours))] | |
return df | |
if __name__ == '__main__': | |
tweetUser='AiBreakfast' | |
feeds='\n'.join(getRss(tweetUser,48)['summary']) | |
print(len(feeds),feeds) | |
prompt="'''%s'''"%feeds+"organize the to a markdown post in Chinese" | |
chatgptBot = ChatGPT(config={"access_token": os.environ['CHATGPT'], 'proxy': PROXY}) | |
reply_text=None | |
for data in chatgptBot.ask(prompt): | |
convId = data['conversation_id'] | |
reply_text = data["message"] | |
try: | |
chatgptBot.delete_conversation(convId) | |
except: | |
pass | |
print(reply_text) | |
html = markdown.markdown(reply_text) | |
# 将 HTML 写入文件 | |
with open(tweetUser+".html", "w", encoding="utf-8") as f: | |
f.write(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment