Пример #1
0
def main():
    global list_time_price_dm
    redis = redis_db()
    dict_data = read_mysql2dict()

    for time in list_time_price_dm:
        save_price_dm(redis, dict_data, time)
Пример #2
0
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.')
Пример #3
0
def main():
        global dict_date, list_price_month
        redis = redis_db()
        dict_data = read_mysql2dict('10:30:00', '11:00:00', 'number')
        list_date = list(map(lambda x : dict_date[x], list_price_month))
        date = '2014-06-29'
        list_data = dict_data[date]
        name = 'history:number:%s:full' % date
        line = create_number_line(name, list_data)
        print(name)
Пример #4
0
def write_dict2redis(dict_redis, t='price'):
    redis = redis_db()
    if t == 'price':
        prefix = 'format_price_'
    elif t == 'number':
        prefix = 'format_number_'
    else:
        return
    for date in dict_redis:
        list_redis = dict_redis[date]
        key = prefix + date.replace('-', '_')
        redis.set(key, list_redis)
        print('%s save to redis ok' % key)
Пример #5
0
def main():
    global source_data_a, source_data_b, MAX_Y

    proto = udp_proto()

    source_redis = redis_db(pp_config['redis_source_db'])
    redis = redis_db()

    list_ay = [None]
    list_ax = create_list_ax()
    list_by = [None]
    list_bx = create_list_bx()

    #date = pp_config['redis_date']

    name_number = 'current:number'
    line_number = draw_number_line(name_number, list_ax, list_ay, MAX_Y)
    redis.set(name_number, line_number)

    name_price = 'current:price'
    line_price = draw_price_line(name_price, list_bx, list_by)
    redis.set(name_price, line_price)

    while True:
        code = read_redis_data(source_redis, pp_config['redis_source_key'],
                               proto)
        if code == 'B':
            list_by = create_list_y(source_data_b)
            line_price = draw_price_line(name_price, list_bx, list_by)
            redis.set(name_price, line_price)
            continue
        if code == 'A':
            list_ay = create_list_y(source_data_a)
            line_number = draw_number_line(name_number, list_ax, list_ay,
                                           MAX_Y)
            redis.set(name_number, line_number)
            continue
Пример #6
0
def main():
    redis = redis_db()

    dict_data = read_mysql2dict()
    save_price_line(redis, dict_data)
    save_multi_price_line(redis, dict_data)

    dict_data = read_mysql2dict('10:30:00', '11:00:00', 'number')
    save_number_line(redis, dict_data)

    #dict_data = read_mysql2dict('10:30:00', '11:00:00', 'number')
    save_rate_line(redis, dict_data)

    #dict_data = read_mysql2dict('10:30:00', '11:00:00', 'number')
    save_rate_ma_line(redis, dict_data, 10)
Пример #7
0
def main():
    global pp_config, log_file, info_db
    rdb = redis_db(info_db)
    log = open(log_file, 'a')
    buff = rdb.get(pp_config['redis_key'])
    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]
        if day == pp_config['redis_day']:
            datetime = day + ' ' + time
            #print(datetime + '\t'+ info)
            log.write(datetime + '\t' + info + '\r\n')
    log.close()
    print()
    print('info saved into file.')
Пример #8
0
#!/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]