commit 3adb1a2c602591017907578a1e1344a052727d5d Author: Andrew Williams Date: Sun Jan 24 17:34:52 2016 +0000 Initial commit diff --git a/gishgenerator/__init__.py b/gishgenerator/__init__.py new file mode 100644 index 0000000..fb5ac9b --- /dev/null +++ b/gishgenerator/__init__.py @@ -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 '' \ No newline at end of file diff --git a/gishgenerator/app.py b/gishgenerator/app.py new file mode 100644 index 0000000..54f3905 --- /dev/null +++ b/gishgenerator/app.py @@ -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() diff --git a/gishgenerator/data/animals.txt b/gishgenerator/data/animals.txt new file mode 100644 index 0000000..187c92e --- /dev/null +++ b/gishgenerator/data/animals.txt @@ -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 \ No newline at end of file diff --git a/gishgenerator/templates/index.html b/gishgenerator/templates/index.html new file mode 100644 index 0000000..29102e2 --- /dev/null +++ b/gishgenerator/templates/index.html @@ -0,0 +1,67 @@ + + + + + + + + AbnosomeDuckies Fantastic Mascot Name Generator + + + + + + + + + + + + +
+ +
+

AbnosomeDuckies Fantastic Mascot Name Generator

+
+ +
+
+
+ +
+
+ +
+
+ +
+

Random Mascot Name:

+

{{ name }}

+
+
+
+ + + \ No newline at end of file