Skip to content

Instantly share code, notes, and snippets.

@slackorama
Last active January 8, 2019 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slackorama/8a795e18e7331f848e74 to your computer and use it in GitHub Desktop.
Save slackorama/8a795e18e7331f848e74 to your computer and use it in GitHub Desktop.
Make Github starred repos bookmarks in pinboard. I wish IFTTT did this.
#!/usr/bin/env python
# send github starred repos to pinboard
# Get the token here:
# https://api.pinboard.in/v1/user/api_token/info
from __future__ import print_function
import sys
import requests
GH_URL = 'https://api.github.com/users/{username}/starred'
ADD_URL = 'https://api.pinboard.in/v1/posts/add'
GET_URL = 'https://api.pinboard.in/v1/posts/get'
def get_starred(username):
"Get the starred repos for user."
return requests.get(GH_URL.format(username=username)).json()
def main(args):
"main"
username = args[1]
token = args[2]
pb_session = requests.Session()
pb_session.params = {
'auth_token': '{username}:{token}'.format(username=username,
token=token)}
for repo in get_starred(username):
url = repo.get('html_url')
exists = pb_session.get(GET_URL, params={'url': url})
exists.raise_for_status()
if exists.status_code != 200:
print('Bad response')
continue
# uh...just look for url in the response..skip XML parsing
if url not in exists.text:
params = {'url': url,
'description': repo.get('full_name'),
'extended': repo.get('description'),
'tags': 'github,starred'}
update = pb_session.get(ADD_URL, params=params)
update.raise_for_status()
print('Added {0}'.format(repo.get('name')))
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage: {0} [github username] [pinboard token]'.format(sys.argv[0]))
sys.exit(-1)
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment