Last active
February 9, 2022 15:51
-
-
Save dphiffer/25c34909b72d9e0c988c297381079604 to your computer and use it in GitHub Desktop.
Revue export script
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
api_keys: | |
your_list: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
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 python | |
import requests | |
import yaml | |
def export_issues(name, api_key): | |
with open(f"{name}_issues.json", "w") as file: | |
file.write(load_from_revue('issues', api_key)) | |
print(f" saved {name}_issues.json") | |
def export_subscribers(name, api_key): | |
with open(f"{name}_subscribers.json", "w") as file: | |
file.write(load_from_revue('subscribers', api_key)) | |
print(f" saved {name}_subscribers.json") | |
def load_from_revue(list, api_key): | |
base_url = "https://www.getrevue.co/api" | |
rsp = requests.get(f"{base_url}/v2/{list}", headers={ | |
"Authorization": f"Token {api_key}" | |
}) | |
rsp.raise_for_status() | |
return rsp.text | |
if __name__ == '__main__': | |
api_keys = {} | |
with open("config.yml", "r") as file: | |
config = yaml.safe_load(file) | |
for name, api_key in config['api_keys'].items(): | |
print(f"exporting {name}") | |
export_issues(name, api_key) | |
export_subscribers(name, api_key) | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment