From 00ea089a0b9f015b77de175acba9ae9420ad5441 Mon Sep 17 00:00:00 2001 From: Nathan Probert <109328434+nathan-probert@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:47:33 -0400 Subject: [PATCH] remove example (#35) * remove example * not sure what happened last time lol --- examples/create_image.py | 58 ---------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 examples/create_image.py diff --git a/examples/create_image.py b/examples/create_image.py deleted file mode 100644 index 6bb4453..0000000 --- a/examples/create_image.py +++ /dev/null @@ -1,58 +0,0 @@ -import requests -import mimetypes -from image_handler_client.schemas.image_info import ImageStatus -import os -from dotenv import load_dotenv - -# Quick script to test our POST image/create endpoint -# See also imaginate_api/templates/index.html for other ways to call the same endpoint -load_dotenv() - -# First type of call (via bytes) -IMAGE = "examples/images/pokemon.png" -URL = "http://127.0.0.1:5000/image/create" -MIME = mimetypes.guess_type(IMAGE) -PEXELS_BASE_URL = "https://api.pexels.com/v1" - -if not MIME: - print("Could not guess file type") - exit(1) -files = {"file": (IMAGE.split("/")[-1], open(IMAGE, "rb"), MIME[0])} -response = requests.post( - URL, - {"real": True, "date": 1, "theme": "pokemon", "status": ImageStatus.UNVERIFIED.value}, - files=files, -) -if response.ok: - print(f"Endpoint returned: {response.json()}") -else: - print(f"Endpoint returned: {response.status_code}") - -# Second type of call (via Pexels) -QUERY = "pokemon" -TOTAL_RESULTS = 1 # Max per page is 80: https://www.pexels.com/api/documentation/#photos-search__parameters__per_page -response = requests.get( - f"{PEXELS_BASE_URL}/search", - params={"query": QUERY, "per_page": TOTAL_RESULTS}, - headers={"Authorization": os.getenv("PEXELS_TOKEN")}, -) -response_data = response.json() -if TOTAL_RESULTS > response_data["total_results"]: - print(f"Requested {TOTAL_RESULTS} > Total {response_data['total_results']}") -photos_data = response_data["photos"] -for photo in photos_data: - response = requests.post( - URL, - { - "url": photo["src"]["original"], - "real": True, - "date": 1, - "theme": "pokemon", - "status": ImageStatus.UNVERIFIED.value, - }, - files=files, - ) - if response.ok: - print(f"Endpoint returned: {response.json()}") - else: - print(f"Endpoint returned: {response.status_code}")