-
Notifications
You must be signed in to change notification settings - Fork 0
/
2demo.py
executable file
·40 lines (32 loc) · 1.09 KB
/
2demo.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
#!/usr/bin/env python2.7
#
# Demonstration of Interro
#
# Copyright (c) 2012 Dominic van Berkel. See LICENSE for details.
#
import interro as inter
def output(value):
"""Callback for Interro's msg_callback
Necessary as py2 doesn't know print as a function."""
print value
c = inter.Interro(msg_callback=output)
c.add(inter.YesNoQ('TOS',
question='Do you agree to the TOS?',
onanswer={True: 'email'},
default_next='noTOS'))
c.add(inter.TextQ('email',
question='What is your email address?',
message='We will not share this with bad people',
validation=[(lambda x: '@' in x, 'Invalid address.')],
confirm=True,
default_next='age'))
c.add(inter.NumberQ('age',
question='How old are you?',
req_positive=True))
c.add(inter.MessageQ('noTOS',
message='Well, that\'s unfortunate. Bye!'))
c.start('TOS')
while not c.complete:
response = raw_input('> ')
c.answer(response)
print(c.results())