-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetRapidBoard.py
More file actions
86 lines (67 loc) · 2.06 KB
/
Copy pathGetRapidBoard.py
File metadata and controls
86 lines (67 loc) · 2.06 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
82
83
84
85
86
import sys
import os
import requests
import json
import base64
import pymysql
from datetime import datetime
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import Utility.JSONUtility as Utility
import Utility.RepoConfig as Repo
import Utility.DBConfig as DB
def collectRapidBoard():
"""
Collect the rapid board (list of boards) from the repository
"""
print("Collect Rapid Board...")
url = "https://{}/rest/greenhopper/1.0/rapidviews/list/".format(repo.domain)
json_data = createRequest(url)
writeFile(json_data, repo.name, db.folder)
def createRequest(url):
"""
Send a request to the given URL
<url>: The URL to send the request to
"""
# userpass = "username:password"
userpass = repo.userpass
encoded = str(base64.b64encode(bytearray(userpass, "utf-8")))
basicAuth = "Basic " + encoded[2:len(encoded)-1]
headers = {
"Accept": "application/json",
"Authorization": basicAuth,
}
try:
response = requests.request(
"GET",
url,
headers = headers
)
except requests.exceptions.RequestException as e:
print("ERROR: {}".format(e))
json_data = json.loads(response.text)
return json_data
def writeFile(data, repo, folder):
path = "<file_path>".format(folder, repo)
try:
with open(path, 'w') as json_file:
json.dump(data, json_file, indent=4)
print("Write '{}' success!!".format(json_file.name))
except:
print("Write error!!")
sys.exit(1)
if __name__ == '__main__':
repo = Repo.createRepo()
db = DB.createDB(repo)
connection = pymysql.connect(
host=db.host,
port=db.port,
user=db.user,
passwd=db.pwd,
database=db.repo.name,
cursorclass=pymysql.cursors.DictCursor
)
cursor = connection.cursor()
collectRapidBoard()
cursor.close()
connection.close()
print("DB Connection is closed")