Last active
October 28, 2023 02:13
-
-
Save HemanthJabalpuri/21233992df1bee2f6bdf2fafb96e25ee to your computer and use it in GitHub Desktop.
F-Droid json parsing test. Below is index-v1.json structure from f-droid. I tried to parse this json using Python (attached below)
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
{ | |
"apps": [ | |
{ | |
"authorName": "Lo\u00efc Teyssier", | |
"categories": [ | |
"Science & Education" | |
], | |
"suggestedVersionName": "1.3.1", | |
"suggestedVersionCode": "14", | |
"issueTracker": "https://github.com/lolo-io/OneList/issues", | |
"license": "MIT", | |
"sourceCode": "https://github.com/lolo-io/OneList", | |
"added": 1568851200000, | |
"icon": "com.lolo.io.onelist.14.png", | |
"packageName": "com.lolo.io.onelist", | |
"lastUpdated": 1604016000000, | |
"localized": { | |
"en-US": { | |
"description": "1List is a simple app to manage several lists from only one screen.\nAdd items to a list with only one click. Browse, view, organize your lists from only one screen.\n\nFeatures :\n\t- User friendly lists management and smooth navigation\n\t- Add, delete, edit items in your lists\n\t- Move items within your lists\n\t- Mark items as done or undone\n\t- Add comments on each items\n\t- Create an unlimited number of lists\n\t- Move, edit, remove your lists\n\t... more to come in the near future\n", | |
"featureGraphic": "featureGraphic_-zO6p3BS0xLAuhxcwHFYOTtFYcg9BEQsyiTN2ILvavs=.png", | |
"name": "1List - Simple Lists for TODO, Shopping, Movies...", | |
"phoneScreenshots": [ | |
"screen1.png", | |
"screen2.png", | |
"screen3.png", | |
"screen4.png", | |
"screen5.png", | |
"screen6.png" | |
], | |
"summary": "Simple app to manage several lists from only one screen" | |
}, | |
"fr-FR": { | |
"featureGraphic": "featureGraphic_-zO6p3BS0xLAuhxcwHFYOTtFYcg9BEQsyiTN2ILvavs=.png" | |
} | |
} | |
}, | |
{ | |
"categories": [ | |
"Games" | |
], | |
"changelog": "https://github.com/mattvchandler/2050/releases", | |
"suggestedVersionName": "1.0.10", | |
"suggestedVersionCode": "190010010", | |
"issueTracker": "https://github.com/mattvchandler/2050/issues", | |
"license": "MIT", | |
"sourceCode": "https://github.com/mattvchandler/2050", | |
"added": 1558051200000, | |
"packageName": "org.mattvchandler.a2050", | |
"lastUpdated": 1693608133000, | |
"localized": { | |
"en-US": { | |
"description": "Much like the original, you start with small numbered pieces and combine\nlike-numbered pieces into progressively larger ones, working toward 2048.\n\nUnlike the original, the pieces are free to move in any direction, bounce off of\nthe walls and each other, are subject to gravity, and grow progressively larger.\n", | |
"featureGraphic": "featureGraphic_Nj1yhypMv3b68y_bv7xacNkeyv23BMkgH2mb3xy-hGU=.png", | |
"icon": "icon_3BMQD76YZDYHbtVP8WR8CTKi6E7pd6L82YveKdLHjR4=.png", | |
"name": "2050", | |
"phoneScreenshots": [ | |
"scrn_phone_land_1.png", | |
"scrn_phone_land_2.png", | |
"scrn_phone_land_3.png", | |
"scrn_phone_port_1.png", | |
"scrn_phone_port_2.png", | |
"scrn_phone_settings.png" | |
], | |
"sevenInchScreenshots": [ | |
"scrn_tablet_7_land.png", | |
"scrn_tablet_7_port.png" | |
], | |
"summary": "A game loosely based on 2048, but with circles instead of squares", | |
"tenInchScreenshots": [ | |
"scrn_tablet_10_land.png", | |
"scrn_tablet_10_port.png" | |
] | |
}, | |
"id": { | |
"description": "Sama seperti yang asli, Anda mulai dengan potongan angka kecil dan gabung potongan yang sama angka sehingga menjadi potongan yang lebih besar ke angka 2048.\n\nBerbeda dengan yang asli, potongannya bebas bergerak ke arah mana pun, mantul di dinding dan satu sama lain, tunduk pada gravitasi, dan tumbuh membesar.\n", | |
"summary": "Sebuah permainan yang didasarkan pada 2048, tapi menggunakan lingkaran, bukan ko" | |
} | |
} | |
} | |
], | |
"packages": { | |
"com.lolo.io.onelist": [ | |
{ | |
"added": 1604016000000, | |
"apkName": "com.lolo.io.onelist_14.apk", | |
"hash": "31b226b7d595f31a636a9ee3772bde3e502517ac8855c56a4258d140648b2df2", | |
"hashType": "sha256", | |
"minSdkVersion": 16, | |
"packageName": "com.lolo.io.onelist", | |
"sig": "88d4c71efea79488eb63d432950ca342", | |
"signer": "f4f7234076e3f87babf78d0b3a2321f985958212151a528390284e3e5a9262dd", | |
"size": 2539126, | |
"srcname": "com.lolo.io.onelist_14_src.tar.gz", | |
"targetSdkVersion": 29, | |
"uses-permission": [ | |
[ | |
"android.permission.WRITE_EXTERNAL_STORAGE", | |
null | |
], | |
[ | |
"android.permission.READ_EXTERNAL_STORAGE", | |
null | |
] | |
], | |
"versionCode": 14, | |
"versionName": "1.3.1" | |
}, | |
{ | |
"added": 1577664000000, | |
"apkName": "com.lolo.io.onelist_12.apk", | |
"hash": "8e1a324244b8f3184e1da0f33d9a6fb7112d01414837ba7d470746938e15e076", | |
"hashType": "sha256", | |
"minSdkVersion": 16, | |
"packageName": "com.lolo.io.onelist", | |
"sig": "88d4c71efea79488eb63d432950ca342", | |
"signer": "f4f7234076e3f87babf78d0b3a2321f985958212151a528390284e3e5a9262dd", | |
"size": 2434324, | |
"srcname": "com.lolo.io.onelist_12_src.tar.gz", | |
"targetSdkVersion": 28, | |
"uses-permission": [ | |
[ | |
"android.permission.WRITE_EXTERNAL_STORAGE", | |
null | |
], | |
[ | |
"android.permission.READ_EXTERNAL_STORAGE", | |
null | |
] | |
], | |
"versionCode": 12, | |
"versionName": "1.2.3" | |
}, | |
{ | |
"added": 1577059200000, | |
"apkName": "com.lolo.io.onelist_11.apk", | |
"hash": "6412a2b1c1629c0936505a0654440c266cc822be6d40f1a89d9b723b306a9452", | |
"hashType": "sha256", | |
"minSdkVersion": 16, | |
"packageName": "com.lolo.io.onelist", | |
"sig": "88d4c71efea79488eb63d432950ca342", | |
"signer": "f4f7234076e3f87babf78d0b3a2321f985958212151a528390284e3e5a9262dd", | |
"size": 2434383, | |
"srcname": "com.lolo.io.onelist_11_src.tar.gz", | |
"targetSdkVersion": 28, | |
"uses-permission": [ | |
[ | |
"android.permission.WRITE_EXTERNAL_STORAGE", | |
null | |
], | |
[ | |
"android.permission.READ_EXTERNAL_STORAGE", | |
null | |
] | |
], | |
"versionCode": 11, | |
"versionName": "1.2.2" | |
} | |
], | |
"org.mattvchandler.a2050": [ | |
{ | |
"added": 1693608133000, | |
"apkName": "org.mattvchandler.a2050_190010010.apk", | |
"hash": "98a0e75e589c319093db56cf98bfa32d920b9436a9cbe7c30b32dcf7a4a6d284", | |
"hashType": "sha256", | |
"minSdkVersion": 19, | |
"nativecode": [ | |
"arm64-v8a", | |
"armeabi-v7a", | |
"x86", | |
"x86_64" | |
], | |
"packageName": "org.mattvchandler.a2050", | |
"sig": "2805fa546d280abddb9875ff323b3565", | |
"signer": "b5b82827a3823eff1e86b683977d4a61171941d7a2a9c8632839ad8a45f28759", | |
"size": 5079962, | |
"srcname": "org.mattvchandler.a2050_190010010_src.tar.gz", | |
"targetSdkVersion": 33, | |
"uses-permission": [ | |
[ | |
"android.permission.ACCESS_FINE_LOCATION", | |
null | |
], | |
[ | |
"android.permission.ACCESS_COARSE_LOCATION", | |
null | |
], | |
[ | |
"org.mattvchandler.a2050.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION", | |
null | |
] | |
], | |
"versionCode": 190010010, | |
"versionName": "1.0.10" | |
}, | |
{ | |
"added": 1645833600000, | |
"apkName": "org.mattvchandler.a2050_190010009.apk", | |
"hash": "9ad9c487017ee06a8f0d5507f775cd19892844e7201e4948a517b90c758a5fbc", | |
"hashType": "sha256", | |
"minSdkVersion": 19, | |
"nativecode": [ | |
"arm64-v8a", | |
"armeabi-v7a", | |
"x86", | |
"x86_64" | |
], | |
"packageName": "org.mattvchandler.a2050", | |
"sig": "2805fa546d280abddb9875ff323b3565", | |
"signer": "b5b82827a3823eff1e86b683977d4a61171941d7a2a9c8632839ad8a45f28759", | |
"size": 4922071, | |
"srcname": "org.mattvchandler.a2050_190010009_src.tar.gz", | |
"targetSdkVersion": 32, | |
"uses-permission": [ | |
[ | |
"android.permission.ACCESS_FINE_LOCATION", | |
null | |
], | |
[ | |
"android.permission.ACCESS_COARSE_LOCATION", | |
null | |
] | |
], | |
"versionCode": 190010009, | |
"versionName": "1.0.9" | |
}, | |
{ | |
"added": 1604793600000, | |
"apkName": "org.mattvchandler.a2050_190010008.apk", | |
"hash": "4c0dc682010b5ec419e12fc50c14887edfeec6fea4c8cbc4ca0641386e1970b1", | |
"hashType": "sha256", | |
"minSdkVersion": 19, | |
"nativecode": [ | |
"arm64-v8a", | |
"armeabi-v7a", | |
"x86", | |
"x86_64" | |
], | |
"packageName": "org.mattvchandler.a2050", | |
"sig": "2805fa546d280abddb9875ff323b3565", | |
"signer": "b5b82827a3823eff1e86b683977d4a61171941d7a2a9c8632839ad8a45f28759", | |
"size": 4396556, | |
"srcname": "org.mattvchandler.a2050_190010008_src.tar.gz", | |
"targetSdkVersion": 30, | |
"uses-permission": [ | |
[ | |
"android.permission.ACCESS_FINE_LOCATION", | |
null | |
] | |
], | |
"versionCode": 190010008, | |
"versionName": "1.0.8" | |
} | |
] | |
} | |
} |
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
import argparse, os, sys, json | |
data = None | |
app_data = {} | |
def print_pkg(pkg): | |
print(f'Name\t\t: {pkg["name"]}') | |
print(f'Summary\t\t: {pkg["summary"]}') | |
print(f'Category\t: {pkg["category"]}') | |
print(f'min SDK\t\t: {pkg["minSdkVersion"]}') | |
def fill_keys(app): | |
name = summary = None | |
minSdkVersion = 999 | |
if 'name' in app: | |
name = app['name'] | |
if 'localized' in app: | |
langs = [ 'en-US', 'en_US', 'en-GB', 'en' ] | |
for item in app['localized']: | |
if item in langs: | |
if 'name' in app['localized'][item]: | |
name = app['localized'][item]['name'] | |
if 'summary' in app['localized'][item]: | |
summary = app['localized'][item]['summary'] | |
if name and summary: | |
break | |
category = ', '.join(map(str, app['categories'])) | |
pkg = app['packageName'] | |
if pkg in data['packages']: | |
apk_data = data['packages'][pkg][0] | |
if 'minSdkVersion' in apk_data: | |
minSdkVersion = apk_data['minSdkVersion'] | |
app_data[pkg] = { | |
'name': name, | |
'category': category, | |
'summary': summary, | |
'minSdkVersion': minSdkVersion | |
} | |
def filter_by_minsdk(apilevel): | |
minSdkVersion = 999 | |
for app in data['apps']: | |
pkg = app['packageName'] | |
if 'minSdkVersion' in data['packages'][pkg][0]: | |
minSdkVersion = data['packages'][pkg][0]['minSdkVersion'] | |
if minSdkVersion <= apilevel: | |
fill_keys(app) | |
# write json with all the app specific data | |
# follow index-v1.json format | |
def debug(app): | |
jsonf = 'debug.json' | |
if os.path.exists(jsonf): | |
# since file exists, append data to it | |
# if data is not already present | |
with open(jsonf, 'r') as file: | |
result_json = json.load(file) | |
index = -1 | |
for app_item in result_json['apps']: | |
if app_item['packageName'] == app['packageName']: | |
index = result_json['apps'].index(app) | |
if index != -1: | |
result_json['apps'][index] = app | |
else: | |
result_json['apps'].append(app) | |
result_json['packages'][app['packageName']] = data['packages'][app['packageName']] | |
else: | |
result_json = {} | |
result_json['apps'] = [ | |
app # object | |
] | |
result_json['packages'] = { | |
app['packageName']: data['packages'][app['packageName']] # array | |
} | |
with open(jsonf, 'w') as outfile: | |
outfile.write(json.dumps(result_json, indent = 2)) | |
def parse_pkg(pkg): | |
for app in data['apps']: | |
if pkg: | |
if app['packageName'] == pkg: | |
fill_keys(app) | |
print_pkg(app_data[pkg]) | |
#debug(app) | |
break | |
else: | |
fill_keys(app) | |
def write_to_file(outf): | |
result_json = json.dumps(app_data, indent = 2) | |
with open(outf, 'w') as outfile: | |
outfile.write(result_json) | |
def main(inf, outf, pkg, apilevel): | |
global data | |
with open(inf, 'r') as file: | |
data = json.load(file) | |
if apilevel: | |
filter_by_minsdk(int(apilevel)) | |
else: | |
parse_pkg(pkg) | |
if outf: | |
write_to_file(outf) | |
if __name__ == '__main__': | |
if not sys.version_info >= (3, 7): | |
abort('Requires Python 3.7+') | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--outfile', help='output json file path') | |
parser.add_argument('--apilevel', help='list apps with minimum SDK version less than apilevel') | |
parser.add_argument('--pkg', help='An optional pkg name') | |
parser.add_argument('infile', help='input index-v1.json') | |
args = parser.parse_args() | |
main(args.infile, args.outfile, args.pkg, args.apilevel) |
Author
HemanthJabalpuri
commented
Oct 27, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment