示例#1
0
文件: main.py 项目: permag/pyTalk
def say_weather(weather):
    if weather:
        if (weather[0] == 'light rain showers' or weather[0] == 'rain showers' or
            weather[0] == 'heavy rain showers' or weather[0] == 'showers'):
            say.say('Och så lite väder. Just nu är det {0}, så det kanske är bäst att ni gå till Tegel idag då.'.format(weather[1]))
        else:
            say.say('Och så lite väder. Just nu är det {0}, så ni kan väl gå vart ni vill.'.format(weather[1]))
示例#2
0
文件: main.py 项目: permag/pyTalk
def main(mode):
    data = get_restaurants()
    weather = forecast.get(data['forecast_url'].encode('utf-8'))

    # mode
    if mode == 'suggestions':
        say.say('Här kommer några förslag:')
        for item in data['restaurants']:
            read_restaurant_menu(item, mode, data['prefered'])
        return
    elif mode == 'weather':
        say_weather(weather)
        return

    # intro
    say_intro()

    # get restaurants
    for item in data['restaurants']:
        read_restaurant_menu(item, mode, None)

    # say weather
    say_weather(weather)

    # Tuesday message
    if scraper.get_today_as_string() == 'Tisdag':
        say.say(OUTRO_SPECIAL)
def askwolfram():
	import SpeechRecognitionAsk as sra
	import wolfquery,say
	question = sra.ask()
	print(question)
	response = wolfquery.wolfquery(question)
	say.say(response)
	return response
示例#4
0
def main(args, debug=False):
    fn = args[1] if len(args) > 1 else 'cis.pml'

    with open(fn, 'rb') as f:
        soup = BeautifulSoup(f)

    buf_main = SIO.StringIO()
    say.setfiles([buf_main])

    say( u'def {_main_atom}():' )
    say( u'    plist = list()' )

    adjuster = None
    for index, pml_tag in enumerate( soup.find_all('pml') ):
        bufc = SIO.StringIO()
        #         return "
        # <h3>Now, Good Bye...!</h3>
        # "
        for cld in pml_tag.children:
            if isinstance(cld, Tag):     # BS4 parses HTML tags in <pml/>!
                bufc.write( repr(cld) )
            else:
                if index == 0:            # we get "leading indent" from PML-0
                    if adjuster == None:
                        adjuster = LeadingIndent(cld)
                else:
                    cld = adjuster( cld )

                bufc.write( cld )

        say( bufc.getvalue() )
        bufc.close()
        say(u'    plist.append(pml)')   # append that <pml/> Py code ...

        # replace <pml/> ==>> <div><!-- pml-N --></div> - for Re.sub
        div = soup.new_tag("div")
        div.string = Comment( "pml-{}".format(index) )
        pml_tag.replace_with( div )

    say(u'    return plist')

    the_code = buf_main.getvalue()
    with open("out.py", 'wb') as fp:
        fp.write(the_code)
    buf_main.close()

    if debug == True:
        print( the_code )
    exec( the_code )                     # "execute" (to scope-in) the Py prog

    results = pml_code_func()            # run the Py-program from <pml> blocks
    if debug == True:
        pprint( [ item for item in results] )

    shtml = soup.prettify(formatter="minimal")
    shtml = _comment_re.sub( SubHandler(results), shtml )
    print( shtml )
示例#5
0
文件: main.py 项目: permag/pyTalk
def say_suggestions(name, text_list, prefered):
    do_break = False
    for pref in prefered:
        for s in pref:
            s = s.encode('utf-8')
            for text in text_list:
                text = text.lower()
                if text.find(s) != -1:
                    do_break = True
                    say.say('På {0} är det {1}.'.format(name, text));
            if do_break:
                do_break = False
                break
示例#6
0
文件: main.py 项目: permag/pyTalk
def read_restaurant_menu(restaurant_item, mode, prefered):
    text_list = scraper.get_text_list(restaurant_item['url'])
    if not text_list:
        return
    if mode == 'suggestions':
        say_suggestions(restaurant_item['name_pronunciation'], text_list, prefered)
    print('\n********* Restaurant: {0} *********'.format(restaurant_item['name']))
    i = 0
    for text in text_list:
        i += 1
        print(text)
        if mode == 'menu':
            if i is 1:
                say.say('{0}. {1}'.format(restaurant_item['name_pronunciation'], text))
            else:
                say.say('. {0}'.format(text))
示例#7
0
文件: say_test.py 项目: rvsp/python-1
 def test_one_thousand_two_hundred_thirty_four(self):
     self.assertEqual(say(1234), "one thousand two hundred thirty-four")
示例#8
0
文件: say_test.py 项目: rvsp/python-1
 def test_twenty_two(self):
     self.assertEqual(say(22), "twenty-two")
示例#9
0
 def test_987654321123(self):
     self.assertEqual(say(987654321123),
                      ("nine hundred and eighty-seven billion "
                       "six hundred and fifty-four million "
                       "three hundred and twenty-one thousand "
                       "one hundred and twenty-three"))
示例#10
0
 def test_eight_hundred_and_ten_thousand(self):
     self.assertEqual(say(810000), "eight hundred and ten thousand")
示例#11
0
 def test_fourteen(self):
     self.assertEqual("fourteen", say(14))
示例#12
0
 def test_eight_hundred_and_ten_thousand(self):
     self.assertEqual(say(810000), "eight hundred and ten thousand")
示例#13
0
 def test_twenty_two(self):
     self.assertEqual(say(22), "twenty-two")
示例#14
0
 def test_twenty(self):
     self.assertEqual(say(20), "twenty")
示例#15
0
 def test_fourteen(self):
     self.assertEqual(say(14), "fourteen")
示例#16
0
 def test_one_hundred_twenty_three(self):
     self.assertEqual("one hundred and twenty-three", say(123))
示例#17
0
 def test_zero(self):
     self.assertEqual("zero", say(0))
示例#18
0
 def test_987654321123(self):
     self.assertEqual(
         say(987654321123), ("nine hundred and eighty-seven billion "
                             "six hundred and fifty-four million "
                             "three hundred and twenty-one thousand "
                             "one hundred and twenty-three"))
示例#19
0
 def test_number_negative(self):
     with self.assertRaises(AttributeError):
         say(-1)
示例#20
0
 def test_number_too_large(self):
     with self.assertRaisesWithMessage(ValueError):
         say(1e12)
示例#21
0
 def test_one_million_two(self):
     self.assertEqual(say(1000002), "one million and two")
示例#22
0
 def test_number_negative(self):
     with self.assertRaisesWithMessage(ValueError):
         say(-1)
示例#23
0
 def test_number_negative(self):
     with self.assertRaises(ValueError):
         say(-1)
示例#24
0
 def test_zero(self):
     self.assertEqual(say(0), "zero")
示例#25
0
文件: say_test.py 项目: rvsp/python-1
 def test_fourteen(self):
     self.assertEqual(say(14), "fourteen")
示例#26
0
 def test_one_thousand_two_hundred_thirty_four(self):
     self.assertEqual("one thousand two hundred and thirty-four", say(1234))
示例#27
0
文件: say_test.py 项目: rvsp/python-1
 def test_one_hundred_twenty_three(self):
     self.assertEqual(say(123), "one hundred twenty-three")
示例#28
0
 def test_one_million(self):
     self.assertEqual("one million", say(1e6))
示例#29
0
文件: say_test.py 项目: rvsp/python-1
 def test_one_billion(self):
     self.assertEqual(say(1000000000), "one billion")
示例#30
0
 def test_one_million_two(self):
     self.assertEqual("one million and two", say(1000002))
示例#31
0
 def test_twenty_two(self):
     self.assertEqual("twenty-two", say(22))
示例#32
0
 def test_1002345(self):
     self.assertEqual("one million two thousand three hundred and forty-five", say(1002345))
示例#33
0
 def test_one_billion(self):
     self.assertEqual("one billion", say(1e9))
示例#34
0
 def test_one_billion(self):
     self.assertEqual("one billion", say(1e9))
示例#35
0
 def test_one(self):
     self.assertEqual("one", say(1))
示例#36
0
 def test_number_to_large(self):
     with self.assertRaises(AttributeError):
         say(1e12)
示例#37
0
 def test_number_to_large(self):
     with self.assertRaises(AttributeError):
         say(1e12)
示例#38
0
 def test_number_negative(self):
     with self.assertRaises(AttributeError):
         say(-42)
示例#39
0
 def test_one_hundred_twenty(self):
     self.assertEqual(say(120), "one hundred and twenty")
示例#40
0
 def test_zero(self):
     self.assertEqual("zero", say(0))
示例#41
0
 def test_one_million(self):
     self.assertEqual(say(1e6), "one million")
示例#42
0
 def test_fourteen(self):
     self.assertEqual("fourteen", say(14))
示例#43
0
 def test_1002345(self):
     self.assertEqual(
         say(1002345),
         "one million two thousand three hundred and forty-five")
示例#44
0
 def test_twenty(self):
     self.assertEqual("twenty", say(20))
示例#45
0
 def test_number_to_large(self):
     with self.assertRaises(ValueError):
         say(1e12)
示例#46
0
 def test_twenty_two(self):
     self.assertEqual("twenty-two", say(22))
示例#47
0
 def test_zero(self):
     self.assertEqual(say(0), "zero")
示例#48
0
 def test_one_hundred(self):
     self.assertEqual("one hundred", say(100))
示例#49
0
文件: say_test.py 项目: rvsp/python-1
 def test_one(self):
     self.assertEqual(say(1), "one")
示例#50
0
 def test_one_hundred_twenty(self):
     self.assertEqual("one hundred and twenty", say(120))
示例#51
0
文件: say_test.py 项目: rvsp/python-1
 def test_twenty(self):
     self.assertEqual(say(20), "twenty")
示例#52
0
 def test_one_hundred_twenty_three(self):
     self.assertEqual("one hundred and twenty-three", say(123))
示例#53
0
文件: say_test.py 项目: rvsp/python-1
 def test_one_hundred(self):
     self.assertEqual(say(100), "one hundred")
示例#54
0
 def test_one_thousand(self):
     self.assertEqual("one thousand", say(1000))
示例#55
0
文件: say_test.py 项目: rvsp/python-1
 def test_one_thousand(self):
     self.assertEqual(say(1000), "one thousand")
示例#56
0
 def test_one(self):
     self.assertEqual("one", say(1))
示例#57
0
文件: say_test.py 项目: rvsp/python-1
 def test_one_million_two_thousand_three_hundred_forty_five(self):
     self.assertEqual(say(1002345),
                      "one million two thousand three hundred forty-five")
示例#58
0
 def test_one_hundred_seventy(self):
     self.assertEqual(say(170), "one hundred seventy")
示例#59
0
文件: say_test.py 项目: rvsp/python-1
 def test_a_big_number(self):
     self.assertEqual(
         say(987654321123),
         "nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three",
     )
示例#60
0
 def test_twenty(self):
     self.assertEqual("twenty", say(20))