Spaces:
Runtime error
Runtime error
from django.shortcuts import render | |
from django.http import JsonResponse, HttpResponse | |
import requests | |
import json | |
import base64 | |
authToken = 'fab57498544244e38bfc2741880f8d61:ed9628295b0642e1b38308795c9cdadd58012df4ceb84a3b9d441c017a1eeac0' | |
def home(request): | |
message = "Welcome at home!" | |
return JsonResponse({'message': message}) | |
def establishment_List(request): | |
global authToken | |
url = "https://101smokeshop-uat.revelup.com/enterprise/Establishment/?order_by=id&limit=10&offset=0" | |
headers = { | |
'API-AUTHENTICATION': authToken | |
} | |
response = requests.request("GET", url, headers=headers) | |
data = response.json()["objects"] | |
urlBase = "https://101smokeshop-uat.revelup.com" | |
for i in range(len(data)): | |
try: | |
imgData = requests.request("GET", urlBase+data[i]["logo_img"], headers=headers).json() | |
print(imgData) | |
data[i]["logo_img"] = imgData["image_url"] | |
except: | |
pass | |
try: | |
data[i]["address"] = requests.request("GET", urlBase+data[i]["address"], headers=headers).json() | |
except: | |
pass | |
return JsonResponse({"data": data}) | |
def resources_forward(request, resource_name,image_id): | |
url = "https://101smokeshop-uat.revelup.com/resources/"+resource_name+"/"+image_id | |
headers = { | |
'API-AUTHENTICATION': authToken | |
} | |
response = requests.request("GET", url, headers=headers) | |
imageUrl = response.json()["image_url"] | |
response = requests.request("GET", imageUrl) | |
return HttpResponse(response.content, content_type=response.headers['Content-Type']) | |
def product_category(request): | |
global authToken | |
url = "https://101smokeshop-uat.revelup.com/products/ProductCategory/" | |
headers = { | |
'API-AUTHENTICATION': authToken | |
} | |
response = requests.request("GET", url, headers=headers) | |
data = response.json()["objects"] | |
return JsonResponse({"data": data}) |