-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.py
executable file
·71 lines (63 loc) · 1.75 KB
/
scale.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
#! /usr/bin/env python3
from utils import *
import json, datetime
user = input('42 login: ')
print('')
req_projects = req_42api('/v2/users/{}/projects_users'.format(user))
if (req_projects == False):
print(red("User not found :("))
exit(1)
projects = dict()
for project in req_projects:
if len(project['teams']) > 0:
date = datetime.datetime.strptime(project['teams'][0]['created_at'].split('.')[0], '%Y-%m-%dT%H:%M:%S')
projects[yellow(date) + ': ' + blue(project['project']['name'])] = project['project']['id']
try:
project = print_inquirer("Select a project", sorted(projects, reverse=True))
except TypeError:
exit(0)
except KeyboardInterrupt:
exit(0)
try:
if project in projects:
project_name = project
project = projects[project_name]
print('Fetching correction scale for:', blue(project_name), '-', yellow(project), '\n')
else:
print(red('Select a valid project!'))
exit(1)
except KeyboardInterrupt:
exit(1)
payload = {
'filter':
{
'filled': 'true'
}
}
i = 1
loop = True
while loop:
datas = req_42api('/v2/projects/{}/scale_teams'.format(project), payload=payload, size=100, nb_result=-1, number=i)
if len(datas) == 0:
print(red("No scale found :("))
exit(1)
for data in datas:
if data["questions_with_answers"]:
loop = False
break
i += 1
rating = {
'bool': "[ {} | {} ]".format(green('Yes'), red('No')),
'multi': "[{0}--{0}--{0}--{0}--{0}--{0}]".format(pink('#'))
}
questions = dict()
for question in data["questions_with_answers"]:
questions[question["id"]] = {
"name": question["name"],
"guide": question["guidelines"],
"rating": question["rating"]
}
for question in sorted(questions):
print(yellow(questions[question]["name"]), rating[questions[question]["rating"]])
print(blue(questions[question]["guide"]))
print("")