Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
API-examples/utils.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
40 lines (32 sloc)
964 Bytes
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 python2 | |
# -- coding: utf-8 -- | |
import os | |
import sys | |
import requests | |
from getpass import getpass | |
# Using this method of secret storing: | |
# https://stackoverflow.com/questions/25501403/storing-the-secrets-passwords-in-a-separate-file | |
try: | |
import credentials | |
token = credentials.API_key | |
except Exception as e: | |
print (e) | |
token = getpass() | |
credentials_file = open("credentials.py", "w") | |
credentials_file.writelines("API_key = \"" + token +"\"") | |
credentials_file.close | |
API_URL = 'https://www.muckrock.com/api_v1/' | |
def get_api_key(): | |
return token | |
def get_headers(token=None): | |
if token: | |
return { | |
'Authorization': 'Token %s' % token, | |
'content-type': 'application/json' | |
} | |
else: | |
return {'content-type': 'application/json'} | |
def display_progress(current, total): | |
percent = (current / total) * 100.00 | |
sys.stdout.write("\r%d%%" % percent) | |
sys.stdout.flush() |