-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaster.py
88 lines (63 loc) · 2.05 KB
/
Master.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
from socket import *
import requests
from collections import deque
from flask import Flask
from flask_restful import Resource, Api, request
import shutil
trees = []
blobUrlList = []
githubUrl = 'https://api.github.com/repos/oconnes9/Distributed_System/commits'
app = Flask(__name__)
api = Api(app)
blobUrlList = deque()
newCC = 0
CC = 0
blobListLength = 0
class Master(Resource):
def get(self):
global blobUrlList
if blobUrlList:
return blobUrlList.popleft()
else:
return "finished"
def put(self):
global CC
newCC = int(request.form['cc'])
CC = CC + newCC
print("RECEIVED: " + str(newCC))
aveCC = CC / blobListLength
print("Average CC: " + str(aveCC))
return '', 204
def getHeader(): #function to return the
print("1")
with open('token.txt', 'r') as tmpFile:
token = tmpFile.read() # get the token from a text file in current directory
payload = {'access_token': token}
headers = {'Accept': 'application/vnd.github.v3.raw'}
return (payload, headers)
def getTrees(githubUrl):
print("2")
headers = getHeader()
resp = requests.get(githubUrl, params=headers[0], headers=headers[1])
for item in resp.json():
trees.append(item['commit']['tree']['url'])
return trees
def blobList(githubUrl, trees):
print("3")
headers = getHeader()
for blobUrl in trees:
resp = requests.get(blobUrl, params=headers[0], headers=headers[1])
tree = resp.json()['tree']
for item in tree:
fileUrl = item['url']
filename = item['path']
urlFilename = fileUrl + '|' + filename
blobUrlList.append(urlFilename)
blobListLength = len(blobUrlList)
def main():
trees = getTrees(githubUrl) #Get list of tree URLs
blobList(githubUrl, trees) #Get blob URL for each tree
app.run(host = 'localhost', port = 1111, debug=False)
api.add_resource(Master, '/')
if __name__ == "__main__":
main()