Skip to content

Commit

Permalink
Use i.spoo.me as the image backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingzy committed Oct 4, 2024
1 parent 07dd3d8 commit 320def1
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 14 deletions.
67 changes: 67 additions & 0 deletions gifs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"1.gif": "https://i.spoo.me/245125",
"10.gif": "https://i.spoo.me/884006",
"11.gif": "https://i.spoo.me/259350",
"12.gif": "https://i.spoo.me/312893",
"13.gif": "https://i.spoo.me/392463",
"14.gif": "https://i.spoo.me/985992",
"15.gif": "https://i.spoo.me/984184",
"16.gif": "https://i.spoo.me/457493",
"17.gif": "https://i.spoo.me/868013",
"18.gif": "https://i.spoo.me/363708",
"19.gif": "https://i.spoo.me/813777",
"2.gif": "https://i.spoo.me/844214",
"20.gif": "https://i.spoo.me/108260",
"21.gif": "https://i.spoo.me/398042",
"22.gif": "https://i.spoo.me/688545",
"23.gif": "https://i.spoo.me/106795",
"24.gif": "https://i.spoo.me/265169",
"25.gif": "https://i.spoo.me/947033",
"26.gif": "https://i.spoo.me/762730",
"27.gif": "https://i.spoo.me/408674",
"28.gif": "https://i.spoo.me/509743",
"29.gif": "https://i.spoo.me/174132",
"3.gif": "https://i.spoo.me/824365",
"30.gif": "https://i.spoo.me/491034",
"31.gif": "https://i.spoo.me/681301",
"32.gif": "https://i.spoo.me/634182",
"33.gif": "https://i.spoo.me/163444",
"34.gif": "https://i.spoo.me/294540",
"35.gif": "https://i.spoo.me/623698",
"36.gif": "https://i.spoo.me/535485",
"37.gif": "https://i.spoo.me/100853",
"38.gif": "https://i.spoo.me/855418",
"39.gif": "https://i.spoo.me/504785",
"4.gif": "https://i.spoo.me/489802",
"40.gif": "https://i.spoo.me/929747",
"41.gif": "https://i.spoo.me/434237",
"42.gif": "https://i.spoo.me/626233",
"43.gif": "https://i.spoo.me/852508",
"44.gif": "https://i.spoo.me/839369",
"45.gif": "https://i.spoo.me/388087",
"46.gif": "https://i.spoo.me/163853",
"47.gif": "https://i.spoo.me/131075",
"48.gif": "https://i.spoo.me/480716",
"49.gif": "https://i.spoo.me/687803",
"5.gif": "https://i.spoo.me/558918",
"50.gif": "https://i.spoo.me/173309",
"51.gif": "https://i.spoo.me/207173",
"52.gif": "https://i.spoo.me/338334",
"53.gif": "https://i.spoo.me/592812",
"54.gif": "https://i.spoo.me/670148",
"55.gif": "https://i.spoo.me/551803",
"56.gif": "https://i.spoo.me/201552",
"57.gif": "https://i.spoo.me/785985",
"58.gif": "https://i.spoo.me/102133",
"59.gif": "https://i.spoo.me/166013",
"6.gif": "https://i.spoo.me/825204",
"60.gif": "https://i.spoo.me/240933",
"61.gif": "https://i.spoo.me/290508",
"62.gif": "https://i.spoo.me/629563",
"63.gif": "https://i.spoo.me/172412",
"64.gif": "https://i.spoo.me/345035",
"65.gif": "https://i.spoo.me/820786",
"7.gif": "https://i.spoo.me/495204",
"8.gif": "https://i.spoo.me/230792",
"9.gif": "https://i.spoo.me/941059"
}
99 changes: 99 additions & 0 deletions images.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"1.jpg": "https://i.spoo.me/283755",
"10.jpg": "https://i.spoo.me/154162",
"11.jpg": "https://i.spoo.me/999078",
"12.jpg": "https://i.spoo.me/328073",
"13.jpg": "https://i.spoo.me/633946",
"14.jpg": "https://i.spoo.me/849037",
"15.jpg": "https://i.spoo.me/606551",
"16.jpg": "https://i.spoo.me/554919",
"17.jpg": "https://i.spoo.me/203789",
"18.jpg": "https://i.spoo.me/662866",
"19.jpg": "https://i.spoo.me/963063",
"2.jpg": "https://i.spoo.me/625753",
"20.jpg": "https://i.spoo.me/438004",
"21.jpg": "https://i.spoo.me/755003",
"22.jpg": "https://i.spoo.me/223329",
"23.jpg": "https://i.spoo.me/341672",
"24.jpg": "https://i.spoo.me/704085",
"25.jpg": "https://i.spoo.me/649152",
"26.jpg": "https://i.spoo.me/150434",
"27.jpg": "https://i.spoo.me/544537",
"28.jpg": "https://i.spoo.me/938051",
"29.jpg": "https://i.spoo.me/209463",
"3.jpg": "https://i.spoo.me/915532",
"30.jpg": "https://i.spoo.me/806544",
"31.jpg": "https://i.spoo.me/520093",
"32.jpg": "https://i.spoo.me/829234",
"33.jpg": "https://i.spoo.me/935350",
"34.jpg": "https://i.spoo.me/319321",
"35.jpg": "https://i.spoo.me/446516",
"36.jpg": "https://i.spoo.me/580236",
"37.jpg": "https://i.spoo.me/370593",
"38.jpg": "https://i.spoo.me/223637",
"39.jpg": "https://i.spoo.me/390215",
"4.jpg": "https://i.spoo.me/977747",
"40.jpg": "https://i.spoo.me/512459",
"41.jpg": "https://i.spoo.me/519957",
"42.jpg": "https://i.spoo.me/768281",
"43.jpg": "https://i.spoo.me/513138",
"44.jpg": "https://i.spoo.me/535255",
"45.jpg": "https://i.spoo.me/913209",
"46.jpg": "https://i.spoo.me/929755",
"47.jpg": "https://i.spoo.me/129101",
"48.jpg": "https://i.spoo.me/386159",
"49.jpg": "https://i.spoo.me/874179",
"5.jpg": "https://i.spoo.me/158213",
"50.jpg": "https://i.spoo.me/449196",
"51.jpg": "https://i.spoo.me/200629",
"52.jpg": "https://i.spoo.me/263353",
"53.jpg": "https://i.spoo.me/750683",
"54.jpg": "https://i.spoo.me/815235",
"55.jpg": "https://i.spoo.me/260018",
"56.jpg": "https://i.spoo.me/268898",
"57.jpg": "https://i.spoo.me/748847",
"58.jpg": "https://i.spoo.me/149544",
"59.jpg": "https://i.spoo.me/570502",
"6.jpg": "https://i.spoo.me/949387",
"60.jpg": "https://i.spoo.me/825320",
"61.jpg": "https://i.spoo.me/941268",
"62.jpg": "https://i.spoo.me/540861",
"63.jpg": "https://i.spoo.me/930408",
"64.jpg": "https://i.spoo.me/178414",
"65.jpg": "https://i.spoo.me/473485",
"66.jpg": "https://i.spoo.me/245959",
"67.jpg": "https://i.spoo.me/782754",
"68.jpg": "https://i.spoo.me/390502",
"69.jpg": "https://i.spoo.me/110369",
"7.jpg": "https://i.spoo.me/571793",
"70.jpg": "https://i.spoo.me/532339",
"71.jpg": "https://i.spoo.me/669831",
"72.jpg": "https://i.spoo.me/665263",
"73.jpg": "https://i.spoo.me/132587",
"74.jpg": "https://i.spoo.me/769519",
"75.jpg": "https://i.spoo.me/965712",
"76.jpg": "https://i.spoo.me/962091",
"77.jpg": "https://i.spoo.me/577422",
"78.jpg": "https://i.spoo.me/416535",
"79.jpg": "https://i.spoo.me/528151",
"8.jpg": "https://i.spoo.me/376882",
"80.jpg": "https://i.spoo.me/363977",
"81.jpg": "https://i.spoo.me/444602",
"82.jpg": "https://i.spoo.me/363841",
"83.jpg": "https://i.spoo.me/362464",
"84.jpg": "https://i.spoo.me/624062",
"85.jpg": "https://i.spoo.me/834761",
"86.jpg": "https://i.spoo.me/965805",
"87.jpg": "https://i.spoo.me/595280",
"88.jpg": "https://i.spoo.me/182542",
"89.jpg": "https://i.spoo.me/605716",
"9.jpg": "https://i.spoo.me/416024",
"90.jpg": "https://i.spoo.me/658056",
"91.jpg": "https://i.spoo.me/107349",
"92.jpg": "https://i.spoo.me/935283",
"93.jpg": "https://i.spoo.me/233627",
"94.jpg": "https://i.spoo.me/176772",
"95.jpg": "https://i.spoo.me/474324",
"96.jpg": "https://i.spoo.me/921237",
"97.jpg": "https://i.spoo.me/705442"
}
25 changes: 11 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import random
from io import BytesIO
import os
import json
import uvicorn


