-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
114 lines (90 loc) · 2.69 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Imports
import praw
import os
# Init Reddit client
r = praw.Reddit("SCRIPT")
r.validate_on_submit = True
logo = """
____ _ _ _ _
| _ \ ___ __| | __| (_) |_
| |_) / _ \/ _` |/ _` | | __|
| _ < __/ (_| | (_| | | |_
|_| \_\___|\__,_|\__,_|_|\__|
_ _ _
| \ | |_ _| | _____ _ __
| \| | | | | |/ / _ \ '__|
| |\ | |_| | < __/ |
|_| \_|\__,_|_|\_\___|_|
"""
main_menu = """
Select an option:
[1] Show all comments
[2] Edit and Delete all comments
"""
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def get_username():
username = r.user.me()
return username
def get_all_comments():
username = get_username()
comments = r.redditor(str(username)).comments.new()
list_of_comments = []
for comment in comments:
list_of_comments.append(
{
"comment_id": comment.id,
"comment_body": comment.body,
"comment_permalink": comment.permalink,
}
)
return list_of_comments
def edit_and_delete_all_comments():
clear_screen()
comments = get_all_comments()
if len(comments) == 0:
return print("No comments found")
for comment in comments:
try:
print("Editing and Deleting comment: " + comment["comment_id"])
edit_comment(comment["comment_id"])
delete_comment(comment["comment_id"])
except:
print("Could not edit and delete comment: " + comment["comment_id"])
return
print(f"Successfully edited and deleted {len(comments)} comments.")
def show_all_comments():
clear_screen()
comments = get_all_comments()
for comment in comments:
print("Comment ID: " + comment["comment_id"])
print("Comment Body: " + comment["comment_body"])
print("Comment Link: " + comment["comment_permalink"])
print("------------------")
print(f"Found {len(comments)} comments")
def delete_comment(comment: str):
try:
r.comment(comment).delete()
except:
print("Could not delete comment: " + comment)
return
def edit_comment(comment: str):
try:
r.comment(comment).edit(body="Lorem Ipsum...")
except:
print("Could not edit comment: " + comment)
return
def main():
clear_screen()
print(logo)
print("")
print(main_menu)
menu_choice = input(":: ")
if menu_choice == 1 or menu_choice == "1":
show_all_comments()
elif menu_choice == 2 or menu_choice == "2":
edit_and_delete_all_comments()
else:
print("You should press the correct button :)")
if __name__ == "__main__":
main()