Skip to content

Instantly share code, notes, and snippets.

@danigm
Created May 5, 2021 14:49
Show Gist options
  • Save danigm/26022296d6ff79a5be4d9aaa496a2146 to your computer and use it in GitHub Desktop.
Save danigm/26022296d6ff79a5be4d9aaa496a2146 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from requests import get
from requests import delete
from json import dumps
USER = 'danigm'
PASSWORD = 'XXXX'
ORG = 'endlessm'
ACCEPT = { 'accept' : 'application/vnd.github.v3+json' }
def list_watched2(user, pw, page=1):
url = 'https://api.github.com/user/subscriptions'
auth = (user, pw)
params = { 'per_page': 100, 'page': page }
r = get(url, auth=auth, headers=ACCEPT, params=params)
return [i['url'] for i in r.json()]
def list_watched(user, pw, f=None):
page = 1
content = list_watched2(user, pw, page)
output = list(content)
while content:
page += 1
content = list_watched2(user, pw, page)
if content:
output += list(content)
return filter(f, output)
def unwatch(user, pw, repo_url):
url = '{0}/subscription'.format(repo_url)
r = delete(url, auth=(user, pw), headers=ACCEPT)
return { 'status' : r.status_code, 'repo' : repo_url }
def unwatch_all(user, pw):
repos = list_watched(user, pw, lambda x: ORG in x)
result = [ unwatch(user, pw, repo) for repo in repos ]
return dumps(result, indent=4)
print(unwatch_all(USER, PASSWORD))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment