-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
46 lines (39 loc) · 1.23 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
44
45
46
'''
This script is used for changing the text below total members & live
members count in the developersIndia subreddit
'''
import praw
import os
import random
import time
import json
client_id = os.environ["REDDIT_CLIENT_ID"]
client_secret = os.environ["REDDIT_CLIENT_SECRET"]
reddit_pass = os.environ["REDDIT_PASSWORD"]
def get_titles():
with open('dataset.json', 'r') as f:
data = json.load(f)
titles = data['titles']
currentlyViewingText, subscribersText = random.sample(titles, 2)
return [currentlyViewingText, subscribersText]
def update_titles():
reddit = praw.Reddit(
client_id=client_id,
client_secret=client_secret,
password=reddit_pass,
user_agent="Update Titles by u/devsIndiaBot",
username="devsIndiaBot",
)
widgets = reddit.subreddit("developersIndia").widgets
id_card = widgets.id_card
print("Titles Before update")
# total members
print(id_card.subscribersText)
print(id_card.currentlyViewingText)
titles = get_titles()
print(titles)
widgets.id_card.mod.update(currentlyViewingText=titles[0])
widgets.refresh()
widgets.id_card.mod.update(subscribersText=titles[1])
if __name__ == '__main__':
update_titles()