def main(): global pp_config mdb = mysql_db(pp_config['mysql_origin_db']) rdb = redis_db(pp_config['redis_db']) redis_key = pp_config['redis_key'] redis_day = pp_config['redis_day'] buff = rdb.get(redis_key) list_data = [] for line in buff: line = line.decode().lstrip('(').rstrip(')') try: date, info = line.split(',', 1) except: continue info = info.strip() info = info.strip('\'') date = date.strip('\'') day, time = date.split(' ', 1) time = time.split('.', 1)[0] day = redis_day # XXX XXX XXX if day == redis_day: datetime = day + ' ' + time list_data.append((datetime, info)) prefix = 'format_origin_' table = prefix + redis_day.replace('-', '_') mdb.clean_table(table) mdb.insert_log_list(table, list_data) mdb.flush() print('date saved into mysql.')
def main(): global dict_table, pp_config mysql = mysql_db(pp_config['mysql_format_db']) format_data = fmt_readexcel2list() for m in format_data: list_data = format_data[m] table = 'format_price_' + dict_date[m].replace('-', '_') mysql.clean_table(table) mysql.insert_price_list(table, list_data) mysql.flush()
def main(): global date, month, dict_number_time, dict_price_time org_mysql = mysql_db(pp_config['mysql_origin_db']) list_log = read_log(org_mysql, date) org_mysql.close() parser = udp_proto() list_price, list_number = parse_log(parser, date, list_log) time_number = dict_number_time[month] time_number_begin = date + ' ' + time_number[0] time_number_end = date + ' ' + time_number[1] time_price = dict_price_time[month] time_price_begin = date + ' ' + time_price[0] time_price_end = date + ' ' + time_price[1] list_format_price = fmt_formater(list_price, time_price_begin, time_price_end) list_format_number = fmt_formater(list_number, time_number_begin, time_number_end) fmt_mysql = mysql_db(pp_config['mysql_format_db']) write_number(fmt_mysql, date, list_format_number) write_price(fmt_mysql, date, list_format_price)
def read_mysql2list(date, begin, end, mode): global pp_config mysql = mysql_db(pp_config['mysql_format_db']) if mode == 'price': prefix = 'format_price_' elif mode == 'number': prefix = 'format_number_' else: return None table = prefix + date.replace('-', '_') list_data = mysql.read(table) list_out = [] for data in list_data: time = str(data[1]).split()[1] if time_sub(time, begin) >= 0 and time_sub(end, time) >= 0: list_out.append(data) mysql.close() return list_out
def read_mysql2dict(begin='11:29:00', end='11:30:00', mode='price'): global dict_date, list_price_month, list_number_month, pp_config mysql = mysql_db(pp_config['mysql_format_db']) dict_data = OrderedDict() if mode == 'price': prefix = 'format_price_' list_month = list_price_month elif mode == 'number': prefix = 'format_number_' list_month = list_number_month else: return dict_data for m in list_month: table = prefix + dict_date[m].replace('-', '_') list_data = mysql.read(table) if list_data == None: continue list_out = [] for data in list_data: time = str(data[1]).split()[1] if time_sub(time, begin) >= 0 and time_sub(end, time) >= 0: list_out.append(data) dict_data[dict_date[m]] = list_out mysql.close() return dict_data
#!/usr/bin/env python3 from wsgiref.simple_server import make_server from pygal import Line from pp_log import posix_logger from pp_db import mysql_db, redis_db #======================================= logger = posix_logger('pygal.log') mysql = mysql_db() redis = redis_db() if mysql != None: logger.info('mysql connect init ok') if redis != None: logger.info('redis connect init ok') #======================================= def application(env, start_response): global logger, mysql, redis req = env['REQUEST_URI'].split('/', 2)[2].strip().strip('?') logger.debug(req) data = redis.get(req) if data == None: data = (req + ':Data no found !!!').encode() start_response('200 OK', [('Content-Type', 'text/html')]) return [data]