-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbridge.py
More file actions
83 lines (63 loc) · 2.19 KB
/
bridge.py
File metadata and controls
83 lines (63 loc) · 2.19 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
import pickle
import cloudant
from db import DB2
from pr_nlu_analysis import Repository
from query import run_query
import json
# switch source to existing data set
def use_existing_data(table):
db = DB2("credentials/db2_credentials.json")
db.switch_view("SOURCE", table)
db.close()
# gather from new repo and switch source
def use_new_data(auth, repo, pull_type):
# database = cloudant.CDatabase("credentials/cloudant_credentials.json")
owner_repo = repo.split("/")
table = f"{owner_repo[0]}_{owner_repo[1]}_{pull_type}"
# collect data and add it to the database
data = run_query(auth, owner_repo[0], owner_repo[1], pull_type)
repo = Repository(data, pull_type)
# repo.to_csv()
# uncomment this and comment data = ... and repo = ... lines to quickly test DB commands
# with open("data/store.txt", "rb") as file:
# repo = pickle.load(file)
# create connection to DB2
db = DB2("credentials/db2_credentials.json")
# create and clear the table in case it doesn't exist or already has data
db.create(table)
db.clear(table)
# insert data into the table
db.insert_data(table, repo.repo_items)
# switch the source to the gathered data
db.switch_view("SOURCE", table)
add_name(table)
db.close()
# adds the name of a database to a file
def add_name(name):
with open("data/tables.txt", "r+") as tables:
if name not in tables.read():
tables.write(name + "\n")
# main function for testing code
if __name__ == '__main__':
print("Enter an access token: ", end="")
auth = input()
p_type = ""
own_re = ""
valid = False
while not valid:
print("Enter a repo (owner/repo): ", end="")
own_re = input()
if len(own_re.split("/")) != 2:
print("Invalid input")
else:
print("Get issues or pull requests? (i or p): ", end="")
letter = input()
if letter == "i":
p_type = "issues"
valid = True
elif letter == "p":
p_type = "pullRequests"
valid = True
else:
print("Invalid input")
use_new_data(auth, own_re, p_type)