-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdbhandler.py
97 lines (83 loc) · 2.36 KB
/
dbhandler.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
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
'''
OctoDog Web Application
Database handler
http://octodog.sinaapp.com/
@author: bambooom
'''
import sae.kvdb
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#ROOT = os.path.dirname(os.path.abspath(__file__))
def fetch_repos():
kv = sae.kvdb.Client()
temp1 = [i[1] for i in list(kv.get_by_prefix("repo#"))]
temp2 = sorted(temp1, key = lambda x:x['name'])
name_list = [temp2[i]['name'] for i in range(len(temp2))]
kv.disconnect_all()
return name_list
def fetch_repo_dict():
kv = sae.kvdb.Client()
temp = [i[1] for i in kv.get_by_prefix("repo#")]
kv.disconnect_all()
return temp
def fetch_owner_by_repo(repo):
temp = fetch_repo_dict()
for i in temp:
if i["name"] == repo:
return i["owner"]
return None
def add_repo(new_repo):
kv = sae.kvdb.Client()
key = "repo#" + str(new_repo['name'])
kv.set(key,new_repo)
kv.disconnect_all()
def get_graph_data(repo_dict):
namelist=[]
cmlist=[]
attlist=[]
uelist=[]
for repo in repo_dict:
for key, value in repo.items():
if key == "name":
namelist.append(value)
elif key == "stats":
cmlist.append(value[0])
attlist.append(value[1])
uelist.append(value[2])
data = [namelist,cmlist,attlist,uelist]
kv=sae.kvdb.Client()
kv.set("graph",data)
kv.disconnect_all()
def get_table_data(repo_dict):
table_data=[]
for repo in repo_dict:
tdict={}
for key, value in repo.items():
if key == "name":
tdict[key]=value
elif key == "stats":
tdict["commits"]=value[0]
tdict["attention"]=value[1]
tdict["uneven"]=value[2]
table_data.append(tdict)
kv=sae.kvdb.Client()
kv.set("table", table_data)
kv.disconnect_all()
def update_stats(repo):
kv=sae.kvdb.Client()
key = "repo#" + str(repo['name'])
from get_repos_stats import fetch_for_one
repo['stats'] = fetch_for_one(repo['owner'],repo['name'])
kv.set(key, repo)
kv.disconnect_all()
#new_repo=('OctoDog','https://github.com/OctoPuppy/Octodog')
#add_repo(new_repo)
#add_repo(new_repo)
#add_repo(new_repo)
#reponame_list = fetch_name_list(fetch_repos_table())
#print reponame_list
#a = get_repo_table()
#print len(a)