-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (26 loc) · 1.37 KB
/
main.py
File metadata and controls
31 lines (26 loc) · 1.37 KB
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
import praw
import os
import time
import openai
from dotenv import load_dotenv
load_dotenv()
reddit = praw.Reddit(client_id=os.getenv('REDDIT_CLIENT_ID'),
client_secret=os.getenv('REDDIT_CLIENT_SECRET'),
username=os.getenv('REDDIT_USERNAME'),
password=os.getenv('REDDIT_PASSWORD'),
user_agent=('user_agent'))
subreddit = reddit.subreddit('r/web3')
openai.api_key = os.getenv('OPENAI_API_KEY')
with open('keywords/selected_keywords.txt', 'r') as f:
selected_keywords = [line.strip() for line in f]
for comment in subreddit.stream.comments(skip_existing=True):
if any(keyword in comment.body for keyword in selected_keywords):
print("Commentaire trouvé avec les mots-clés suivants : {}".format(selected_keywords))
response = openai.Completion.create(engine="text-davinci-002",
prompt=comment.body,
max_tokens=150)
reply_text = response.choices[0].text.format("[example.com](https://example.com/)")
reply_text += " Je t'invite à essayer un des templates de [example]({}).".format("[example.com](https://example.com/)")
comment.reply(reply_text)
print("Réponse envoyée pour le commentaire {}.".format(comment.id))
time.sleep(10)