Ejemplo n.º 1
0
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]))
Ejemplo n.º 2
0
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
Ejemplo n.º 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 )
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
 def test_one_thousand_two_hundred_thirty_four(self):
     self.assertEqual(say(1234), "one thousand two hundred thirty-four")
Ejemplo n.º 8
0
 def test_twenty_two(self):
     self.assertEqual(say(22), "twenty-two")
Ejemplo n.º 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"))
Ejemplo n.º 10
0
 def test_eight_hundred_and_ten_thousand(self):
     self.assertEqual(say(810000), "eight hundred and ten thousand")
Ejemplo n.º 11
0
 def test_fourteen(self):
     self.assertEqual("fourteen", say(14))
Ejemplo n.º 12
0
 def test_eight_hundred_and_ten_thousand(self):
     self.assertEqual(say(810000), "eight hundred and ten thousand")
Ejemplo n.º 13
0
 def test_twenty_two(self):
     self.assertEqual(say(22), "twenty-two")
Ejemplo n.º 14
0
 def test_twenty(self):
     self.assertEqual(say(20), "twenty")
Ejemplo n.º 15
0
 def test_fourteen(self):
     self.assertEqual(say(14), "fourteen")
Ejemplo n.º 16
0
 def test_one_hundred_twenty_three(self):
     self.assertEqual("one hundred and twenty-three", say(123))
Ejemplo n.º 17
0
 def test_zero(self):
     self.assertEqual("zero", say(0))
Ejemplo n.º 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"))
Ejemplo n.º 19
0
 def test_number_negative(self):
     with self.assertRaises(AttributeError):
         say(-1)
Ejemplo n.º 20
0
 def test_number_too_large(self):
     with self.assertRaisesWithMessage(ValueError):
         say(1e12)
Ejemplo n.º 21
0
 def test_one_million_two(self):
     self.assertEqual(say(1000002), "one million and two")
Ejemplo n.º 22
0
 def test_number_negative(self):
     with self.assertRaisesWithMessage(ValueError):
         say(-1)
Ejemplo n.º 23
0
 def test_number_negative(self):
     with self.assertRaises(ValueError):
         say(-1)
Ejemplo n.º 24
0
 def test_zero(self):
     self.assertEqual(say(0), "zero")
Ejemplo n.º 25
0
 def test_fourteen(self):
     self.assertEqual(say(14), "fourteen")
Ejemplo n.º 26
0
 def test_one_thousand_two_hundred_thirty_four(self):
     self.assertEqual("one thousand two hundred and thirty-four", say(1234))
Ejemplo n.º 27
0
 def test_one_hundred_twenty_three(self):
     self.assertEqual(say(123), "one hundred twenty-three")
Ejemplo n.º 28
0
 def test_one_million(self):
     self.assertEqual("one million", say(1e6))
Ejemplo n.º 29
0
 def test_one_billion(self):
     self.assertEqual(say(1000000000), "one billion")
Ejemplo n.º 30
0
 def test_one_million_two(self):
     self.assertEqual("one million and two", say(1000002))
Ejemplo n.º 31
0
 def test_twenty_two(self):
     self.assertEqual("twenty-two", say(22))
Ejemplo n.º 32
0
 def test_1002345(self):
     self.assertEqual("one million two thousand three hundred and forty-five", say(1002345))
Ejemplo n.º 33
0
 def test_one_billion(self):
     self.assertEqual("one billion", say(1e9))
Ejemplo n.º 34
0
 def test_one_billion(self):
     self.assertEqual("one billion", say(1e9))
Ejemplo n.º 35
0
 def test_one(self):
     self.assertEqual("one", say(1))
Ejemplo n.º 36
0
 def test_number_to_large(self):
     with self.assertRaises(AttributeError):
         say(1e12)
Ejemplo n.º 37
0
 def test_number_to_large(self):
     with self.assertRaises(AttributeError):
         say(1e12)
Ejemplo n.º 38
0
 def test_number_negative(self):
     with self.assertRaises(AttributeError):
         say(-42)
Ejemplo n.º 39
0
 def test_one_hundred_twenty(self):
     self.assertEqual(say(120), "one hundred and twenty")
Ejemplo n.º 40
0
 def test_zero(self):
     self.assertEqual("zero", say(0))
Ejemplo n.º 41
0
 def test_one_million(self):
     self.assertEqual(say(1e6), "one million")
Ejemplo n.º 42
0
 def test_fourteen(self):
     self.assertEqual("fourteen", say(14))
Ejemplo n.º 43
0
 def test_1002345(self):
     self.assertEqual(
         say(1002345),
         "one million two thousand three hundred and forty-five")
Ejemplo n.º 44
0
 def test_twenty(self):
     self.assertEqual("twenty", say(20))
Ejemplo n.º 45
0
 def test_number_to_large(self):
     with self.assertRaises(ValueError):
         say(1e12)
Ejemplo n.º 46
0
 def test_twenty_two(self):
     self.assertEqual("twenty-two", say(22))
Ejemplo n.º 47
0
 def test_zero(self):
     self.assertEqual(say(0), "zero")
Ejemplo n.º 48
0
 def test_one_hundred(self):
     self.assertEqual("one hundred", say(100))
Ejemplo n.º 49
0
 def test_one(self):
     self.assertEqual(say(1), "one")
Ejemplo n.º 50
0
 def test_one_hundred_twenty(self):
     self.assertEqual("one hundred and twenty", say(120))
Ejemplo n.º 51
0
 def test_twenty(self):
     self.assertEqual(say(20), "twenty")
Ejemplo n.º 52
0
 def test_one_hundred_twenty_three(self):
     self.assertEqual("one hundred and twenty-three", say(123))
Ejemplo n.º 53
0
 def test_one_hundred(self):
     self.assertEqual(say(100), "one hundred")
Ejemplo n.º 54
0
 def test_one_thousand(self):
     self.assertEqual("one thousand", say(1000))
Ejemplo n.º 55
0
 def test_one_thousand(self):
     self.assertEqual(say(1000), "one thousand")
Ejemplo n.º 56
0
 def test_one(self):
     self.assertEqual("one", say(1))
Ejemplo n.º 57
0
 def test_one_million_two_thousand_three_hundred_forty_five(self):
     self.assertEqual(say(1002345),
                      "one million two thousand three hundred forty-five")
Ejemplo n.º 58
0
 def test_one_hundred_seventy(self):
     self.assertEqual(say(170), "one hundred seventy")
Ejemplo n.º 59
0
 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",
     )
Ejemplo n.º 60
0
 def test_twenty(self):
     self.assertEqual("twenty", say(20))