Skip to content

Instantly share code, notes, and snippets.

@thecubic
Last active June 13, 2023 08:43
Show Gist options
  • Save thecubic/e76c67bcd14a21290009a8f7e0028578 to your computer and use it in GitHub Desktop.
Save thecubic/e76c67bcd14a21290009a8f7e0028578 to your computer and use it in GitHub Desktop.
takes PLC record chain, finds a DID's operations, caches stuff
#!/usr/bin/env python3
# written by github.com/thecubic
# hireable for bar and bat mitzvahs and software
import os
import requests
import json
import pprint
url = "https://plc.directory/export"
# it me, but it can also you
me = "did:plc:vnjkyosaxdimztkjsap2qkrs"
# what flies but is not a bird
# team mammal represent
bats = []
# use a cache because both the network and python
# are fucking slow as balls
if os.path.exists("bats.json"):
with open("bats.json") as batcache:
bats = json.load(batcache)
import code
nbats = len(bats)
if not len(bats):
# I will send you the epoch in anger
battime = "1970-01-01T00:00:00.000Z"
else:
battime = bats[-1]["createdAt"]
while True:
newbats = 0
newurl = f"{url}?after={battime}&count=1000"
block = requests.get(newurl)
for line in block.text.split("\n"):
if not line.strip():
continue
try:
obj = json.loads(line)
except json.decoder.JSONDecodeError as e:
print(f"fucked line: {line}")
raise
bats.append(obj)
newbats += 1
if not newbats:
break
nbats += newbats
if battime == obj["createdAt"]:
break
battime = obj["createdAt"]
print(len(bats))
myops = []
# scan it for meeeeee
for record in bats:
if record["did"] == me:
myops.append(record)
for myop in myops:
# to get your actual user number you have to count DIDs, not ops
# 2lazy@thistime
print(f"operation number {bats.index(myop)}:")
pprint.pprint(myop)
print()
# fuck around and find out data is annoying
code.interact(local=locals())
# save batcache
with open("bats.json", "w") as batcache:
json.dump(bats, batcache)
@thecubic
Copy link
Author

lmao find the bug aw fuck

@thecubic
Copy link
Author

177784
operation number 95337:
{'cid': 'bafyreiflkkwduqfy2dgm2smqd6ucumtipbl4x5uijsvqwt4fjjd4mcmaci',
 'createdAt': '2023-05-06T09:46:19.619Z',
 'did': 'did:plc:vnjkyosaxdimztkjsap2qkrs',
 'nullified': False,
 'operation': {'alsoKnownAs': ['at://thecubic.bsky.social'],
               'prev': None,
               'rotationKeys': ['did:key:zQ3shhCGUqDKjStzuDxPkTxN6ujddP4RkEKJJouJGRRkaLGbg',
                                'did:key:zQ3shpKnbdPx3g3CmPf5cRVTPe1HtSwVn5ish3wSnDPQCbLJK'],
               'services': {'atproto_pds': {'endpoint': 'https://bsky.social',
                                            'type': 'AtprotoPersonalDataServer'}},
               'sig': 'X-N5nlBjvDdByE8x0ZCXb3w8zApEN-GJahSGTJD21HtLrQQdzFcjy4HdevWm_XB5rtu8T7t9xqJ_69yAnjKieA',
               'type': 'plc_operation',
               'verificationMethods': {'atproto': 'did:key:zQ3shXjHeiBuRCKmM36cuYnm7YEMzhGnCmCyW92sRJ9pribSF'}}}

operation number 95342:
{'cid': 'bafyreic2ln6kal76boncvkjezeknb33l2osocdvjmbjh6bqxu6nb3ibiki',
 'createdAt': '2023-05-06T09:50:52.228Z',
 'did': 'did:plc:vnjkyosaxdimztkjsap2qkrs',
 'nullified': False,
 'operation': {'alsoKnownAs': ['at://thecubic.net'],
               'prev': 'bafyreiflkkwduqfy2dgm2smqd6ucumtipbl4x5uijsvqwt4fjjd4mcmaci',
               'rotationKeys': ['did:key:zQ3shhCGUqDKjStzuDxPkTxN6ujddP4RkEKJJouJGRRkaLGbg',
                                'did:key:zQ3shpKnbdPx3g3CmPf5cRVTPe1HtSwVn5ish3wSnDPQCbLJK'],
               'services': {'atproto_pds': {'endpoint': 'https://bsky.social',
                                            'type': 'AtprotoPersonalDataServer'}},
               'sig': '160mTloeRpsAVqtXU6ewi2jkEdhbjW0-au-uDgJbQdl37bU2W_ejeDqcAsABEDgyomoy2Tzgz_-QzdgmxUdvXg',
               'type': 'plc_operation',
               'verificationMethods': {'atproto': 'did:key:zQ3shXjHeiBuRCKmM36cuYnm7YEMzhGnCmCyW92sRJ9pribSF'}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment