Skip to content

Instantly share code, notes, and snippets.

@danleyb2
Created January 17, 2016 17:35
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 danleyb2/a720073af59a07d88ffb to your computer and use it in GitHub Desktop.
Save danleyb2/a720073af59a07d88ffb to your computer and use it in GitHub Desktop.
load Link header into a dictionary
#!/usr/bin/env python3.4
#### Nyaundi Brian <ndieksman@gmail.com>
from pprint import pprint
links_string_from_header='<https://api.github.com/search/users?q=location%3AKenya&page=4>; rel="next",' \
' <https://api.github.com/search/users?q=location%3AKenya&page=34>; rel="last", ' \
'<https://api.github.com/search/users?q=location%3AKenya&page=1>; rel="first", ' \
'<https://api.github.com/search/users?q=location%3AKenya&page=2>; rel="prev"'
links_dict={
rel.split('=')[1].strip('"') : link.strip('<> ')
for (link,rel) in (url_rel.split(';')
for url_rel in links_string_from_header.split(','))
}
pprint(links_dict)
print()
print('Next '+links_dict['next'])
print('Prev '+links_dict['prev'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment