Created
January 17, 2016 17:35
-
-
Save danleyb2/a720073af59a07d88ffb to your computer and use it in GitHub Desktop.
load Link header into a dictionary
This file contains 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
#!/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