Commit dfef6089 authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

adding buggy splash2 script

parent f8117c7a
#!/usr/bin/env python3
from pymongo import MongoClient
def db_connect():
# try to create instance of MongoClient object
client = MongoClient('mongodb://localhost:8000/')
print("Error: failed to create mongo client")
# switch to the specified database
db = client.test
# return a handle to the database
# connect to database
db = db_connect()
# get one random document from images collection
result = db.images.find()
# if a result came back
if result:
# iterate through objects in the cursor (should only be 1)
for img in result:
# pull out the img url and alt text
img_src = img['src']
img_alt = img['alt']
print("Content-Type: text/html\n")
print("""<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Hello Caflucks</title>
<h1>Welcome to Catflucks</h1>
<p>You are viewing a random image of a cat.</p>
<img src="{}" alt="{}" width=500>
</html>""".format( img_alt, img_src ))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment