-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConfig.py
More file actions
54 lines (48 loc) · 2.17 KB
/
Config.py
File metadata and controls
54 lines (48 loc) · 2.17 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import praw
import os
import json
from imgurpython import ImgurClient
def get_json_data(fname):
with open(fname) as json_data:
data = json.load(json_data)
return data
def dump(db, fname):
with open(fname, 'w') as outfile: # Write out new data
outfile.write(json.dumps(db, sort_keys=True, indent=4))
class Config():
def __init__(self, sub_name):
self.fname = "config/" + sub_name.lower() + ".json"
self.raw_config = get_json_data(self.fname)
self.subreddit_name = self.raw_config['subreddit_name'].lower()
self.client_id = self.raw_config['client_id']
self.client_secret = self.raw_config['client_secret']
self.bot_username = self.raw_config['bot_username']
self.bot_password = self.raw_config['bot_password']
self.refresh_token = self.raw_config['refresh_token']
self.reddit = praw.Reddit(client_id=self.client_id, client_secret=self.client_secret, user_agent='Swap Bot for ' + self.subreddit_name + ' v1.0 (by u/RegExr)', refresh_token=self.refresh_token)
self.subreddit = self.reddit.subreddit(self.subreddit_name)
self.hours_between_posts = self.raw_config['hours_between_posts']
self.lock_post = self.raw_config['lock_post']
self.whitelisted_words = self.raw_config['whitelisted_words']
self.num_minutes_flair = self.raw_config['num_minutes_flair']
if self.num_minutes_flair <= 0:
self.num_minutes_flair = float('inf')
self.cooldown_hours = self.raw_config['cooldown_hours']
self.imgur_freshness_days = self.raw_config['imgur_freshness_days']
self.imgur_client = self.raw_config['imgur_client']
self.imgur_secret = self.raw_config['imgur_secret']
try:
if self.imgur_client and self.imgur_secret:
self.imgur = ImgurClient(self.imgur_client, self.imgur_secret)
else:
self.imgur = None
except:
self.imgur = None
self.copy_bans_to = self.raw_config['copy_bans_to']
self.remove_from_reports = self.raw_config['remove_from_reports']
self.modmail_replies = self.raw_config['modmail_replies']
self.enabled = self.raw_config['enabled']
self.frequency_warning_text = self.raw_config['frequency_warning_text']
def dump(self):
with open(self.fname, 'w') as outfile:
outfile.write(json.dumps(self.raw_config, sort_keys=True, indent=4))