-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2021 UuuNyaa <[email protected]> | ||
# This file is part of blender_mmd_assets. | ||
|
||
import json | ||
import sys | ||
|
||
import requests | ||
|
||
|
||
def list_asset_download_counts(session, repo): | ||
response = session.get(f'https://api.github.com/repos/{repo}/releases') | ||
response.raise_for_status() | ||
|
||
releases = json.loads(response.text) | ||
|
||
assets = [] | ||
for release in releases: | ||
for asset in release['assets']: | ||
assets.append({ | ||
'updated_at': asset['updated_at'], | ||
'name': asset['name'], | ||
'size': asset['size'], | ||
'download_count': asset['download_count'], | ||
}) | ||
|
||
return assets | ||
|
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 2: | ||
print(f'ERROR: invalid arguments: {[a for a in sys.argv]}', file=sys.stderr) | ||
exit(1) | ||
|
||
repo = sys.argv[1] | ||
|
||
session = requests.Session() | ||
print(json.dumps(list_asset_download_counts(session, repo), indent=2, ensure_ascii=False)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2021 UuuNyaa <[email protected]> | ||
# This file is part of blender_mmd_assets. | ||
|
||
# Get latest asset download URL | ||
import json | ||
import requests | ||
|
||
repo = 'UuuNyaa/blender_mmd_assets' | ||
response = requests.get( | ||
f'https://api.github.com/repos/{repo}/releases/latest', | ||
headers={'Accept': 'application/vnd.github.v3+json'} | ||
) | ||
|
||
asset = json.loads(response.text)['assets'][0] | ||
browser_download_url = asset['browser_download_url'] | ||
|
||
# Get assets zip file | ||
response = requests.get( | ||
browser_download_url, | ||
headers={'Accept': 'application/zip'} | ||
) | ||
|
||
# Extract assets.json | ||
import io | ||
import zipfile | ||
|
||
with zipfile.ZipFile(io.BytesIO(response.content)) as zip: | ||
assets_json = zip.read('assets.json').decode('utf-8') | ||
|
||
print(assets_json) |