Initial commit

This commit is contained in:
2016-01-24 17:34:52 +00:00
commit 3adb1a2c60
4 changed files with 338 additions and 0 deletions

37
gishgenerator/__init__.py Normal file
View File

@@ -0,0 +1,37 @@
from random import choice
from pkgutil import get_data
animal_list = get_data('gishgenerator', 'data/animals.txt').split('\n')
animal_image_cache = {}
def generate_name():
name1 = choice(animal_list)
name2 = choice(animal_list)
combined_name = name1[:-1] + name2[1:]
print name1, "+", name2, "=", combined_name
img1 = get_image_for_text(name1)
img2 = get_image_for_text(name2)
return combined_name, img1, img2
def get_image_for_text(text):
import urllib2
import json
if text in animal_image_cache:
return animal_image_cache[text]
try:
fetcher = urllib2.build_opener()
f = fetcher.open("http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + text + "&start=0")
data = json.load(f)
animal_image = data['responseData']['results'][0]['unescapedUrl']
animal_image_cache[text] = animal_image
return animal_image
except:
return ''

13
gishgenerator/app.py Normal file
View File

@@ -0,0 +1,13 @@
from flask import Flask, render_template
from gishgenerator import generate_name
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route('/')
def index():
name, img1, img2 = generate_name()
return render_template('index.html', name=name, img1=img1, img2=img2)
if __name__ == '__main__':
app.run()

View File

@@ -0,0 +1,221 @@
Aardvark
Albatross
Alligator
Alpaca
American Bison
Ant
Anteater
Antelope
Ape
Armadillo
Donkey
Baboon
Badger
Barracuda
Bat
Bear
Beaver
Bee
Boar
Buffalo
Butterfly
Camel
Caribou
Cat
Caterpillar
Cattle
Chamois
Cheetah
Chicken
Chimpanzee
Chinchilla
Chough
Clam
Cobra
Cockroach
Cod
Cormorant
Coyote
Crab
Crane
Crocodile
Crow
Curlew
Deer
Dinosaur
Dog
Dogfish
Dolphin
Donkey
Dotterel
Dove
Dragonfly
Duck
Dugong
Dunlin
Eagle
Echidna
Eel
Eland
Elephant
Elephant seal
Elk
Emu
Falcon
Ferret
Finch
Fish
Flamingo
Fly
Fox
Frog
Gaur
Gazelle
Gerbil
Giant Panda
Giraffe
Gnat
Gnu
Goat
Goose
Goldfinch
Goldfish
Gorilla
Goshawk
Grasshopper
Grouse
Guanaco
Guinea fowl
Guinea pig
Gull
Hamster
Hare
Hawk
Hedgehog
Heron
Herring
Hippopotamus
Hornet
Horse
Human
Hummingbird
Hyena
Jackal
Jaguar
Jay
Jellyfish
Kangaroo
Koala
Komodo dragon
Kouprey
Kudu
Lapwing
Lark
Lemur
Leopard
Lion
Llama
Lobster
Locust
Loris
Louse
Lyrebird
Magpie
Mallard
Manatee
Marten
Meerkat
Mink
Mole
Monkey
Moose
Mouse
Mosquito
Mule
Narwhal
Newt
Nightingale
Octopus
Okapi
Opossum
Oryx
Ostrich
Otter
Owl
Ox
Oyster
Panther
Parrot
Partridge
Peafowl
Pelican
Penguin
Pheasant
Pig
Pigeon
Pony
Porcupine
Porpoise
Prairie Dog
Quail
Quelea
Rabbit
Raccoon
Rail
Ram
Rat
Raven
Red deer
Red panda
Reindeer
Rhinoceros
Rook
Ruff
Salamander
Salmon
Sand Dollar
Sandpiper
Sardine
Scorpion
Sea lion
Sea Urchin
Seahorse
Seal
Shark
Sheep
Shrew
Skunk
Snail
Snake
Spider
Squid
Squirrel
Starling
Stingray
Stinkbug
Stork
Swallow
Swan
Tapir
Tarsier
Termite
Tiger
Toad
Trout
Turkey
Turtle
Viper
Vulture
Wallaby
Walrus
Wasp
Weasel
Whale
Wolf
Wolverine
Wombat
Woodpecker
Worm
Wren
Yak
Zebra

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>AbnosomeDuckies Fantastic Mascot Name Generator</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">
.images img {
max-height: 250px;
}
.header,
{
padding-right: 15px;
padding-left: 15px;
}
/* Custom page header */
.header {
padding-bottom: 20px;
border-bottom: 1px solid #e5e5e5;
}
.content {
padding-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h3 class="text-muted">AbnosomeDuckies Fantastic Mascot Name Generator</h3>
</div>
<div class="content">
<div class="row images">
<div class="col-md-6 thumbnail">
<img src="{{ img1 }}"/>
</div>
<div class="col-md-6 thumbnail">
<img src="{{ img2 }}"/>
</div>
</div>
<div style="text-align: center;">
<p>Random Mascot Name:</p>
<h1>{{ name }}</h1>
</div>
</div>
</div>
</body>
</html>