Skip to content

Instantly share code, notes, and snippets.

@Frankenmint
Created November 11, 2025 09:22
Show Gist options
  • Save Frankenmint/f6af490f36fce61c57f742810fe411e3 to your computer and use it in GitHub Desktop.
Save Frankenmint/f6af490f36fce61c57f742810fe411e3 to your computer and use it in GitHub Desktop.
giphy.py
import os
import requests
API_KEY = ""
BASE_URL = "https://api.giphy.com/v1/gifs/search"
def fetch_gifs(keyword, limit=20):
params = {
"api_key": API_KEY,
"q": keyword,
"limit": limit,
"rating": "pg-13"
}
response = requests.get(BASE_URL, params=params)
data = response.json()
# Create a folder to save GIFs if it doesn't exist
if not os.path.exists("gifs"):
os.makedirs("gifs")
for i, gif in enumerate(data.get("data", [])):
gif_url = gif["images"]["original"]["url"]
gif_data = requests.get(gif_url).content
with open(f"gifs/{keyword}_{i}.gif", "wb") as f:
f.write(gif_data)
print(f"Saved GIF {i + 1} for keyword '{keyword}'")
if __name__ == "__main__":
print("Enter a keyword to fetch GIFs (type 'exit' to quit):")
while True:
keyword = input("> ").strip()
if keyword.lower() == 'exit':
break
if keyword:
fetch_gifs(keyword)
else:
print("Please enter a valid keyword.")
print("Goodbye!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment