Created
June 19, 2018 12:40
-
-
Save NiklasRosenstein/7b57769ad7a0c61cd16ba003e11784a8 to your computer and use it in GitHub Desktop.
Watch all repositories that you have read/write/admin access to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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