-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authors _submissions(RestAPI).py
60 lines (39 loc) · 1.22 KB
/
Authors _submissions(RestAPI).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
##Authors who havesubmissions > = threshold
# https://jsonmock.hackerrank.com/api/article_users?page=1
# threshold (int) parameter
# return list of usernames where submission_count >= threshold
import requests
import json
# url = "https://jsonmock.hackerrank.com/api/article_users"
# response = requests.get(url)
# #response.status_code
# #response.text
# res = response.text
# #print(type(res))
# a = json.loads(res)
# print(type(a))
# #print(a['data'])
# l = a['data']
# print(len(l))
# a1 = l[0]
# print(a1)
# print('author = %s' %a1['username'])
# print('submission count is %s' %a1['submission_count'])
def resfun(t):
userlist = []
for q in range(1, 3):
url = "https://jsonmock.hackerrank.com/api/article_users?page=%s"%q
response = requests.get(url)
if response.status_code == 200:
res = response.text
jres = json.loads(res)
p = jres['total_pages']
jresdata = jres['data']
for x in range(0, len(jresdata)):
if jresdata[x]['submission_count'] >= t:
userlist.append(jresdata[x]['username'])
return userlist
# print(jresdata[0])
# print(jresdata[0]['username'])
t1 = 10
print(resfun(t1))