Created
October 15, 2023 14:03
-
-
Save Niklp09/9715aca011120d1cba7b81329dfd18e1 to your computer and use it in GitHub Desktop.
Script to count the git hosts used on ContentDB; tested w/ python 3.11
This file contains hidden or 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
| # Script to count the git hosts used on ContentDB; tested w/ python 3.11 | |
| import requests, json, re, time, operator | |
| hosts = {} | |
| pkgnum = 0 | |
| def val(key): | |
| if key in hosts.keys(): | |
| return hosts[key] | |
| else: | |
| return 0 | |
| def regex_url(url): # https://regex101.com/r/cYN1MT/1 | |
| split = re.split("https?://(www\.)?([a-zA-Z0-9]+)(\.[a-zA-Z0-9.-]+)", url) | |
| return split[2] + split[3] | |
| request = requests.get("https://content.minetest.net/api/packages/") | |
| packages = json.loads(request.content) | |
| for package in packages: | |
| pkgurl = f"https://content.minetest.net/api/packages/{package['author']}/{package['name']}" | |
| pkgnum = pkgnum + 1 | |
| print(f"Check package #{pkgnum}: {pkgurl}") | |
| req = requests.get(pkgurl) | |
| pkg = None | |
| try: | |
| pkg = json.loads(req.content) | |
| except: | |
| print(f"Error in decoding response for {pkgurl} (maybe too many requests)") | |
| #print(pkg.content) # debug, enable if needed | |
| time.sleep(5) | |
| continue | |
| if pkg["repo"] != None: | |
| host = regex_url(pkg["repo"]) | |
| hosts[host] = val(host) + 1 | |
| else: | |
| hosts["No repo"] = val("No repo") + 1 | |
| time.sleep(1.2) # ratelimit | |
| hosters = dict(sorted(hosts.items(), key = operator.itemgetter(1), reverse = True)) | |
| for host in hosters: | |
| print(f"{host} Packages: {hosters[host]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment