Example #1
0
 def __init__(self):
     self.host = config.get(self.config_key, 'host')
     self.port = config.get(self.config_key, 'port')
     self.db = config.get(self.config_key, 'db')
     self.redis_client = redis.StrictRedis(host=self.host,
                                           port=self.port,
                                           db=self.db)
Example #2
0
    def do_action(self, session):
        login_card = self.get_argument('login_card', None)
        password = self.get_argument('password', None)
        error_msg = ''
        if not login_card:
            error_msg = Error.NO_LOGIN_CARD
        elif not password:
            error_msg = Error.NO_PASSWORD

        if not error_msg:
            gen_password = Md5Helper().ori_str_gen(password)
            account = session.query(Account).filter(
                and_(
                    or_(Account.email == login_card,
                        Account.name == login_card),
                    Account.password == gen_password)).one_or_none()
            if account:
                cookie_expire_time = int(
                    config.get('global', 'cookie_expire_time'))
                domain = config.get('global', 'domain')
                self.set_secure_cookie("account_id",
                                       account.id,
                                       domain=domain,
                                       expires_days=cookie_expire_time)
                show = {'name': account.name, 'email': account.email}
                self.set_result({'show': show})
            else:
                error_msg = Error.LOGIN_ERROR

        if error_msg:
            self.set_error(1, error_msg)
Example #3
0
    def do_action(self, session):
        name = self.get_argument('name', None)
        password = self.get_argument('password', None)
        email = self.get_argument('email', None)
        error_msg = None
        if not all((name, password, email)):
            error_msg = Error.NO_REGISTER_ARGS
        if not error_msg and not VerifyHelper().name_check(name):
            error_msg = Error.NAME_ERROR
        if not error_msg and not VerifyHelper().mail_check(email):
            error_msg = Error.MAIL_ERROR
        if not error_msg:
            error_msg = VerifyHelper().password_verify(password)

        if not error_msg:
            try:
                account = session.query(Account.id).filter(
                    or_(Account.name == name,
                        Account.email == email)).one_or_none()

                if not account:
                    create_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                                time.localtime(time.time()))
                    account = Account(
                        id=tools.unique_id('ad'),
                        name=name,
                        password=Md5Helper().ori_str_gen(password),
                        email=email,
                        create_time=create_time)
                    session.add(account)
                    cookie_expire_time = int(
                        config.get('global', 'cookie_expire_time'))
                    domain = config.get('global', 'domain')
                    self.set_secure_cookie("account_id",
                                           account.id,
                                           domain=domain,
                                           expires_days=cookie_expire_time)
                    show = {'name': account.name, 'email': account.email}
                    self.set_result({'show': show})

                elif account.name == name:
                    error_msg = Error.DUPLICATE_NAME
                else:
                    error_msg = Error.DUPLICATE_MAIL
            except Exception, e:
                logger.api_logger().api_error(e)
                error_msg = Error.SERVER_ERROR
Example #4
0
def error500():
    key = 'error500_mysql'
    return MySQLHelper(
        "%s:%s" % (config.get(key, "host"), config.get(key, "port")),
        config.get(key, "user"), config.get(key, "password"),
        config.get(key, "database"))
Example #5
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tornado.httpserver
import tornado.ioloop
import tornado.locale
import tornado.web
from tornado.options import define, options, parse_command_line
from src.utils import config
from load import load_models

port = int(config.get("global", "port"))
debug_mode = int(config.get("global", "debug_mode"))
process_num = int(config.get("global", "process_num"))

settings = {
    'debug': debug_mode,
}

# define global parameter
define("port", default=port, help="server listening port")
define("models", default={})

# set global parameter
load_models()


def main():
    parse_command_line()
    print("start api server at %s" % options.port)

    import router
Example #6
0
 def __init__(self):
     self.host = config.get('redis', 'host')
     self.port = config.get('redis', 'port')
     self.db = config.get('redis', 'db')
Example #7
0
    def do_action(self):
        # data source
        raw_values = [{
            'date': '2018-10-10 00:01:00',
            'col1': 1.1,
            'col2': 2.1
        }, {
            'date': '2018-10-10 00:02:00',
            'col1': 1.2,
            'col2': 2.2
        }, {
            'date': '2018-10-10 00:03:00',
            'col1': 1.3,
            'col2': 2.3
        }, {
            'date': '2018-10-10 00:04:00',
            'col1': 1.4,
            'col2': 2.4
        }, {
            'date': '2018-10-10 00:05:00',
            'col1': 1.5,
            'col2': 2.5
        }]

        # delete redis rows by key
        rc = RedisClient()
        rc.delete_key("error500")

        # save to redis
        values = {
            "error500_" + str(value.get("date", "0")): {
                "timestamp": str(value.get("date", "0")),
                "col1": str(value.get("col1", 1.0)),
                "col2": str(value.get("col2", 2.0)),
            }
            for value in raw_values
        }
        rc.set_cache_data(values)

        # mysql create table
        name = config.get("mysql_error500_test", "name")
        cols = config.get("mysql_error500_test", "col").split(', ')
        types = config.get("mysql_error500_test", "type").split(', ')
        primarys = config.get("mysql_error500_test", "primary").split(', ')
        error500().execute(create_table_sql(name, cols, types, primarys))

        # insert mysql
        values = [{
            "timestamp":
            int(
                time.mktime(
                    time.strptime(str(value.get("date", 0)),
                                  '%Y-%m-%d %H:%M:%S'))),
            "date":
            value.get("date", "0"),
            "col1":
            value.get("col1", 1.0),
            "col2":
            value.get("col2", 1.0),
        } for value in raw_values]

        error500().insert_batch(name, values)
        self.set_result({
            "message":
            "succeed to insert ignore {num} rows to {name}".format(
                num=len(values), name=name)
        })
Example #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tornado.web
import tornado.ioloop
import tornado.httpserver
from tornado.options import options, define, parse_command_line
from tornado_sqlalchemy import make_session_factory

from env import set_env
set_env()

from router import url_map
from src.utils import config

DB_HOST = config.get('mysql', 'host')
DB_PORT = config.get('mysql', 'port')
DB = config.get('mysql', 'database')
DB_USER = config.get('mysql', 'user')
DB_PWD = config.get('mysql', 'password')
mysql_engine = 'mysql+mysqldb://%s:%s@%s:%s/%s?charset=utf8' % (
    DB_USER, DB_PWD, DB_HOST, DB_PORT, DB)

factory = make_session_factory(mysql_engine)
port = config.get('global', 'port')
debug_model = int(config.get('global', 'debug_model'))
process_num = int(config.get('global', 'process_num'))
define("port", default=port, help=" server listen port")

settings = {
    'debug': debug_model,