Skip to content

Instantly share code, notes, and snippets.

Last active Dec 7, 2020
What would you like to do?
a random gif web-service
import platform
import giphy_client
from import ApiException
from http.server import HTTPServer, BaseHTTPRequestHandler
api_key = "REPLACE_WITH_YOUR_GIPHY_API_KEY" # str | Giphy API Key.
# create an instance of the API class
api_instance = giphy_client.DefaultApi()
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
content = """<head>
div {text-align: center;}
content += "\nServer: " + platform.node() + "\n"
rating = "g"
fmt = "json"
tag = "bunny"
api_response = api_instance.gifs_random_get(
api_key, tag=tag, rating=rating, fmt=fmt
gif_id =
content += "<h1>Welcome to the Mysocket Gif generator</h1>"
content += f"<img src='{gif_id.image_original_url}'>"
content += "<br><p>For more details see: <a href=''>Easy Multi-region load balancing with as a global Load Balancer</a></p>"
except ApiException as e:
content += "Exception when calling Giphy API :( "
content_center = f"<div> {content} </div>"
self.send_header("Content-type", "text/html")
httpd = HTTPServer(("", 8000), SimpleHTTPRequestHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment