From 5721cb88ef4ec2d2a0efaf655739936f999a3f85 Mon Sep 17 00:00:00 2001 From: Adrian Huang Date: Fri, 2 Dec 2016 20:31:43 -0800 Subject: [PATCH 1/2] asdasdasd --- server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server.py b/server.py index 646e5e5..56cedf1 100644 --- a/server.py +++ b/server.py @@ -6,6 +6,10 @@ app = Flask(__name__) app.config['DEBUG'] = True +@app.route('/potato') +def potato(): + return "HI" + @app.route('/leaderboard') def leaderboard(name=None): name = request.args["name"] From 90e6ab587d0d747c9ff96404325ab9d383b367e7 Mon Sep 17 00:00:00 2001 From: Adrian Huang Date: Fri, 23 Dec 2016 22:08:31 -0800 Subject: [PATCH 2/2] Minor bugfix and some QOL changes --- directory.py | 244 ++++++++++++++++++------------- server.py | 19 ++- templates/games/trivia_game.html | 3 +- 3 files changed, 151 insertions(+), 115 deletions(-) diff --git a/directory.py b/directory.py index f88c9e0..4746a3e 100644 --- a/directory.py +++ b/directory.py @@ -20,113 +20,149 @@ } TRIVIA_QUESTIONS_LIST = { - 1 : "What is 4+5", - 2 : "What is 1+9", - 3 : "What is 1*5", - 4 : "Andrew, or Andrew?", - 5 : "What is a state located in the southeastern region of the United States?", - 6 : "What is a U.S. state situated in the northwest extremity of the Americas?", - 7 : "What is a state in the southwestern region of the United States?", - 8 : "What is a state located in the southeastern region of the United States?", - 9 : "What is the most populous state in the United States as well as the third most extensive by area?", - 10 : "What is a state in the United States encompassing most of the Southern Rocky Mountains as well as the northeastern portion of the Colorado Plateau and the western edge of the Great Plains?", - 11 : "What is the southernmost state in the New England region of the United States?", - 12 : "What is one of the Mid-Atlantic states located in the Northeast megalopolis region of the United States?", - 13 : "What is a state located in the southeastern region of the United States?", - 15 : "What is the 50th and most recent state of the United States of America, receiving statehood on August 21, 1959?", - 16 : "What is a state in the northwestern region of the United States?", - 17 : "What is a state in the midwestern region of the United States?", - 18 : "What is a U.S. state located in the midwestern and Great Lakes regions of North America?", - 19 : "What is a U.S. state in the Midwestern United States, bordered by the Mississippi River on the east and the Missouri River and the Big Sioux River on the west?", - 20 : "What is a U.S. state located in the Midwestern United States?", - 21 : "What is a state located in the east south-central region of the United States?", - 22 : "What is a state located in the southern region of the United States?", - 23 : "What is a state in New England, in the United States?", - 24 : "What is a state located in the Mid-Atlantic region of the United States, bordering Virginia, West Virginia, and Washington, D.C. to its south and west; Pennsylvania to its north; and Delaware to its east?", - 25 : "What is the most populous state in the New England part of the northeastern region of the United States?", - 26 : "What is a state located in the Great Lakes and midwestern regions of the United States?", - 27 : "What is a state in the Midwestern United States?", - 28 : "What is a state located in the southern region of the United States?", - 29 : "What is a state located in the Midwestern United States?", - 30 : "What is a state in the Western region of the United States?", - 31 : "What is a state that lies in both the Great Plains and the Midwestern United States?", - 32 : "What is a state in the Western, Mountain West, and Southwestern regions of the United States of America?", - 33 : "What is a state in the New England region of the northeastern United States?", - 34 : "What is a state in the northeastern and mid-Atlantic regions of the United States?", - 35 : "What is a state located in the southwestern region of the United States of America?", - 36 : "What is a state in the Northeastern United States and is the 27th-most extensive, fourth-most populous, and seventh-most densely populated U.S. state?", - 37 : "What is a state in the southeastern region of the United States?", - 38 : "What is the 39th state of the United States, having been admitted to the union on November 2, 1889?", - 39 : "What is an Eastern state in the Great Lakes region of the United States?", - 40 : "What is a state located in the South Central United States?", - 41 : "What is a state in the Pacific Northwest region of the United States?", - 42 : "What is a state located in the northern and Mid-Atlantic regions of the United States?", - 43 : "What is a state in the New England region of the United States?", - 44 : "What is a state in the southeastern region of the United States?", - 45 : "What is a state located in the Midwestern region of the United States?", - 46 : "What is a state located in the southeastern region of the United States?", - 47 : "What is the second largest state in the United States by both area and population?", - 48 : "What is a state in the western United States?", - 49 : "What is a New England state in the northeastern region of the United States?", - 50 : "What is a state located in the South Atlantic region of the United States?", - 52 : "What is a state located in the Appalachian region of the Southern United States?", - 53 : "What is a U.S. state located in the north-central United States, in the Midwest and Great Lakes regions?", - 54 : "What is a state in the mountain region of the Western United States?", + 1 : "Which southeastern state in the United States has one of the nation's largest navigable waterways?", + 2 : "What is a U.S. state situated in the northwest extremity of the Americas?", + 3 : "Which southwestern state in the United States had part of its territory bought in 1853 as part of the Gadsden Purchase?", + 4 : "Which southeastern state in the United States contains parts of the Ozark and Ouachita Mountains?", + 5 : "Which state was admitted into the union in 1850 and is the birthplace of the film industry?", + 6 : "Whisk Four Corners state contains the peak of Mount Elbert?", + 7 : "Which northeastern state contains the Thames River as has Yankee Doodle as their state song?", + 8 : "A famous photograph of George Washington crossing a river on Christmas Day takes place in which state?", + 9 : "The Seminole Wars occurred in which state that borders the Gulf of Mexico?", + 10 : "Which southeastern state is also known as The Peach State?", + 11 : "Which state is primarily formed from volcanic activity?", + 12 : "Which northwestern state contains parts of the Great Basin, Snake River Plain, and Rocky Mountains?", + 13 : "Which midwestern US state contains the Erie Canal?", + 14 : "Which midwestern US state is also known as 'Land of the Indians'?", + 15 : "Which midwestern US state is bordered by the Mississippi River on the east and the Missouri River and the Big Sioux River on the west?", + 16 : "Which US state is Dorothy in 'The Wizard of Oz' from?", + 17 : "Which south-central US state is known for their nationally successful fast food chain?", + 18 : "Which US state is named in a land purchase between America and the French in 1803?", + 19 : "Which northeastern US state was admitted into the Union as part of the Missouri Compromise?", + 20 : "Which midatlantic US state borders Virginia and is known as the birthplace of religious freedom?", + 21 : "Which northeastern US state is well known for their higher education, engineering, and maritime trade?", + 22 : "Which US state is bounded by four Great Lakes?", + 23 : "Which midwestern US state contains the Metrodome?", + 24 : "Which southern US state carries the reputation of being the most religious state in the country?", + 25 : "Which midwest US state once held the starting points of the Pony Express, Santa Fe Trail, and Oregon Trail?", + 26 : "Which western US state has a landsize in the top 5 of all US states, but a population density in the bottom 5 of all US states?", + 27 : "Which midwestern US state is divided into the Dissected Till Plains and the Great Plains?", + 28 : "In which midwestern US state is prostitution legal?", + 29 : "Which northeastern US state contains the cities Manchester and Concord?", + 30 : "Which northeastern US state is known as the car theft capital of the world?", + 31 : "Which Four Corners state was named by Spanish explorers seeking the wealth of Mexico?", + 32 : "Which northeastern US state as 722 miles of subway track?", + 33 : "Which western US state contains Harker's Island?", + 34 : "Which northern US state grows omre sunflowers than any other state?", + 35 : "Which eastern state is also known as the Buckeye State?", + 36 : "Which south-central US state contains the Ouachitas, Arbuckles, Wichitas, and Kiamichis mountain ranges?", + 37 : "Which Pacific northwest state contains Crater Lake?", + 38 : "In which US state was the Hershey company founded in?", + 39 : "What is the smallest state in the United States?", + 40 : "In which US state did the first battle of the Civil War take place?", + 41 : "Which midwestern US state contains Mount Rushmore?", + 42 : "In which southeastern US state did bluegrass music and Jack Daniels originate from?", + 43 : "Which southern state is also known as the Lone Star State?", + 44 : "Which Four Corners state contains the Great Salt Lake?", + 45 : "Which northeastern US state has been previously claimed by both New Hampshire and New York?", + 46 : "Which US state holds the largest military base in the country?", + 47 : "Which northwest US state is home to the first revolving restaurant in the country?", + 48 : "Which state located in the Appalachian region was admitted into the United States during the American Civil War?", + 49 : "Which midwest US state is known as the dairy capital of the United States?", + 50 : "Which US state was the first state to give women the right to vote?", + 51 : "What color were the Witch of the East's slippers in the original Wizard of Oz?", + 52 : "In Star Wars, what is the Emporers last name?", + 53 : "What is the name of the Queen witch in Sleeping Beauty?", + 54 : "Which Disney film has a main character that doesn't speak?", + 55 : "What was the first Disney film to be nominated for an Oscar?", + 56 : "In Aladdin, what animal does Jafar turn into?", + 57 : "Which Disney princess has healing powers?", + 58 : "Which Disney princess is also known as 'The Fairest One of All?'", + 59 : "What is the name of the teacup in 'Beauty and the Beast'?", + 60 : "What is the name of the antagonist in 'The Emperor's New Groove'?", + 61 : "In 'The Little Mermaid,' what is the name of Ariel's father?", + 62 : "In 'The Emperor's New Groove,' what animal does Kuzco turn into?", + 63 : "In 'Cars,' what is Lightning McQueen's racing numbers?", + 64 : "What is the name of the antagonist in 'Toy Story 2'?", + 65 : "How any animal main characters are there in 'Winnie the Pooh'?", + 66 : "What is the name of the tree that attacks Harry and Ron in 'Harry Potter and the Chamber of Secrets'?", + 67 : "Who is the first to tell Harry Potter that he is a wizard?", + 68 : "In the Harry Potter universe, what is the name of the plant that screams when harvested?", + 69 : "Where did Harry Potter live before his parents died?", + 70 : "What is the shape of Harry Potter's patronus?" } TRIVIA_ANSWERS_LIST = { - 1 : "9", - 2 : "10", - 3 : "5", - 4: "yoonko", - 5 : "Alabama", - 6 : "Alaska", - 7 : "Arizona", - 8 : "Arkansas", - 9 : "California", - 10 : "Colorado", - 11 : "Connecticut", - 12 : "Delaware", - 13 : "Florida", - 15 : "Hawaii", - 16 : "Idaho", - 17 : "Illinois", - 18 : "Indiana", - 19 : "Iowa", - 20 : "Kansas", - 21 : "Kentucky", - 22 : "Louisiana", - 23 : "Maine", - 24 : "Maryland", - 25 : "Massachusetts", - 26 : "Michigan", - 27 : "Minnesota", - 28 : "Mississippi", - 29 : "Missouri", - 30 : "Montana", - 31 : "Nebraska", - 32 : "Nevada", - 33 : "New Hampshire", - 34 : "New Jersey", - 35 : "New Mexico", - 36 : "New York", - 37 : "North Carolina", - 38 : "North Dakota", - 39 : "Ohio", - 40 : "Oklahoma", - 41 : "Oregon", - 42 : "Pennsylvania", - 43 : "Rhode Island", - 44 : "South Carolina", - 45 : "South Dakota", - 46 : "Tennessee", - 47 : "Texas", - 48 : "Utah", - 49 : "Vermont", - 50 : "Virginia", - 52 : "West Virginia", - 53 : "Wisconsin", - 54 : "Wyoming", + 1 : "Alabama", + 2 : "Alaska", + 3 : "Arizona", + 4 : "Arkansas", + 5 : "California", + 6 : "Colorado", + 7 : "Connecticut", + 8 : "Delaware", + 9 : "Florida", + 10: "Georgia", + 11 : "Hawaii", + 12 : "Idaho", + 13 : "Illinois", + 14 : "Indiana", + 15 : "Iowa", + 16 : "Kansas", + 17 : "Kentucky", + 18 : "Louisiana", + 19 : "Maine", + 20 : "Maryland", + 21 : "Massachusetts", + 22 : "Michigan", + 23 : "Minnesota", + 24 : "Mississippi", + 25 : "Missouri", + 26 : "Montana", + 27 : "Nebraska", + 28 : "Nevada", + 29 : "New Hampshire", + 30 : "New Jersey", + 31 : "New Mexico", + 32 : "New York", + 33 : "North Carolina", + 34 : "North Dakota", + 35 : "Ohio", + 36 : "Oklahoma", + 37 : "Oregon", + 38 : "Pennsylvania", + 39 : "Rhode Island", + 40 : "South Carolina", + 41 : "South Dakota", + 42 : "Tennessee", + 43 : "Texas", + 44 : "Utah", + 45 : "Vermont", + 46 : "Virginia", + 47 : "Washington", + 48 : "West Virginia", + 49 : "Wisconsin", + 50 : "Wyoming", + 51 : "Silver", + 52 : "Palpatine", + 53 : "Maleficient", + 54 : "Dumbo", + 55 : "Beauty and the Beast", + 56 : "Cobra", + 57 : "Rapunzel", + 58 : "Snow White", + 59 : "Chip", + 60 : "Yzma", + 61 : "King Triton", + 62 : "Llama", + 63 : "95", + 64 : "Andy", + 65 : "8", + 66 : "The Whomping Willow", + 67 : "Hagrid", + 68 : "Mandrake", + 69 : "Godric's Hallow", + 70 : "Stag" } CODE_GOLF_QUESTIONS_LIST = { diff --git a/server.py b/server.py index 56cedf1..3137830 100644 --- a/server.py +++ b/server.py @@ -6,10 +6,6 @@ app = Flask(__name__) app.config['DEBUG'] = True -@app.route('/potato') -def potato(): - return "HI" - @app.route('/leaderboard') def leaderboard(name=None): name = request.args["name"] @@ -60,20 +56,23 @@ def password_generation(): @app.route('/api/trivia_game', methods=['GET', 'POST']) def trivia(): + # GET pulls the next question in line in TRIVIA_QUESTIONS_LIST if request.method == 'GET': key = int(request.args.get('question')) if key in directory.TRIVIA_QUESTIONS_LIST: - return "%d. %s" % (key, directory.TRIVIA_QUESTIONS_LIST[key]) + return directory.TRIVIA_QUESTIONS_LIST[key] else: return "No questions left! Check back later for more!" + # POST normalizes the user and database answers and compares them elif request.method == 'POST': - answer = normalize(request.form["answer"]) + answer = request.form["answer"] questionNum = int(request.form["question"]) - - if (directory.TRIVIA_ANSWERS_LIST[questionNum] == answer): + if (normalize(directory.TRIVIA_ANSWERS_LIST[questionNum]) == \ + normalize(answer)): return json.dumps({"result": "Correct!"}) - return json.dumps({"result": "Wrong!"}) - return "pls" + return json.dumps({"result": "Wrong! Correct Answer: %s" \ + %(directory.TRIVIA_ANSWERS_LIST[questionNum])}) + return "Wrong request method given." def normalize(string): return re.sub(r'\W+', '', string.lower()) diff --git a/templates/games/trivia_game.html b/templates/games/trivia_game.html index 8f5f707..719591d 100644 --- a/templates/games/trivia_game.html +++ b/templates/games/trivia_game.html @@ -13,7 +13,7 @@

Trivia

How to Play

Answer the questions.
- Caution: you only get one shot per question!

+ Caution: You only get one shot per question!

Scoring

@@ -68,6 +68,7 @@

How to Exit

} }); } + function next() { var guess = document.getElementById('solution').value; if (guess == "") {