/
main.py
50 lines (42 loc) · 1.36 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
import praw
import sys
from colorama import init, Fore
import connection_manager
import ui_manager
from cmd_parser import CmdParser
import io_manager
# TODO
# add a previous page command
"""
simply prints prompt and waits for a response via raw_input()
"""
def get_cmd():
sys.stdout.write(Fore.WHITE + '(pyreddit) > ')
return raw_input()
"""
sets up the program and contains the main cmd fetch cycle
"""
def main():
print 'Reading credentials from credentials.txt...'
client_id, client_secret, user_agent, username, password = io_manager.load_credentials_from_file()
print 'Read successfully!'
print 'Connecting to reddit...'
reddit = connection_manager.connect_to_reddit(client_id, client_secret, user_agent, username, password)
print 'Connection successful! Logged in as user', reddit.user.me()
print 'Reading settings from settings.txt...'
default_page_size, default_num_comments = io_manager.load_settings_from_file()
print 'Read successfully!'
print 'Startting pyreddit...'
cmd_parser = CmdParser(reddit, default_page_size, default_num_comments)
ui_manager.reset_screen(reddit)
cmd_parser.cmd_help()
while True:
try:
cmd_parser.parse_cmd(get_cmd())
except SystemExit:
quit()
except Exception, e:
print e
if __name__ == '__main__':
init()
main()