-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal_start.py
More file actions
53 lines (44 loc) · 1.86 KB
/
terminal_start.py
File metadata and controls
53 lines (44 loc) · 1.86 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
import signal
import sys
from connectors.generic import login, create_feed, backup_tofeed, mimic_feed, save_hot, unsave
from connectors.terminal import Terminal
REDDIT_URL = "https://www.reddit.com"
# a signal handler to handle shutdown of the bot
def signal_handler(sig, frame):
print('Closing bot...')
sys.exit(0)
def run_bot():
""" Method that will run the Subreddit-Scanner bot """
reddit = login()
print("Logged in successfully...")
terminal_obj = Terminal()
# runs the program indefinitely
while True:
# fetches the command
command = input("\nWhat would you like to do today?\n"
"1. (c)reate\n"
"2. (b)ackup\n"
"3. (m)imic\n"
"4. (s)ave hot items\n"
"5. (u)nsave\n"
"6. (q)uit\n")
# performs the action based on the command given
if command == "c" or command == "create" or command == "1":
create_feed(reddit, terminal_obj)
elif command == 'b' or command == "backup" or command == "2":
backup_tofeed(reddit, terminal_obj)
elif command == "m" or command == "mimic" or command == "3":
mimic_feed(reddit, terminal_obj)
elif command == "s" or command == "save hot items" or command == "4":
save_hot(reddit, terminal_obj)
elif command == "u" or command == "unsave" or command == "5":
unsave(reddit, terminal_obj)
elif command == "q" or command == "quit" or command == "6":
sys.exit(0)
else:
print("Invalid command given! Please choose one of the given options")
if __name__ == '__main__':
# sets up signal to be recognized by user
signal.signal(signal.SIGINT, signal_handler)
print('To close the bot please press Ctrl + C')
run_bot()