Expand All @@ -35,8 +36,12 @@
panda_facts = [i.strip() for i in panda_facts]

panda_pics = os.listdir("images")
with open("images.json", "r") as f:
pics_json = json.loads(f.read())

panda_gifs = os.listdir("gifs")
with open("gifs.json", "r") as f:
gifs_json = json.loads(f.read())


def create_cache():
Expand Down Expand Up @@ -74,18 +79,14 @@ def get_random_gif(request: Request):

@app.get("/raw_pic", tags=["pics"])
async def get_random_pic_raw():
random_pic_path = f"images/{random.choice(panda_pics)}"
with open(random_pic_path, "rb") as file:
contents = file.read()
return StreamingResponse(BytesIO(contents), media_type="image/jpeg")
random_pic = random.choice(panda_pics)
return RedirectResponse(url=pics_json[random_pic])


@app.get("/raw_gif", tags=["gifs"])
async def get_random_gif_raw():
random_gif_path = f"gifs/{random.choice(panda_gifs)}"
with open(random_gif_path, "rb") as file:
contents = file.read()
return StreamingResponse(BytesIO(contents), media_type="image/gif")
random_gif = random.choice(panda_gifs)
return RedirectResponse(url=gifs_json[random_gif])


@app.get("/all", tags=["facts", "pics", "gifs"])
Expand Down Expand Up @@ -126,9 +127,7 @@ async def get_image(file_name: str, cache: TTLCache = Depends(create_cache)):
if cached_response:
return cached_response

response = FileResponse(file_path, media_type="image/jpeg")
cache[file_name] = response
return response
return RedirectResponse(url=pics_json[file_name])


@app.get("/g/{file_name}", tags=["gifs"])
Expand All @@ -141,9 +140,7 @@ async def get_gif(file_name: str, cache: TTLCache = Depends(create_cache)):
if cached_response:
return cached_response

response = FileResponse(file_path, media_type="image/gif")
cache[file_name] = response
return response
return RedirectResponse(url=gifs_json[file_name])


@app.get("/health", tags=["health"])
Expand Down

0 comments on commit 320def1

Please sign in to comment.