def main(): g = Google.Google() g.authenticate() l = -1 at_least_one = False for msg in g.search(query): at_least_one = True if g.resultSizeEstimate != l: l = g.resultSizeEstimate print l content = g.GetMimeMessage(msg['id']) print content['subject'] if not at_least_one: print 'No results'
# -*- coding: utf-8 -*- import Google sheet = Google( "https://www.googleapis.com/auth/spreadsheets" ) # read-write, use 'spreadsheets.readonly' if you lack the authorizations sheet.open( 'My Sheet', '<GOOGLE SHEET ID>' ) # store the id in memory for easier use. replace '<GOOGLE SHEET ID>' with the sheet id (easily found in the url= print(sheet.read('My Sheet', 'Page1!A3:C200') ) # example, reading the cells A3 to C200 from the sub sheet 'Page 1' sheet.write('My Sheet', 'Page2!A2:C3', [['test1', 'test2', 'test3'], ['test4', 'test5', 'test6'] ]) # write 2 rows with these test strings in the specified range sheet.close('My Sheet') # remove from memory
paragraphs: Iterator[str] = filter(lambda x: x, text.split('\n')) for paragraph in paragraphs: try: detector = Detector(paragraph) except UnknownLanguage: print("无法检测源语言") else: language: str = detector.language.code print(paragraph) print(translator.translate([paragraph], language)) print(u"Detected source language: {}".format( detector.language.name)) if __name__ == '__main__': translators = {"CaiYun": CaiYun.CaiYun(), "Google": Google.Google()} parser = argparse.ArgumentParser( description="use translators to translate text") parser.add_argument("text", type=str, help="the source text you want to translate") parser.add_argument( "-t", "--translator", type=str, default="Google", choices=translators.keys(), help="specify the translator you want to use (default: %(default)s)") args = parser.parse_args() text = args.text.replace('\n', ' ') main(text, translators.get(args.translator))