|
36 | 36 | import plistlib |
37 | 37 | import codecs |
38 | 38 | import ssl |
| 39 | +from datetime import datetime, timedelta |
39 | 40 |
|
40 | 41 | from io import StringIO |
41 | 42 |
|
@@ -262,13 +263,37 @@ def get_default_nwjs_branch(self): |
262 | 263 | Get the default nwjs branch to search for |
263 | 264 | the changelog from github. |
264 | 265 | """ |
265 | | - github_url = self.settings['version_info']['github_api_url'] |
| 266 | + query_api = False |
| 267 | + nwjs_branch_path = get_data_file_path(config.NW_BRANCH_FILE) |
266 | 268 |
|
267 | | - resp = utils.urlopen(github_url) |
268 | | - json_string = resp.read().decode('utf-8') |
269 | | - data = json.loads(json_string) |
| 269 | + if os.path.exists(nwjs_branch_path): |
| 270 | + mod_time = os.path.getmtime(nwjs_branch_path) |
| 271 | + mod_time = datetime.fromtimestamp(mod_time) |
| 272 | + hour_ago = datetime.now() - timedelta(hours=1) |
270 | 273 |
|
271 | | - return data['default_branch'] |
| 274 | + if mod_time <= hour_ago: |
| 275 | + query_api = True |
| 276 | + else: |
| 277 | + query_api = True |
| 278 | + |
| 279 | + branch = None |
| 280 | + |
| 281 | + if query_api: |
| 282 | + github_url = self.settings['version_info']['github_api_url'] |
| 283 | + |
| 284 | + resp = utils.urlopen(github_url) |
| 285 | + json_string = resp.read().decode('utf-8') |
| 286 | + data = json.loads(json_string) |
| 287 | + branch = data['default_branch'] |
| 288 | + |
| 289 | + with codecs.open(nwjs_branch_path, 'w', encoding='utf-8') as f: |
| 290 | + f.write(branch) |
| 291 | + |
| 292 | + else: |
| 293 | + with codecs.open(nwjs_branch_path, 'r', encoding='utf-8') as f: |
| 294 | + branch = f.read().strip() |
| 295 | + |
| 296 | + return branch |
272 | 297 |
|
273 | 298 | def get_versions(self): |
274 | 299 | """Get the versions from the NW.js Github changelog""" |
|
0 commit comments