datonic / hub

🏛️ Open Data, together
https://publish.obsidian.md/davidgasquez/Open+Data
MIT License
8 stars 0 forks source link

Collect existing datapackages #21

Open davidgasquez opened 1 year ago

davidgasquez commented 1 year ago

Basically, get these files: https://github.com/search?q=path%3A**%2Fdatapackage.json&type=code

davidgasquez commented 1 year ago

Some quick code to do that. :point_down:


import requests

def search_code(query, page=0):
    url = "https://api.github.com/search/code"
    headers = {
        "Accept": "application/vnd.github+json",
        "Authorization": f"Bearer {os.getenv("BEARER")}"
    }

    # Define the query parameters
    params = {
        "q": query,
        "page": page
    }

    # Make the GET request
    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    return response.json()

data = search_code("filename:datapackage.yaml")

all_items = []
page = 1

while page:
    items = search_code("filename:datapackage.yaml", page)['items']
    all_items.extend(items)
    if not items:
        page = None
    else:
        page = page + 1