8
8
GITHUB_CLIENT_SECRET = ''
9
9
from datetime import datetime
10
10
import pytz
11
+ import ast
12
+
13
+ # Get sniper data
14
+ '''
15
+ https://rawgit.com/cytoscape/cytoscape.js/master/package.json
16
+ "sniper" key, has "js" and "css". Search for "first"
17
+ '''
18
+
19
+ def get_commit_hash (commits_url ):
20
+ # import ast
21
+
22
+ commits_url = commits_url .split ('{' )[0 ] + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
23
+ print commits_url
24
+ response = urllib .urlopen (commits_url )
25
+ data = json .loads (response .read ())[0 ]
26
+ return data ['sha' ]
27
+
28
+ def update_visualizations (component , commit_hash ):
29
+ github_url_list = component .github_url .split ('?' )[0 ].split ('/' )
30
+ owner = github_url_list [4 ]
31
+ repo_name = github_url_list [5 ]
32
+ # print "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + "/package.json"
33
+ try :
34
+ sniper_data = json .load (urllib .urlopen ("https://cdn.rawgit.com/" + str (owner ) +
35
+ '/' + str (repo_name ) + "/" + commit_hash + "/package.json" ))["sniper" ]
36
+ except :
37
+ return
38
+ try :
39
+ buildJS = sniper_data ["buildJS" ]
40
+ except :
41
+ buildJS = []
42
+ try :
43
+ js = sniper_data ["js" ]
44
+ except :
45
+ js = []
46
+ js_dependencies = buildJS + js
47
+ try :
48
+ buildCSS = sniper_data ["buildCSS" ]
49
+ except :
50
+ buildCSS = []
51
+ try :
52
+ css = sniper_data ["css" ]
53
+ except :
54
+ css = []
55
+ css_dependencies = buildCSS + css
56
+ for dependency in js_dependencies :
57
+ if dependency .startswith ('https://' ):
58
+ dependency , created = JSDependency .objects .get_or_create (component = component , js_url = dependency )
59
+ elif dependency .startswith ('/' ):
60
+ dependency = "https://cdn.rawgit.com/" + str (owner ) + '/' + str (repo_name ) + "/" + commit_hash + dependency
61
+ dependency , created = JSDependency .objects .get_or_create (component = component , js_url = dependency )
62
+ else :
63
+ dependency = "https://cdn.rawgit.com/" + str (owner ) + '/' + str (repo_name ) + "/" + commit_hash + "/" + dependency
64
+ dependency , created = JSDependency .objects .get_or_create (component = component , js_url = dependency )
65
+ for dependency in css_dependencies :
66
+ if dependency .startswith ('https://' ):
67
+ dependency , created = CSSDependency .objects .get_or_create (component = component , css_url = dependency )
68
+ elif dependency .startswith ('/' ):
69
+ dependency = "https://cdn.rawgit.com/" + str (owner ) + '/' + str (repo_name ) + "/" + commit_hash + dependency
70
+ dependency , created = CSSDependency .objects .get_or_create (component = component , css_url = dependency )
71
+ else :
72
+ dependency = "https://cdn.rawgit.com/" + str (owner ) + '/' + str (repo_name ) + "/" + commit_hash + "/" + dependency
73
+ dependency , created = CSSDependency .objects .get_or_create (component = component , css_url = dependency )
74
+ try :
75
+ sniperData = SniperData .objects .get (component = component )
76
+ except :
77
+ sniperData = SniperData .objects .create (component = component )
78
+ try :
79
+ no_browserify = sniper_data ['noBrowserify' ]
80
+ sniperData .no_browserify = no_browserify
81
+ if no_browserify :
82
+ sniperData .wzrd_url = '#'
83
+ else :
84
+ sniperData .wzrd_url = "https://wzrd.in/bundle/" + component .name
85
+ except :
86
+ pass
87
+ sniperData .save ()
11
88
12
89
def get_github_data (github_url ):
13
90
response = urllib .urlopen (github_url )
@@ -18,6 +95,7 @@ def get_npm_data():
18
95
# response = urllib2.urlopen()
19
96
hdr = {'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' }
20
97
req = urllib2 .Request ("http://registry.npmjs.com/-/v1/search?text=keywords:biojs,bionode&size=500" , headers = hdr )
98
+ # req = urllib2.Request("http://registry.npmjs.com/-/v1/search?text=biojs-vis-msa&size=1", headers=hdr)
21
99
response = urllib2 .urlopen (req )
22
100
data = json .load (response )
23
101
return data
@@ -28,7 +106,7 @@ def get_contributors_data(contributors_url):
28
106
return data
29
107
30
108
def get_downloads (downloads_url ):
31
- import ast
109
+ # import ast
32
110
print downloads_url
33
111
response = urllib .urlopen (downloads_url )
34
112
downloads = 0
@@ -126,6 +204,23 @@ def handle(self, *args, **options):
126
204
_component .created_time = aware_date
127
205
except :
128
206
pass
207
+ # try:
208
+ str_date = github_data ['updated_at' ]
209
+ req_date = datetime .strptime (str_date , "%Y-%m-%dT%H:%M:%SZ" ) #This object is timezone unaware
210
+ aware_date = pytz .utc .localize (req_date ) #This object is now timezone aware
211
+ # if _component.github_update_time:
212
+ # if aware_date > _component.github_update_time:
213
+ # _component.github_updated_time = aware_date
214
+ # latest_commit_hash = get_commit_hash(github_data['commits_url'])
215
+ # _component.latest_commit_hash = latest_commit_hash
216
+ # update_visualizations(_component, latest_commit_hash)
217
+ # else:
218
+ _component .github_update_time = aware_date
219
+ latest_commit_hash = get_commit_hash (github_data ['commits_url' ])
220
+ _component .latest_commit_hash = latest_commit_hash
221
+ update_visualizations (_component , latest_commit_hash )
222
+ # except:
223
+ # pass
129
224
_component .save ()
130
225
print str (github_data ['contributors_url' ]) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
131
226
try :
0 commit comments