Skip to content

Instantly share code, notes, and snippets.

@slezica
Last active May 2, 2023 18:23
Show Gist options
  • Save slezica/bbe58316c9cf09c22099eade87bcd49c to your computer and use it in GitHub Desktop.
Save slezica/bbe58316c9cf09c22099eade87bcd49c to your computer and use it in GitHub Desktop.
Print a list of Decentraland entity IDs for emotes deployed after a certain date.
#!/usr/bin/env python3
import sys
import json
import urllib.request
def http_get(url):
headers = {
"User-Agent": "urllib" # Important! If empty, 403 Forbidden
}
request = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
return content
# Check the server status:
about = json.loads(http_get('https://peer.decentraland.org/about'))
if not about['healthy']:
print("Server is not healthy!")
sys.exit(1)
# Get the list of snapshots:
snapshots = json.loads(http_get('https://peer.decentraland.org/content/snapshots'))
# Obtain the file identifier tor the emote snapshot, and download it:
emote_snapshot_hash = snapshots['entities']['emote']['hash']
emote_snapshot_url = f'https://peer.decentraland.org/content/contents/{emote_snapshot_hash}'
emote_snapshot = http_get(emote_snapshot_url)
# IMPORTANT:
# This file is potentially huge (such is the case for profiles). We happen to know that
# the emote snapshot is tiny, so we can buffer it like above, and even split it in-memory.
emote_snapshot_lines = emote_snapshot.split('\n')
# Check the header:
if emote_snapshot_lines[0] != '### Decentraland json snapshot':
print("Invalid snapshot header!")
sys.exit(1)
# Cool! Now, let's find all emote entities that were deployed after some arbitrary time:
emote_min_timestamp = 1667798160000
for line in emote_snapshot_lines[1:]:
if len(line) == 0:
break # the snapshot can end with a newline
emote = json.loads(line)
if emote['localTimestamp'] >= emote_min_timestamp:
print(emote['entityId'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment