Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super(TestDB, self).__init__(*args, **kwargs)
     self.db = DataBase("test")
Ejemplo n.º 2
0
import asyncio
from aiohttp import web
import json
from db.db import DataBase

db = DataBase()


async def send(message):
    reader, writer = await asyncio.open_connection('calculator', 8888)
    message_len = len(message)
    writer.write(f'{message_len}\n{message}'.encode())
    data = await reader.read()
    writer.close()
    return data


async def calc(request):
    data = await request.json()
    answer = await send(json.dumps(data))
    answer = answer.decode()
    if answer:
        if answer != 'False':
            expression_id = db.save_result(float(answer))
            return web.json_response({'expression_id': expression_id})
        raise web.HTTPBadRequest()
    raise web.HTTPInternalServerError()


async def result(request):
    data = await request.json()
Ejemplo n.º 3
0
        else:
            start = self.threadID*distributeNum
            end = start + distributeNum
            logs.debug("start:%d,end:%d",start,end)
            self.startGrabInfo(start,end)

    def run(self):
        logs.debug(self.name + " is running")
        self.entrance()

if __name__ == "__main__":
    threads = []
    #多线程
    config = Config()
    sysConfig = config.GetSysConfigPara()
    logConfig = config.GetLogConfigPara()
    dbConfig = config.GetDBConfigPara()
    logs = LogHandler(logConfig['logname'],logConfig['level'],logConfig['isfile'])
    db = DataBase(dbConfig['db_host'],dbConfig['db_port'],dbConfig['db_user'],dbConfig['db_pass'],dbConfig['db_db'],dbConfig['db_charset'],dbConfig['db_maxoverflow'])
    threads_num = sysConfig['threads_num']
    db.connectDB()
    page = sysConfig['crwaling_page']
    distributeNum = int(page / threads_num)
    failPageCount=[]
    logs.debug("distributeNum:%d",distributeNum)

    interface = Interface()
    interface.gui_arrang()
    tk.mainloop()