-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathreddit.py
65 lines (45 loc) · 1.82 KB
/
reddit.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import praw
from redditglobals import *
def post_encryption(filename, encryption):
subreddit = r.get_subreddit(SUBREDDIT)
does_not_exist = True
file_submissions = r.search(filename, SUBREDDIT)
# getting the submission of the file if it exists already
count = 0
for submission in file_submissions:
if filename.lower() in submission.title.lower():
count += 1
does_not_exist = False
# create submission if does not exist
if does_not_exist:
file_post = r.submit(SUBREDDIT, filename, " ")
else:
file_post = r.submit(SUBREDDIT, filename + " (" + str(count) + ")", " ")
# going to be splitting the encryption since the comment limit is 10000 characters
# this is the first-level comment
current_comment = file_post.add_comment(encryption[:10000])
encryption = encryption[10000:]
#if it does not fit, then we will add a child comment to it and repeat
if len(encryption) != 0:
while len(encryption) > 10000:
#to-do
current_comment = current_comment.reply(encryption[:10000])
encryption = encryption[10000:]
if len(encryption) > 0:
current_comment.reply(encryption)
def get_decryption(filename):
decryption = ''
subreddit = r.get_subreddit(SUBREDDIT)
comments = subreddit.get_comments()
file_submissions = r.search(filename, SUBREDDIT)
# find the corresponding post for the file
for submission in file_submissions:
if submission.title.lower() == filename.lower():
subm = submission
break
# level the comments
subm.replace_more_comments(limit=None, threshold=0)
comments = praw.helpers.flatten_tree(subm.comments)
for comment in comments:
decryption = decryption + comment.body
return decryption