-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·111 lines (89 loc) · 3.76 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
#!/usr/bin/env python
from __future__ import print_function
from api import *
from parser import *
import getpass
#initial page number of feed
page_number = 1
#check if user wants to quit
want_to_quit = False
#initial login state
user_logged_in = False
#check if user in rant details
in_rant_page = False
#check if user in notifications page
in_notifications_page = False
#check if user wants to login
want_to_login = raw_input("Do you want to login? You need to be logged on to post and vote.(y/n): ")
if want_to_login.startswith("y"):
username = raw_input("Username / E-mail: ")
password = getpass.getpass("Password: ")
while user_logged_in is False:
authorization = login(username, password)
if authorization is not False:
print("Successfully logged in!")
user_logged_in = True
for i in range(0, get_terminal_width()):
print("=",end='')
print("")
else:
print("Something went wrong, probably wrong username/password combination.")
else:
print("It's OK, you can still enjoy devRant!")
for i in range(0, get_terminal_width()):
print("=",end='')
print("")
#parsing 1st page of feed
parse_feed()
while want_to_quit is False:
if user_logged_in:
nav_prompt = "V for next page, Y for previous page, Q to exit, S <term> to search, R <rant ID> to browse a rant, P <rant> to post rant, U <rant ID> to upvote, D <rant ID> to downvote, N to see your notifications\n"
if user_logged_in is False:
nav_prompt = "V for next page, Y for previous page, Q to exit, S <term> to search, R <rant ID> to browse a rant\n"
if in_rant_page is True and user_logged_in is False:
nav_prompt = "Q to exit, S <term> to search, R <rant ID> to browse a rant, B to back\n"
if in_rant_page is True and user_logged_in is True:
nav_prompt = "Q to exit, S <term> to search, U <rant ID> to upvote, D <rant ID> to downvote, A <comment> to add comment, B to back, N to see your notifications\n"
if in_notifications_page:
nav_prompt = "B to back"
#prompt the user accordingly to situation
nav_option = raw_input(nav_prompt)
if nav_option == "v" or nav_option == "V":
page_number += 1
parse_feed("feed", "a", page_number)
if nav_option == "y" or nav_option == "Y":
page_number -= 1
if page_number == 0:
page_number = 1
parse_feed("feed", "a", page_number)
if nav_option == "q" or nav_option == "Q":
want_to_quit = True
if nav_option =="b" or nav_option == "B":
parse_feed("feed", "a", page_number)
in_rant_page = False
if nav_option.startswith("s") or nav_option.startswith("S"):
search_term = nav_option.split()[1]
parse_feed("search", nav_option)
if nav_option.startswith("r") or nav_option.startswith("R"):
rant_id = nav_option.split()[1]
parse_rant(rant_id)
in_rant_page = True
if nav_option.startswith("u") or nav_option.startswith("U"):
post_id = nav_option.split()[1]
if in_rant_page:
vote_post(post_id, authorization['token_key'], authorization['token_id'], authorization['user_id'], "1")
else:
vote_rant(post_id, authorization['token_key'], authorization['token_id'], authorization['user_id'], "1")
if nav_option.startswith("d") or nav_option.startswith("D"):
post_id = nav_option.split()[1]
if in_rant_page:
vote_post(post_id, authorization['token_key'], authorization['token_id'], authorization['user_id'], "1")
else:
vote_rant(post_id, authorization['token_key'], authorization['token_id'], authorization['user_id'], "1")
if nav_option.startswith("n") or nav_option.startswith("N"):
in_notifications_page = True
parse_notifications(authorization['token_key'], authorization['token_id'], authorization['user_id'])
if nav_option.startswith("a") or nav_option.startswith("A"):
comment = nav_option[2:]
post_comment(rant_id, authorization['token_key'], authorization['token_id'], authorization['user_id'], comment)
print("Farewell!")