1
1
from github import Github
2
- import github ,requests_cache ,re ,os ,kaggle ,json ,numpy as np
2
+ import traceback , github ,requests_cache ,re ,os ,kaggle ,json ,numpy as np
3
3
4
4
GITHUB_TOKEN = os .getenv ("GIST_TOKEN" )
5
5
GIST_ID = "c9112c25c5acd400b90741efa81aa411"
@@ -81,20 +81,41 @@ def unformat_bytes(string):
81
81
82
82
for dsn in dataset_names :
83
83
print (f'Processing { dsn } ...' )
84
+ # Old Kaggle Api <1.7
84
85
try :
85
86
user = dsn .split ("/" )[0 ]
86
87
dataset = vars (next ((d for d in usernames [user ] if vars (d )['ref' ] == dsn )))
87
88
downloads .append (int (dataset ['downloadCount' ]))
88
89
views .append (int (dataset ['viewCount' ]))
89
90
sizes .append (int (dataset ['totalBytes' ]))
90
91
print (f'{ dsn } done.' )
91
-
92
- except Exception as e :
93
- print (f'{ e } when reading { dsn } ' )
92
+
93
+ # New Kaggle Api >=1.7
94
+ except KeyError :
95
+ try :
96
+ user = dsn .split ("/" )[0 ]
97
+ dataset = next ((d for d in usernames [user ] if d .ref == dsn ))
98
+ downloads .append (int (dataset .download_count ))
99
+ views .append (int (dataset .view_count ))
100
+ sizes .append (int (dataset .total_bytes ))
101
+ print (f'{ dsn } done.' )
102
+
103
+ except Exception :
104
+ traceback .print_exc ()
105
+ print (f'Error when reading { dsn } ' )
106
+ print (f'Continuing with 0 values...' )
107
+ downloads .append (0 )
108
+ views .append (0 )
109
+ sizes .append (0 )
110
+
111
+ except Exception :
112
+ traceback .print_exc ()
113
+ print (f'Error when reading { dsn } ' )
94
114
print (f'Continuing with 0 values...' )
95
115
downloads .append (0 )
96
116
views .append (0 )
97
117
sizes .append (0 )
118
+
98
119
99
120
views = np .array (views )
100
121
downloads = np .array (downloads )
@@ -121,7 +142,7 @@ def unformat_bytes(string):
121
142
'size' : ds_size ,
122
143
'views' : ds_views ,
123
144
'downloads' : ds_downs ,
124
- }
145
+ }
125
146
json_dump [filename ] = kaggle_stats
126
147
total_bytes += int (np .sum (downloads * size_in_bytes ))
127
148
total_size += int (np .sum (size_in_bytes ))
0 commit comments