-
Notifications
You must be signed in to change notification settings - Fork 2
/
stalk.py
175 lines (116 loc) · 5 KB
/
stalk.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from spoj import Spoj
from codechef import Codechef
from codeforces import Codeforces
class Stalk():
def __init__(self):
self.initialise_platforms()
self.spoj = Spoj()
self.codechef = Codechef()
self.codeforces = Codeforces()
def initialise_platforms(self):
self.platforms = {
"Spoj": 1,
"CodeChef": 2,
"CodeForces": 3
}
def set_platform(self, platform):
self.platform = platform
def get_platform(self):
return self.platform
def get_platforms(self):
return self.platforms
def get_choice(self):
return self.choice
def set_choice(self, choice):
self.choice = choice
def get_all_choices(self):
return list(self.platforms.values())
def set_username(self, username):
self.username = username
def get_username(self):
return self.username
def set_competitor(self, competitor):
self.competitor = competitor
def get_competitor(self):
return self.competitor
def get_menu(self):
menu = "\nChoose Platform\n\n"
for key, value in self.platforms.items():
menu += f"{value}) {key}\n\n"
self.menu = menu
return self.menu
def get_user_problems(self, user):
problems, urls = self.platform.get_user_problems(user)
user_problems = list(zip(problems, urls))
return user_problems
def get_user_choice(self):
menu = str(self.get_menu())
print(menu)
print("Enter your choice: ", end = "")
choice = int(input())
while choice not in list(stalk.get_all_choices()):
print("\nEnter a valid choice")
print(menu, end = "")
choice = int(input())
self.set_choice(choice)
if choice == 1:
self.set_platform(self.spoj)
elif choice == 2:
self.set_platform(self.codechef)
elif choice == 3:
self.set_platform(self.codeforces)
def get_user_input(self):
print("\nEnter your username: ", end = "")
username = input()
while not self.platform.is_valid_user(username):
print("\nEnter a valid username: ", end = "")
username = input()
else:
self.set_username(username)
print("\nEnter your competitor username: ", end = "")
competitor = input()
while not self.platform.is_valid_user(competitor):
print("\nEnter a valid competitor username: ", end = "")
competitor = input()
else:
self.set_competitor(competitor)
def get_problems_solved_by_user(self, user_problems, competitor_problems):
return list(set(user_problems) - set(competitor_problems))
def get_problems_solved_by_both(self, user_problems, competitor_problems):
return list(set(user_problems) & set(competitor_problems))
def display_problems(self, problems):
max_index_len = max(len(str(len(problems))), 5) + 2
max_problem_len = max([len(prob[0]) for prob in problems]) + 2
max_url_len = max([len(prob[1]) for prob in problems ]) + 2
print("\n | ", end = "")
print(f"Index".center(max_index_len, " "), end = " | ")
print(f"Problem".center(max_problem_len, " "), end = " | ")
print(f"URL".center(max_url_len), end = " | ")
print("")
print("-"*(max_index_len + max_problem_len + max_url_len + 12))
for index, value in enumerate(problems):
print(" | ", end = "")
print(f"{index + 1}".center(max_index_len, " "), end = " | ")
print(f"{value[0]}".center(max_problem_len, " "), end = " | ")
print(f"{value[1]}".center(max_url_len), end = " | ")
print("")
def start_stalking(self):
self.get_user_choice()
self.get_user_input()
user_problems = self.get_user_problems(self.username)
competitor_problems = self.get_user_problems(self.competitor)
problems_solved_by_user = self.get_problems_solved_by_user(user_problems, competitor_problems)
problems_solved_by_competitor = self.get_problems_solved_by_user(competitor_problems, user_problems)
problems_solved_by_both = self.get_problems_solved_by_both(competitor_problems, user_problems)
if len(problems_solved_by_competitor) > 0:
print(f"\nProblems Solved by {self.competitor} and not by {self.username}:")
self.display_problems(problems_solved_by_competitor)
if len(problems_solved_by_user) > 0:
print(f"\nProblems Solved by {self.username} and not by {self.competitor}:")
self.display_problems(problems_solved_by_user)
if len(problems_solved_by_both) > 0:
print(f"\nProblems Solved by both {self.username} and {self.competitor}:")
self.display_problems(problems_solved_by_both)
if __name__ == "__main__":
stalk = Stalk()
stalk.start_stalking()