Last active
August 16, 2019 04:14
-
-
Save Tehsurfer/95fdb8bb4995beeb674ddc45f5438620 to your computer and use it in GitHub Desktop.
Python functions to create, update and get jsonstorage.net files
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
import requests | |
# Update or create storage bin | |
def put_json_storage(to_publish, storage_name): | |
headers = {'Content-Type': "application/json; charset=utf-8",'dataType': "json"} | |
data = json.dumps({'data': to_publish}) | |
url = f'https://jsonstorage.net/api/items/{storage_name}' | |
resp = requests.put(url, headers=headers, data=data) | |
if resp.status_code == 200 or 201: | |
print(f'Data successfull uploaded: {resp.json()})') | |
else: | |
print(f'Error! Could not upload to the database: {resp.json()}') | |
# Retrieve Storage | |
def get_json_storage(storage_name): | |
resp = requests.get(url) | |
if resp.status_code == 200: | |
return resp.json() | |
else: | |
print(f'Error! Could not connect to the database: {url} /' | |
f' Error was: {resp.json()}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment