Skip to content

Instantly share code, notes, and snippets.

@av1m
Last active December 16, 2021 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save av1m/ec65f8f9b44ac24bc714322350730b8f to your computer and use it in GitHub Desktop.
Save av1m/ec65f8f9b44ac24bc714322350730b8f to your computer and use it in GitHub Desktop.
Git | Github scripts
"""Updates requirements.txt to the latest version of all dependencies.
You must have == as a dependency specification
You need to define the FILE variable
"""
# coding: utf-8
import requests
FILE = "/path/to/requirements.txt"
with open(FILE) as out:
requirements = out.readlines()
updated_requirements = []
for line in requirements:
if line.startswith("#") or len(line.strip()) == 0:
updated_requirements.append(line)
continue
project, version = line.split("==")
pypi = requests.get(f"https://pypi.org/pypi/{project}/json")
last_version = pypi.json()['info']['version']
if last_version != version.removesuffix("\n"):
version = last_version + "\n"
updated_requirements.append(f"{project}=={version}")
with open(FILE, "w") as infile:
infile.writelines(updated_requirements)
"""Recover the list of repository for which I contributed to
You must set the GITHUB_TOKEN
We use the GraphQL API : https://docs.github.com/en/graphql/overview/explorer
"""
import requests
import json
GITHUB_TOKEN = ""
query = '{ user(login: "av1m") { repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY], includeUserRepositories: true, privacy: PUBLIC, orderBy: {field: STARGAZERS, direction: DESC}) { totalCount edges { node { forkCount stargazerCount name description url } } } } }'
request = requests.post(
"https://api.github.com/graphql",
json={"query": query},
headers={"Authorization": f"token {GITHUB_TOKEN}"},
)
repositories = (
request.json().get("data").get("user").get("repositoriesContributedTo").get("edges")
)
with open("contributions.json", "w") as outfile:
json.dump(repositories, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment