17
17
'''
18
18
19
19
def get_commit_hash (commits_url ):
20
- # import ast
21
-
22
20
commits_url = commits_url .split ('{' )[0 ] + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
23
- print commits_url
21
+ print ( commits_url )
24
22
response = urllib .urlopen (commits_url )
25
23
data = json .loads (response .read ())[0 ]
26
24
return data ['sha' ]
27
25
26
+ ### store the dependency urls and snippet urls
28
27
def update_visualizations (component , commit_hash ):
29
28
github_url_list = component .github_url .split ('?' )[0 ].split ('/' )
30
29
owner = github_url_list [4 ]
31
30
repo_name = github_url_list [5 ]
32
- # print "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + "/package.json"
33
31
try :
34
32
sniper_data = json .load (urllib .urlopen ("https://cdn.rawgit.com/" + str (owner ) +
35
33
'/' + str (repo_name ) + "/" + commit_hash + "/package.json" ))["sniper" ]
@@ -78,14 +76,42 @@ def update_visualizations(component, commit_hash):
78
76
try :
79
77
no_browserify = sniper_data ['noBrowserify' ]
80
78
sniperData .no_browserify = no_browserify
79
+ except :
80
+ pass
81
+ try :
81
82
if no_browserify :
82
83
sniperData .wzrd_url = '#'
83
84
else :
84
- sniperData .wzrd_url = "https://wzrd.in/bundle/" + component .name
85
+ sniperData .wzrd_url = "https://wzrd.in/bundle/" + component .name
86
+ except :
87
+ sniperData .wzrd_url = "https://wzrd.in/bundle/" + component .name
88
+ try :
89
+ snippets_dir_name = sniper_data ['snippets' ][0 ]
90
+ sniperData .snippets_dir_name = snippets_dir_name
85
91
except :
86
92
pass
87
93
sniperData .save ()
88
94
95
+ ### For Snippets URLs
96
+ try :
97
+ print ("https://api.github.com/repos/" + str (owner ) + "/" + str (repo_name ) + "/contents/" + sniperData .snippets_dir_name + "?ref=master&client_id="
98
+ + GITHUB_CLIENT_ID + "&client_secret=" + GITHUB_CLIENT_SECRET )
99
+ snippets_data = urllib .urlopen ("https://api.github.com/repos/" + str (owner ) + "/" + str (repo_name ) + "/contents/" + sniperData .snippets_dir_name + "?ref=master&client_id="
100
+ + GITHUB_CLIENT_ID + "&client_secret=" + GITHUB_CLIENT_SECRET )
101
+ snippets = json .loads (snippets_data .read ())
102
+ for snippet in snippets :
103
+ if not snippet ['name' ].endswith ('.js' ):
104
+ continue
105
+ url = "https://cdn.rawgit.com/" + str (owner ) + '/' + str (repo_name ) + "/" + commit_hash + "/" + sniperData .snippets_dir_name + "/" + snippet ['name' ]
106
+ try :
107
+ req_snippet = Snippet .objects .get (name = snippet ['name' ], sniperData = sniperData )
108
+ req_snippet .url = url
109
+ req_snippet .save ()
110
+ except :
111
+ Snippet .objects .create (name = snippet ['name' ], sniperData = sniperData , url = url )
112
+ except :
113
+ pass
114
+
89
115
def get_github_data (github_url ):
90
116
response = urllib .urlopen (github_url )
91
117
data = json .load (response )
@@ -106,8 +132,7 @@ def get_contributors_data(contributors_url):
106
132
return data
107
133
108
134
def get_downloads (downloads_url ):
109
- # import ast
110
- print downloads_url
135
+ print (downloads_url )
111
136
response = urllib .urlopen (downloads_url )
112
137
downloads = 0
113
138
data = ast .literal_eval (response .read ())
@@ -126,10 +151,10 @@ def handle(self, *args, **options):
126
151
component_data = component ['package' ]
127
152
try :
128
153
_component = Component .objects .get (name = component_data ['name' ])
129
- print 'exists'
154
+ print ( 'exists' )
130
155
except :
131
156
_component = Component .objects .create (name = component_data ['name' ])
132
- print _component .name
157
+ print ( _component .name )
133
158
try :
134
159
_component .version = component_data ['version' ]
135
160
except :
@@ -182,7 +207,7 @@ def handle(self, *args, **options):
182
207
_component .save ()
183
208
184
209
if _component .github_url :
185
- print _component .github_url
210
+ print ( _component .github_url )
186
211
try :
187
212
github_data = get_github_data (_component .github_url )
188
213
except :
@@ -222,7 +247,7 @@ def handle(self, *args, **options):
222
247
# except:
223
248
# pass
224
249
_component .save ()
225
- print str (github_data ['contributors_url' ]) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
250
+ print ( str (github_data ['contributors_url' ]) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET )
226
251
try :
227
252
contributors_data = get_contributors_data (str (github_data ['contributors_url' ]) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET )
228
253
except :
0 commit comments