Skip to content

Instantly share code, notes, and snippets.

@miloheller
Created February 26, 2015 19:53
Show Gist options
  • Save miloheller/83634a6af36c5ccb8816 to your computer and use it in GitHub Desktop.
Save miloheller/83634a6af36c5ccb8816 to your computer and use it in GitHub Desktop.
This is for the program Pythonista. It is a magic eight ball that I made myself.
import time
import random
import console
def get_answers(filename) :
'''read and parse the answer file'''
ret = []
filehandle = open(filename,'r')
for line in filehandle.readlines() :
if line.strip().startswith('#') :
continue
if '--' in line :
line, otherstuff = line.split('--',1)
line = line.strip()
if line != '' :
ret.append(line)
filehandle.close()
return ret
answers = get_answers('Eight_Ball_Answers.text')
import ui
def button_tapped(sender):
sender.title = random.choice(answers)
view = ui.View()
view.name = 'Magic Eight Ball'
view.background_color = 'black'
button = ui.Button(title='To Begin Magic Eight Ball, Tap Me!')
button.center = (view.width * 0.5, view.height * 0.5)
button.flex = 'LRTB'
button.action = button_tapped
view.add_subview(button)
view.present('sheet')
#you also need this in another file, that is named Eight_Ball_Answers.text
# positives
It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yes
Signs point to yes
#ask agains
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again later
# negitives
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment