-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (70 loc) · 2.02 KB
/
app.py
File metadata and controls
82 lines (70 loc) · 2.02 KB
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
import requests
import json
import collections
import re
from secret import accessToken
from flask import Flask, render_template,request
app= Flask(__name__)
headers = {"Authorization": "bearer "+ accessToken }
@app.route('/',methods = ['GET','POST'])
def index():
if request.method == 'POST': # basic Flask structure
username = request.form['github-username']
# return in the browser
while username!='':
prsdata=getpullRequests(username)
return '''{}'''.format(prsdata)
return render_template('index.html')
@app.errorhandler(500)
def not_found(e):
nouser={
"id":"None"
}
return render_template('prs.html',nouser=nouser), 500
def getpullRequests(username):
topic_query = """
query ($name:String!){
repositoryOwner(login:$name){
login
... on User {
name
avatarUrl
pullRequests(last: 100){
nodes{
id
createdAt
additions
deletions
}
}
}
}
}
"""
variables=dict({
"name":str(username)
})
request = requests.post('https://api.github.com/graphql', json={'query': topic_query,"variables":variables},headers=headers)
if request.status_code == 200:
result = request.json()
prsdata = {}
prcount=0
for pr in result['data']['repositoryOwner']['pullRequests']['nodes']:
prdata = {}
if re.match(r'^2019-10', pr['createdAt']):
prcount+=1
prdata['createdAt'] = pr['createdAt']
prdata['additions'] = pr['additions']
prdata['deletions'] = pr['deletions']
prsdata[pr['id']] = prdata
if prsdata:
#print(prsdata)
return render_template('prs.html', prs=prsdata,prcount=prcount)
else:
print("No PRs made in Hacktoberfest")
data={
"id":"Null"
}
return render_template('prs.html',data=data)
if __name__ == "__main__":
app.run()