Skip to content

Instantly share code, notes, and snippets.

@NiklasRosenstein
Created June 19, 2018 12:40
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 NiklasRosenstein/7b57769ad7a0c61cd16ba003e11784a8 to your computer and use it in GitHub Desktop.
Save NiklasRosenstein/7b57769ad7a0c61cd16ba003e11784a8 to your computer and use it in GitHub Desktop.
Watch all repositories that you have read/write/admin access to.
import requests
API = 'https://api.github.com'
session = requests.Session()
session.auth = ('YourUsername', 'YourPassword')
def repos():
page = 0
while True:
repos = session.get(API + '/user/repos?page={}'.format(page)).json()
if not repos:
break
yield from repos
page += 1
def subscribe(owner, repo):
url = API + '/repos/{}/{}/subscription'.format(owner, name)
return session.put(url, json={'subscribed': 'true'}).json()
def main():
for repo in repos():
owner, name = repo['owner']['login'], repo['name']
resp = subscribe(owner, name)
if not resp['subscribed']:
print('error: unable to subscribe to {}/{}'.format(owner, name))
else:
print('subscribed to {}/{}'.format(owner, name))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment