# This is where I am right now.
# It shows tx ids, in theory, didn't find one on a block explorer, but
not commit hashes.
# This sourcefile is in https://github.com/xloem/gitlakepy under
scripts/git-remote-arweave
# This content is commit 67efbad6b03ed7a0ad53fac83a79d5b845ba177b

#!/usr/bin/env python3

import json
import requests

GRAPHQL_URI='https://arweave.net/graphql'

def get_page(uri, Type, cursor=''):
        resp = requests.post(uri,
                json={'query':'''
                        query {
                                transactions(
                                        tags: [
                                                { name: "Type", values: [''' + 
json.dumps(Type) + '''] }
                                        ]
                                        after: ''' + json.dumps(cursor) + '''
                                ) {
                                        edges {
                                                node {
                                                        id
                                                        owner {
                                                                address
                                                        }
                                                        tags {
                                                                name
                                                                value
                                                        }
                                                }
                                                cursor
                                        }
                                }
                        }
                '''}
        )
        cursor = None
        data = resp.json()
        if 'data' not in data:
                raise Exception(data)
        edges = data['data']['transactions']['edges']
        if len(edges):
                cursor = edges[-1]['cursor']
        objects = [
                dict(
                        txid = node['id'],
                        owner = node['owner']['address'],
                        tags = {tag['name']: tag['value'] for tag in 
node['tags']}
                )
                for node in (edge['node'] for edge in edges)
        ]
        return objects, cursor

def yield_all(uri, Type):
        cursor = None
        while True:
                objs, cursor = get_page(uri, Type, cursor = cursor)
                if not len(objs):
                        break
                yield from objs


for obj in yield_all(GRAPHQL_URI, 'update-ref'):
        print(obj)

raise Exception('===> This is just a prototype to show git updates
from arweave. <===')

Reply via email to