示例#1
0
def Tassadar():
    _db = 'tassadar'
    conf = Configuration().get_section(_db)
    database_url = conf.get('url')
    try:
        return MySQLHelper(database_url)
    except Exception, e:
        print e.message

        print_stack()
        return None
示例#2
0
 def __init__(self):
     conf = Configuration()
     host = conf.get("redis", "host")
     port = int(conf.get("redis", "port"))
     self.redis_key = "KST:QUEUE:%s" % conf.get("global", "subpub_prefix")
     try:
         self.handler = StrictRedis(host,
                                    port,
                                    retry_on_timeout=True,
                                    socket_timeout=300,
                                    socket_connect_timeout=300)
     except:
         self.handler = StrictRedis(host, port)
示例#3
0
文件: main.py 项目: nixiaocang/upload
def main():
    parse_command_line()
    port = Configuration().get("global", "port")
    debug_model = int(Configuration().get('global', 'debug'))
    sys.stderr.write("listen server on port %s ..\n" % port)
    application = BlogApplication(handler, **{
        'debug':True if debug_model else False,
        "static_path": os.path.join(os.path.dirname(__file__), "static"),
    })
    server = tornado.httpserver.HTTPServer(application, max_buffer_size=1024*1024*1024)
    server.bind(port)
    server.start(1 if debug_model else 10)
    tornado.ioloop.IOLoop.instance().start()
示例#4
0
 def __init__(self, user_id, token):
     conf = Configuration()
     self.host = conf.get("mongo", "host")
     self.port = int(conf.get("mongo", "port"))
     self.user_id = user_id
     self.opends = Client(token)
     self.ds = self.opends.get_ds(u'快商通')
     self.tb = self.ds.get_table('kuaishangtong')
     #self.vtb = self.ds.get_table('vcard')
     self.vtb = self.ds.get_table('kst_test')
     self.conn = MongoClient(self.host, self.port)
     self.db = self.conn['jiaogf']
     self.yes = datetime.datetime.today() - datetime.timedelta(days=1)
     self.yesterday = datetime.datetime.strftime(self.yes,'%Y%m%d')
示例#5
0
def main():
    port = Configuration().get("global", "port")
    debug_model = int(Configuration().get('global', 'debug'))
    sys.stderr.write("listen server on port %s ..\n" % port)
    application = ServerApplication(
        handler, **{
            'debug': True if debug_model else False,
            "cookie_secret": "18640803942",
            "login_url": "/api/login"
        })
    server = tornado.httpserver.HTTPServer(application,
                                           max_buffer_size=1024 * 1024 * 1024)
    server.bind(port)
    server.start(1 if debug_model else 10)
    tornado.ioloop.IOLoop.instance().start()
示例#6
0
def main():
    port = Configuration().get("global", "port")
    debug_model = int(Configuration().get('global', 'debug'))
    sys.stderr.write("listen server on port %s ..\n" % port)
    application = KstApplication(handler, **{
        'debug':True if debug_model else False,
        "static_path": os.path.join(os.path.dirname(__file__), "static"),
        #"template_path": os.path.join(os.path.dirname(__file__), "templates"),
        #"cookie_secret": "bZJc2sWbQLKos6GkHn/VB9oXwQt8S0R0kRvJ5/xJ89E=",
        #"login_url": "/api/login"
    })
    server = tornado.httpserver.HTTPServer(application, max_buffer_size=1024*1024*1024)
    server.bind(port)
    server.start(1 if debug_model else 10)
    tornado.ioloop.IOLoop.instance().start()
示例#7
0
 def __init__(self):
     self.logger = api_logger()
     try:
         self.conf = Configuration().get_section('blog')
         self.db = MySQLdb.connect(host=self.conf['host'],
                                   user=self.conf['user'],
                                   passwd=self.conf['passwd'],
                                   db=self.conf['db'],
                                   charset=self.conf['charset'])
     except Exception, e:
         self.logger.error(e.message)
         raise e
示例#8
0
 async def get_file(self, reportId, url):
     path = Configuration().get('global', 'log_path')
     res = requests.get(url)
     gzipname = os.path.join(path, reportId + '.csv.gz')
     filename = os.path.join(path, reportId + '.csv')
     with open(gzipname, "wb") as code:
         code.write(res.content)
     g = gzip.GzipFile(mode="rb", fileobj=open(gzipname, 'rb'))
     with open(filename, "wb") as writer:
         writer.write(g.read())
     df = pd.read_csv(filename, encoding='gbk')
     df = df.fillna("")
     df = df.drop([0])
     return df
示例#9
0
 def req_vdata(self, user_id, compId, ak, kst_url, data):
     tt = int(time.time() * 10000)
     data['tt'] = str(tt)
     vprefix = Configuration().get('url_prefix', 'vprefix')
     pu = vprefix + '?user_id="%s"&compId="%s"' % (user_id, compId)
     params = {
         "ak": ak,
         "tt": str(tt),
         "pu": pu,
         "pt": "VISITORCARD",
     }
     kssign = self.gen_sign(data)
     params['kssign'] = kssign
     res = self._request(kst_url, params)
     result = json.loads(res.content)
     runtime_logger().info("用户:%s请求历史名片信息返回结果:%s" % (user_id, res.content))
     conn_res = self.deal_res(result)
     return conn_res
示例#10
0
class SearchReportHandler(BaseHandler):
    route = "search_report_sougou_sem"


class CreativeReportHandler(BaseHandler):
    route = "creative_report_sougou_sem"


class PlanReportHandler(BaseHandler):
    route = "campaign_report_sougou_sem"


if __name__ == "__main__":
    app = tornado.web.Application(handlers=[(
        r"/auth_account",
        AuthAccountHandler), (
            r"/keyword_sougou_sem", KeywordInfoReportHandler
        ), (r"/search_report_sougou_sem", SearchReportHandler
            ), (r"/campaign_report_sougou_sem", PlanReportHandler
                ), (r"/keyword_report_sougou_sem", KeywordReportHandler
                    ), (r"/creative_report_sougou_sem",
                        CreativeReportHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    conf = Configuration()
    port = int(conf.get("global", 'port'))
    debug_model = int(conf.get('global', 'debug'))
    process_num = int(conf.get('global', 'process_num'))
    http_server.listen(int(port))
    http_server.start(1 if debug_model else process_num)
    tornado.ioloop.IOLoop.current().start()
示例#11
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import uuid
import requests
import json
from model.gabrin import Gabrin
from model.leviathan import Leviathan
from util.config import Configuration

OVERLORD_URL = Configuration().get('service', 'OVERLORD_URL')


class Shopex:
    def __init__(self, kwargs):
        self.kwargs = {}
        self.domain = kwargs.get('domain')
        self.contact = kwargs.get('contact', 'admin')
        self.username = kwargs.get('username', 'admin')
        self.password = kwargs.get('username', 'admin')
        self.shopex_id = kwargs.get('shopex_id', '131109009276')
        self.kwargs['domain'] = self.domain
        self.kwargs['contact'] = self.contact
        self.kwargs['username'] = self.username
        self.kwargs['password'] = self.password

    def gen_account(self):
        res = requests.post(OVERLORD_URL, data=self.kwargs)
        res = json.loads(res.content)
        status = res.get('status')
        bag = {'status': int(status)}
示例#12
0
 def __init__(self):
     conf = Configuration()
     self.connect_string = conf.get("mongo", "connect_string")
     self.db_name = conf.get("mongo", "database")
     self.conn = MongoClient(self.connect_string)
     self.db = self.conn[self.db_name]
示例#13
0
#!/usr/local/bin/python
# -*- coding:utf-8 -*-

import os
import logging
import logging.config
import traceback
from util.config import Configuration
log_path = Configuration().get('global', 'log_path')
conf_file = os.path.join(os.getenv('CONF'), 'logging.conf')
logging.config.fileConfig(conf_file, defaults={'log_path': log_path})


def runtime_logger():
    return logging.getLogger('runtime')


def print_stack():
    runtime_logger().info(traceback.format_exc().replace("\n", "####"))
示例#14
0
from fastapi import FastAPI, Request, Cookie, Response
from typing import List, Optional
import time
from odmantic import ObjectId

from model.client import Client
from util.config import Configuration
from util.database import Database

config = Configuration()
logger = config.get_logger()
database = Database(config.get_db_url(), config.get_db_name())

app = FastAPI()


@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
    start_time = time.time()
    response = await call_next(request)
    logger.info(f"client {request.client.host}:{request.client.port}")
    process_time = time.time() - start_time
    logger.info(f"time response >> {process_time}")
    response.headers["X-Process-Time"] = str(process_time)
    return response


@app.get("/client",
         response_model=List[Client],
         response_model_exclude={"user"})
async def client_list():
示例#15
0
 def get_token(self, user_id):
     url = Configuration.get('overlord', 'url')
     data = {"user_id": user_id}
     res = self._request(url, data)
     return res.get('token')