Skip to content

Instantly share code, notes, and snippets.

@Tehsurfer
Last active August 16, 2019 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tehsurfer/95fdb8bb4995beeb674ddc45f5438620 to your computer and use it in GitHub Desktop.
Save Tehsurfer/95fdb8bb4995beeb674ddc45f5438620 to your computer and use it in GitHub Desktop.
Python functions to create, update and get jsonstorage.net files
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