def get(self): path = self.request.path if doRender(self, path): logging.ingo("Hi from review!") return q_term = self.request.get("term").strip() q_option = self.request.get("search_option") if q_term: if q_option == "in_tags": query_str = "SELECT * FROM Company WHERE tags='%s'" % q_term.lower() if q_option == "in_names": query_str = "SELECT * FROM Company WHERE company_n_fractions ='%s'" % q_term.title() if q_option == "in_postalcode": query_str = "SELECT * FROM Company WHERE postal_code = %s" % int(q_term) if q_option == "in_cities": query_str = "SELECT * FROM Company WHERE city ='%s'" % q_term.title() if q_option == "in_description": query_str = "SELECT * FROM Company WHERE description_p_fractions ='%s'" % q_term.lower() else: query_str = "SELECT * FROM Company LIMIT 25" companies_data, results_number, first_letters_list, unique_cities, cities_ordered, navbar = get_companies_data( query_str ) template_values = { "companies": companies_data, "Q_term": q_term, "results_number": results_number, "cities_first_letters": first_letters_list, "cities": unique_cities, "cities_ordered": cities_ordered, "search_navbar": navbar, } doRender(self, "review.htm", template_values)
def main(): args = parse_args() token = args.token if not token: if not "TELEGRAM_TOKEN" in os.environ: print( "Please, set bot token through --token or TELEGRAM_TOKEN env variable" ) logging.ingo( "Please, set bot token through --token or TELEGRAM_TOKEN env variable" ) return token = os.environ["TELEGRAM_TOKEN"] ################################################################# # Your task is to complete dialogue_manager.py and use your # advanced DialogueManager instead of SimpleDialogueManager. # This is the point where you plug it into the Telegram bot. # Do not forget to import all needed dependencies when you do so. #simple_manager = SimpleDialogueManager() #bot = BotHandler(token, simple_manager) dialog_manager = DialogueManager(RESOURCE_PATH) bot = BotHandler(token, dialog_manager) ############################################################### print("Ready to talk!") logging.info("Ready to talk!") offset = 0 while True: updates = bot.get_updates(offset=offset) for update in updates: print("An update received.") logging.info("An update received.") if "message" in update: chat_id = update["message"]["chat"]["id"] if "text" in update["message"]: text = update["message"]["text"] if is_unicode(text): print("Update content: {}".format(update)) logging.info("Update content: {}".format(update)) bot.send_message( chat_id, bot.get_answer(update["message"]["text"])) else: bot.send_message( chat_id, "Hmm, you are sending some weird characters to me..." ) offset = max(offset, update['update_id'] + 1) time.sleep(1)
def waitdisappear(self, control, timeout, capture=False, exit=False): """ 等待控件消失 :param control: 控件名称 :param timeout: 等待时间,单位为秒 :param capture: 如果控件在指定时间中未消失,是否截图,默认为false :param exit: 如果控件在指定时间中未消失,是否退出程序,默认为false :return: """ if WaitForDisappear(control, timeout): logging.ingo("控件-{}-在{}s中已消失".format(control, timeout)) else: logging.ingo("控件-{}-在{}s中未消失".format(control, timeout), ConsoleColor.Yellow) # sys.exit(0) if capture: self.captureimg(control) if exit: sys.exit(0)
def on_message(client, userdata, msg): if can_log(): logging.info("Received a message by topic: " + "[" + msg.topic + "]") measurements = json.loads(msg.payload) # timestamp = dateutil.parser.parse(measurements['timestamp']) if measurements.get('timestamp') else None timestamp = measurements['timestamp'] if measurements.get( 'timestamp') else None location = msg.topic.split("/")[1] machine = msg.topic.split("/")[2] if can_log(): info = timestamp if timestamp else "NOW" logging.ingo("Data timestamp is: " + info) to_send = [] for key in measurements: # delete the useless info if not isinstance(measurements[key], str): to_send.append({ 'measurement': key, 'tags': { 'location': location, 'machine': machine }, 'fields': { 'data': measurements[key] }, 'time': str(timestamp) }) if can_log(): logging.info(location + "." + machine + "." + key + " " + measurements[key]) # send data to database try: database.write_points(to_send, database="iot", time_precision="u") # print(database.write(to_send)) except Exception as e: print("the error is: ") print(e)
def waitexist(self, control, timeout, capture=False, exit=False): """ 等待控件出现 :param control: 控件名称 :param timeout: 等待时间,单位为秒 :param capture: 如果控件在指定时间中未出现,是否截图,默认为false :param exit: 如果控件在指定时间中未出现,是否退出程序,默认为false :return: """ if WaitForExist(control, timeout): logging.ingo("控件-{}-在{}s中已存在".format(control, timeout)) return True else: logging.ingo("控件-{}-在{}s中未存在".format(control, timeout), ConsoleColor.Yellow) # sys.exit(0) if capture: self.captureimg(control) if exit: sys.exit(0) return False
def get(self): path = self.request.path if doRender(self, path): logging.ingo('Hi from review!') return q_term = self.request.get('term').strip() q_option = self.request.get('search_option') if q_term: if q_option == "in_tags": query_str = "SELECT * FROM Company WHERE tags='%s'" % q_term.lower( ) if q_option == "in_names": query_str = "SELECT * FROM Company WHERE company_n_fractions ='%s'" % q_term.title( ) if q_option == "in_postalcode": query_str = "SELECT * FROM Company WHERE postal_code = %s" % int( q_term) if q_option == "in_cities": query_str = "SELECT * FROM Company WHERE city ='%s'" % q_term.title( ) if q_option == "in_description": query_str = "SELECT * FROM Company WHERE description_p_fractions ='%s'" % q_term.lower( ) else: query_str = "SELECT * FROM Company LIMIT 25" companies_data, results_number, first_letters_list, unique_cities, cities_ordered, navbar = get_companies_data( query_str) template_values = { 'companies': companies_data, 'Q_term': q_term, 'results_number': results_number, 'cities_first_letters': first_letters_list, 'cities': unique_cities, 'cities_ordered': cities_ordered, 'search_navbar': navbar } doRender(self, 'review.htm', template_values)
def log(sql, args=()): logging.ingo('SQL: %s' % sql)
def thread_func(name): logging.ingo("Thread %s is starting", name) time.sleep(2) logging.info("Thread %s is finishing", name)
def main(): options = _getoptions() command = options.command.lower() if options.logfile: if options.logfile == 'none': logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename=options.logfile, filemode='w') else: logfile = 'sdl-%s-%s-%s.log' % (options.command, options.key, str(int(time.time()))) logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename=logfile, filemode='w') # For Macs which have GDAL.framework, we can autodetect it # and use it automatically. if options.ogr2ogr_path is None: options.ogr2ogr_path = '/Library/Frameworks/GDAL.framework/Programs/ogr2ogr' if not os.path.exists(options.ogr2ogr_path): # We don't have a path to use; let subprocess.call # find it. options.ogr2ogr_path = 'ogr2ogr' if command == 'tilecsvs2appengine': ''' Bulkloads all CSV files for a Tile to App Engine datastore. Assumes all files for loading are in locations matching: Tile[nn-i]/forcouch/*.csv where nn is the tile key and i is a tile section run number. options.workspace should be the directory containing these Tile section subdirectories. ''' if options.config_file is None: sys.exit(0) cmd = 'appcfg.py upload_data --batch_size=%s --num_threads=%s --config_file=%s --filename=%s --kind CellIndex --url=%s' os.chdir(options.workspace) if options.key is None: match = 'Tile*' else: match = 'Tile%s-*' % options.key for tiledir in glob.glob(match): print tiledir couchdir = os.path.join(tiledir, 'forcouch') for csvfile in glob.glob(os.path.join(couchdir,'*.csv')): print csvfile if csvfile.find('-jsonfix.csv') == -1: dr = csv.DictReader(open(csvfile, 'r'), quotechar="'") filename = '%s-jsonfix.csv' % os.path.splitext(csvfile)[0] dwfile = open(filename, 'w') fieldnames = ['cellkey', 'doc'] dw = csv.DictWriter(dwfile, fieldnames, quotechar='"') dw.writer.writerow(dw.fieldnames) # dw = csv.DictWriter(dwfile, ['cellkey', 'doc']) # dw.writeheader() for row in dr: dw.writerow(dict( cellkey=row['cellkey'], doc=simplejson.dumps(simplejson.loads(row['doc'])))) dwfile.flush() dwfile.close() cf = os.path.abspath(options.config_file) fn = os.path.abspath(filename) cmd_line = cmd % ( 1, 5, os.path.abspath(options.config_file), os.path.abspath(filename), options.url) print cmd_line args = shlex.split(cmd_line) subprocess.call(args) sys.exit(1) if command=='prepareworkspace': logging.info('Beginning prepareworkspace()...%s' % options.workspace) t0 = time.time() if not prepareworkspace(options): logging.info('Unable to prepare workspace %s.' % options.workspace) t1 = time.time() logging.info('Total elapsed time to prepareworkspace(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='getworldclimtile': ''' Make sure Worldclim layers are in place for the Tile.''' logging.info('Beginning getworldclimtile()...get Worldclim layers for Tile %s' % options.key) t0 = time.time() if not getworldclimtile(options): logging.ingo('Unable to prepare Worldclim tile layers.') sys.exit(0) t1 = time.time() logging.info('Total elapsed time to getworldclimtile(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='cliptileonly': batchdir = os.path.join(options.workspace,'batches') logging.info('Beginning prepareworkspace()...%s' % options.workspace) t0 = time.time() if not prepareworkspace(options): logging.info('Unable to prepare workspace %s.' % options.workspace) sys.exit(0) t1 = time.time() logging.info('Total elapsed time to prepareworkspace(): %s' % (t1-t0)) logging.info('Beginning makeclippedtile()...create clipped Tile of area to process') t0 = time.time() clippedtile = makeclippedtile(options) t1 = time.time() logging.info('Total elapsed time to makeclippedtile(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='batchcells2shapes': batchdir = os.path.join(options.workspace,'batches') logging.info('Beginning prepareworkspace()...%s' % options.workspace) t0 = time.time() if not prepareworkspace(options): logging.info('Unable to prepare workspace %s.' % options.workspace) sys.exit(0) t1 = time.time() logging.info('Total elapsed time to prepareworkspace(): %s' % (t1-t0)) logging.info('Beginning makeclippedtile()...create clipped Tile of area to process') t0 = time.time() clippedtile = makeclippedtile(options) t1 = time.time() logging.info('Total elapsed time to makeclippedtile(): %s' % (t1-t0)) if not os.path.exists(batchdir): os.mkdir(batchdir) if not os.path.exists(batchdir): logging.info('Unable to make batch directory %s.' % batchdir) sys.exit(0) logging.info('Beginning batchprocesscells()...') t0 = time.time() clippedtile.batchprocesscells(batchdir, options) t1 = time.time() logging.info('Total elapsed time to batchprocesscells(): %s' % (t1-t0)) logging.info('Beginning clipcellbatchfiles()...') t0 = time.time() clippingshape = os.path.join(options.workspace,clippedtile.filename) clipcellbatchfiles(batchdir, clippingshape, options) t1 = time.time() logging.info('Total elapsed time to clipcellbatchfiles(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='starspan': batchdir = os.path.join(options.workspace,'batches') logging.info('Beginning starspanclippedcellbatchfiles()...') t0 = time.time() starspanclippedcellbatchfiles(batchdir, options.vardir) t1 = time.time() logging.info('Total elapsed time to starspanclippedcellbatchfiles(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='starspan2couch': batchdir = os.path.join(options.workspace,'batches') logging.info('Beginning starspancsvdir2couchcsvs()...') t0 = time.time() starspancsvdir2couchcsvs(batchdir, options.key, options.cells_per_degree, options.workspace) t1 = time.time() logging.info('Total elapsed time to starspancsvdir2couchcsvs(): %s' % (t1-t0)) sys.exit(1) if command=='couchfromcsvs': couchdir = os.path.join(options.workspace,'forcouch') logging.info('Beginning couchcsvdir2couchdb()...') t0 = time.time() couchcsvdir2couchdb(couchdir, options.couchurl, options.database) t1 = time.time() logging.info('Total elapsed time to couchcsvdir2couchdb(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='tilesection2couchcsvs': ''' Make sure Worlclim layers are in place for the Tile before running this command.''' batchdir = os.path.join(options.workspace,'batches') couchdir = os.path.join(options.workspace,'forcouch') if not prepareworkspace(options): logging.info('Unable to prepare workspace.') sys.exit(0) logging.info('Beginning makeclippedtile()...create clipped Tile of area to process') t0 = time.time() clippedtile = makeclippedtile(options) t1 = time.time() logging.info('Total elapsed time to makeclippedtile(): %s' % (t1-t0)) if not os.path.exists(batchdir): os.mkdir(batchdir) if not os.path.exists(batchdir): logging.info('Unable to make batch directory %s.' % batchdir) sys.exit(0) logging.info('Beginning batchprocesscells()...') t0 = time.time() clippedtile.batchprocesscells(batchdir, options) t1 = time.time() logging.info('Total elapsed time to batchprocesscells(): %s' % (t1-t0)) logging.info('Beginning clipcellbatchfiles()...') t0 = time.time() clippingshape = os.path.join(options.workspace,clippedtile.filename) clipcellbatchfiles(batchdir, clippingshape, options) t1 = time.time() logging.info('Total elapsed time to clipcellbatchfiles(): %s' % (t1-t0)) logging.info('Beginning starspanclippedcellbatchfiles()...') t0 = time.time() starspanclippedcellbatchfiles(batchdir, options.vardir) t1 = time.time() logging.info('Total elapsed time to starspanclippedcellbatchfiles(): %s' % (t1-t0)) logging.info('Beginning starspancsvdir2couchcsvs()...') t0 = time.time() starspancsvdir2couchcsvs(batchdir, options.key, options.cells_per_degree, options.workspace) t1 = time.time() logging.info('Total elapsed time to starspancsvdir2couchcsvs(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) if command=='full': batchdir = os.path.join(options.workspace,'batches') couchdir = os.path.join(options.workspace,'forcouch') if not prepareworkspace(options): logging.info('Unable to prepare workspace.') sys.exit(0) ''' Make sure Worlclim layers are in place for the Tile.''' logging.info('Beginning getworldclimtile()...get Worldclim layers for Tile %s' % options.key) t0 = time.time() if not getworldclimtile(options): loggging.info('Unable to prepare Worldclim tile layers.') sys.exit(0) t1 = time.time() logging.info('Total elapsed time to getworldclimtile(): %s' % (t1-t0)) logging.info('Beginning makeclippedtile()...create clipped Tile of area to process') t0 = time.time() clippedtile = makeclippedtile(options) t1 = time.time() logging.info('Total elapsed time to makeclippedtile(): %s' % (t1-t0)) if not os.path.exists(batchdir): os.mkdir(batchdir) if not os.path.exists(batchdir): logging.info('Unable to make batch directory %s.' % batchdir) sys.exit(0) logging.info('Beginning batchprocesscells()...') t0 = time.time() clippedtile.batchprocesscells(batchdir, options) t1 = time.time() logging.info('Total elapsed time to batchprocesscells(): %s' % (t1-t0)) logging.info('Beginning clipcellbatchfiles()...') t0 = time.time() clippingshape = os.path.join(options.workspace,clippedtile.filename) clipcellbatchfiles(batchdir, clippingshape, options) t1 = time.time() logging.info('Total elapsed time to clipcellbatchfiles(): %s' % (t1-t0)) logging.info('Beginning starspanclippedcellbatchfiles()...') t0 = time.time() starspanclippedcellbatchfiles(batchdir, options.vardir) t1 = time.time() logging.info('Total elapsed time to starspanclippedcellbatchfiles(): %s' % (t1-t0)) logging.info('Beginning starspancsvdir2couchcsvs()...') t0 = time.time() starspancsvdir2couchcsvs(batchdir, options.key, options.cells_per_degree, options.workspace) t1 = time.time() logging.info('Total elapsed time to starspancsvdir2couchcsvs(): %s' % (t1-t0)) logging.info('Beginning couchcsvdir2couchdb()...') t0 = time.time() couchcsvdir2couchdb(couchdir, options.couchurl, options.database) t1 = time.time() logging.info('Total elapsed time to couchcsvdir2couchdb(): %s' % (t1-t0)) logging.info('Command %s complete.' % (command)) sys.exit(1) logging.info('Command %s not understood.' % command)
host = credentials.get('host'), #port = credentials.get('port'), is_secure = credentials.get('is_secure', True), calling_format = boto.s3.connection.OrdinaryCallingFormat(), ) mp = conn.get_bucket(args.bucket).initiate_multipart_upload(args.key) i = 0 while True: i += 1 ramdisk = mmap.mmap(-1, GIG) ramdisk.write(sys.stdin.read(GIG)) size = ramdisk.tell() if not size: break ramdisk.seek(0) logging.ingo('Uploading chunk {}'.format(i)) try: mp.upload_part_from_file(ramdisk, part_num=i, size=size) except Exception as err: logging.error('Failed writing part - cancelling multipart.') mp.cancel_upload() raise logging.info('Completing multipart.') mp.complete_upload()