-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (34 loc) · 1.77 KB
/
main.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
import praw
from discord_webhook import DiscordWebhook, DiscordEmbed
import time
from configparser import ConfigParser
conf = ConfigParser()
conf.read('conf.ini')
reddit = praw.Reddit(client_id=conf.get('reddit', 'client_id'),
client_secret=conf.get('reddit', 'client_secret'),
refresh_token=conf.get('reddit', 'refresh_token'),
user_agent=conf.get('reddit', 'user_agent'))
posts = {}
def main():
for submission in reddit.subreddit("pewdiepiesubmissions").hot():
if not submission.over_18 and (submission.score >= 15000):
if submission.id not in posts:
webhook = DiscordWebhook(url=conf.get('discord', 'webhook_url'))
embed = DiscordEmbed(color=0xf9013f)
embed.add_embed_field(name=submission.title, value=f'[link](https://reddit.com{submission.permalink})')
embed.set_author(name=submission.author.name, url='https://reddit.com/user/' + submission.author.name,
icon_url=submission.author.icon_img)
embed.set_image(url=submission.url)
embed.set_footer(text=f'👍 {submission.score} | 💬 {submission.num_comments}')
webhook.add_embed(embed)
webhook.execute()
posts[submission.id] = time.time()
time.sleep(5) # To prevent rate limit
if __name__ == '__main__':
while True:
main()
_3_days_from_now = time.time() - 60 * 60 * 72
for submission_id, timestamp in posts.copy().items():
if timestamp < _3_days_from_now: # Check if submission is three days old
posts.pop(submission_id)
time.sleep(60 * 60) # Run every hour