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]))
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
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 )
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
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))
def test_one_thousand_two_hundred_thirty_four(self): self.assertEqual(say(1234), "one thousand two hundred thirty-four")
def test_twenty_two(self): self.assertEqual(say(22), "twenty-two")
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"))
def test_eight_hundred_and_ten_thousand(self): self.assertEqual(say(810000), "eight hundred and ten thousand")
def test_fourteen(self): self.assertEqual("fourteen", say(14))
def test_twenty(self): self.assertEqual(say(20), "twenty")
def test_fourteen(self): self.assertEqual(say(14), "fourteen")
def test_one_hundred_twenty_three(self): self.assertEqual("one hundred and twenty-three", say(123))
def test_zero(self): self.assertEqual("zero", say(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"))
def test_number_negative(self): with self.assertRaises(AttributeError): say(-1)
def test_number_too_large(self): with self.assertRaisesWithMessage(ValueError): say(1e12)
def test_one_million_two(self): self.assertEqual(say(1000002), "one million and two")
def test_number_negative(self): with self.assertRaisesWithMessage(ValueError): say(-1)
def test_number_negative(self): with self.assertRaises(ValueError): say(-1)
def test_zero(self): self.assertEqual(say(0), "zero")
def test_one_thousand_two_hundred_thirty_four(self): self.assertEqual("one thousand two hundred and thirty-four", say(1234))
def test_one_hundred_twenty_three(self): self.assertEqual(say(123), "one hundred twenty-three")
def test_one_million(self): self.assertEqual("one million", say(1e6))
def test_one_billion(self): self.assertEqual(say(1000000000), "one billion")
def test_one_million_two(self): self.assertEqual("one million and two", say(1000002))
def test_twenty_two(self): self.assertEqual("twenty-two", say(22))
def test_1002345(self): self.assertEqual("one million two thousand three hundred and forty-five", say(1002345))
def test_one_billion(self): self.assertEqual("one billion", say(1e9))
def test_one(self): self.assertEqual("one", say(1))
def test_number_to_large(self): with self.assertRaises(AttributeError): say(1e12)
def test_number_negative(self): with self.assertRaises(AttributeError): say(-42)
def test_one_hundred_twenty(self): self.assertEqual(say(120), "one hundred and twenty")
def test_one_million(self): self.assertEqual(say(1e6), "one million")
def test_1002345(self): self.assertEqual( say(1002345), "one million two thousand three hundred and forty-five")
def test_twenty(self): self.assertEqual("twenty", say(20))
def test_number_to_large(self): with self.assertRaises(ValueError): say(1e12)
def test_one_hundred(self): self.assertEqual("one hundred", say(100))
def test_one(self): self.assertEqual(say(1), "one")
def test_one_hundred_twenty(self): self.assertEqual("one hundred and twenty", say(120))
def test_one_hundred(self): self.assertEqual(say(100), "one hundred")
def test_one_thousand(self): self.assertEqual("one thousand", say(1000))
def test_one_thousand(self): self.assertEqual(say(1000), "one thousand")
def test_one_million_two_thousand_three_hundred_forty_five(self): self.assertEqual(say(1002345), "one million two thousand three hundred forty-five")
def test_one_hundred_seventy(self): self.assertEqual(say(170), "one hundred seventy")
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", )