-
-
Save Nek/2a5eb31ef6b058bd036814e5c24d5853 to your computer and use it in GitHub Desktop.
This is a very basic no-frills scraper to retrieve the metadata and digital assets from all tokens minted on hicetnunc.xyz. I share this as a starting point for people who want to experiment with building alternative views on the works created on the platform or preserve the data. Feel free to improve upon this or add additional features.
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
import requests | |
import os | |
import ipfsApi | |
api = ipfsApi.Client(host='https://ipfs.infura.io', port=5001) | |
url = "https://better-call.dev/v1/contract/mainnet/KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton/tokens" | |
r = requests.get(url) | |
data = r.json() | |
format2suffix = {} | |
format2suffix['image/png'] = "png" | |
format2suffix['image/jpeg'] = "jpg" | |
format2suffix['video/mp4'] = "mp4" | |
format2suffix['image/gif'] = "gif" | |
format2suffix['video/quicktime'] = "mov" | |
format2suffix['image/svg+xml'] = "svg" | |
format2suffix['audio/mpeg'] = "mpg" | |
format2suffix['application/pdf'] = "pdf" | |
format2suffix['image/tiff'] = "tif" | |
format2suffix['video/avi'] = "avi" | |
format2suffix['image/webp'] = "webp" | |
format2suffix['image/bmp'] = "bmp" | |
format2suffix['video/x-matroska'] = "mkv" | |
format2suffix['video/webm'] = "webm" | |
assetFolder = "assets/" | |
os.makedirs(assetFolder,exist_ok=True) | |
os.chdir(assetFolder) | |
print(len(data),"tokens") | |
for i in range(len(data)): | |
#print ("token data",data[i]) | |
if "token_info" in data[i]: | |
if "formats" in data[i]["token_info"]: | |
mimeType = data[i]["token_info"]["formats"][0]["mimeType"] | |
uri = data[i]["token_info"]["formats"][0]["uri"].split("ipfs://")[1] | |
if mimeType in format2suffix: | |
saveName = str(data[i]["token_id"])+"."+format2suffix[mimeType] | |
if not os.path.exists(saveName): | |
print("downloading",uri) | |
api.get(uri) | |
if os.path.exists(uri): | |
os.rename(uri,saveName) | |
else: | |
print("unknown mime type:",data[i]["token_info"]["formats"][0]["mimeType"]) | |
else: | |
print ("incomplete token data:",data[i]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment