-
Notifications
You must be signed in to change notification settings - Fork 0
/
beerquiz.py
executable file
·43 lines (36 loc) · 1.59 KB
/
beerquiz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urllib2
from random import randint
import sys
sys.path.insert(0, './lib/pynt')
from pynt.pynt import Settings, Beer
Settings.host = 'http://api.openbeerdatabase.com/v1/'
Settings.public_token = 'db198084eb53128e0fb7246d00aa424ab2fc28d713b43d0df5908652f4a8af4c'
Settings.private_token = '01ae167826935d3cbc0421cd0caa787d4c4a8cf60f5becc796af7566dbaa3711'
def main():
beers = Beer.all()["beers"]
beer = beers[randint(0,len(beers)-1)]
while 1:
print "Which beer is this? \"{}\"".format(beer["description"].encode('utf-8'))
if raw_input('Your guess: ') == beer["name"]:
print "Correct answer, well done!"
return
else:
print "Wrong answer, correct answer is {}\n".format(beer["name"].encode('utf-8'))
beer = beers[randint(0,len(beers)-1)]
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print "\nQuitting...\n"