Example #1
0
def request_url_ls_services(ls=None):

    sql = """
        SELECT id, name, image_url, type, code_in_billing 
        FROM atom_services
        WHERE type LIKE '{}'
        ORDER BY id ASC"""

    array = list()
    standart = AtomDB().execute(sql.format('standart'))
    for x in range(randint(1, 5)):
        name = standart[x].get('name')
        image = standart[x].get('image_url')
        array.append(Service().element(name, 'standart', True, image, None))

    smart_home = AtomDB().execute(sql.format('smart_home'))
    for x in range(len(smart_home)):
        name = smart_home[x].get('name')
        image = smart_home[x].get('image_url')
        billing = smart_home[x].get('code_in_billing')
        array.append(Service().element(name, 'smart_home', True, image,
                                       billing))

    success = {"result": True, "data": array}

    return choice([
        (json(success), 200), (json(success), 200), (error(401), 401)
    ])  # if randint(0, 10) != 5 else (error(9050), 500)
Example #2
0
    def places(self, longitude, latitude, distance):
        """
        return [{}]
        """
        sql = ''' SELECT zip, address, email, work_phones, work_times
                    , ST_AsGeoJSON(point) AS coord
                    , ST_Distance(point, ST_MakePoint({0}, {1})::geography) AS distance 
                    FROM atom_points 
                    WHERE ST_DWithin(point, ST_MakePoint({0}, {1})::geography, {2}) 
                    ORDER BY distance ASC'''.format(longitude, latitude, distance)

        content = []
        for item in AtomDB().execute(sql):
            data = {
                'INDEKS': item.get('zip'),
                'ADDRESS': item.get('address'),
                'EMAIL': item.get('email'),
                'TELEFON': item.get('work_phones'),
                'REZHIM_RABOTY': item.get('work_times'),
                'DOLGOTA': json.loads(item.get('coord')).get('coordinates')[0],
                'SHIROTA': json.loads(item.get('coord')).get('coordinates')[1]
            }
            content.append(data)

        return content
Example #3
0
def request_url_ls():

    token = request.headers.get('token')
    if token in ['', None]:
        return (error(4010), 500)

    sql = f"""
        SELECT login, ls 
        FROM atom_users
        WHERE token LIKE '{token}'"""
    ls = AtomDB().execute_first(sql)

    array = list()
    for i in range(len(ls.get('ls')) if ls is not None else randint(1, 8)):
        array.append(LS().object(1 if i == 0 else 0))

    success = {"result": True, "data": array}

    return (json(success), 200) if randint(0, 20) != 5 else (error(7050), 500)
Example #4
0
def request_auth():
    # {
    #     "login": "******",
    #     "password": "******"
    # }

    login = request.get_json().get('login')
    sql = f"""
        SELECT login, token 
        FROM atom_users
        WHERE login LIKE '{login}'"""
    user = AtomDB().execute_first(sql)

    success = {
        "result": True,
        "token": uuid4().hex if user is None else user.get('token')
    }

    return (json(success), 200) if randint(0, 20) != 5 else (error(401), 500)
Example #5
0
def request_user():

    token = request.headers.get("token")
    sql = f"""
        SELECT login, token 
        FROM atom_users
        WHERE token LIKE '{token}'"""
    user = AtomDB().execute_first(sql)

    phone = '00000000000'
    email = 'xxxxxxxxxxx'

    if user:
        phone = user.get('phone')
        email = user.get('email')

    success = {
        "result": True,
        "data": {
            "id": 23,
            "account_type_id": None,
            "billing_account_id": None,
            "account_login": phone,
            "account_email": email,
            "account_mphone": phone,
            "account_password": "******",
            "account_status": None,
            "flag_sync": None,
            "remember_token": "b2ce18bf8089edf8d5872dc5bbb0bcec",
            "created_at": "2018-10-11T09:41:17.000",
            "updated_at": "2018-11-25T11:59:48.000",
            "account_pdn": None,
            "account_notify": None
        }
    }

    return (json(success), 200) if randint(0, 20) != 5 else (error(4020), 500)
Example #6
0
def error(errorCode):

    sql = """
        SELECT error_code, error_text 
        FROM atom_errors
        WHERE error_code = {}
    """.format(errorCode)
    ex = AtomDB().execute(sql)

    path = f'\n\n-> {request.method} {request.path}'
    error = {
        "result": False,
        "errorCode": ex[0].get('error_code') if len(ex) > 0 else 0,
        "errorText":
        f'{ex[0].get("error_text")}{path}' if len(ex) > 0 else None,
    }
    return json(error)
Example #7
0
def request_url_camera(ls=None):

    sql = """
        SELECT name, video_url
        FROM atom_video"""

    array = list()
    dbarr = AtomDB().execute(sql)
    if len(dbarr) > 0:
        for x in range(len(dbarr)):
            item = {
                "link": dbarr[x].get('video_url'),
                "place": dbarr[x].get('name')
            }
            array.append(item)

    success = {"result": True, "data": array}

    return (json(success), 200) if randint(0, 10) != 5 else (error(9040), 500)
Example #8
0
def request_url_ls_service_id(ls=None, id=None):

    sql = """
        SELECT name, image_url
        FROM atom_forms    
    """

    array = list()
    dbarr = AtomDB().execute(sql)
    for x in range(randint(0, len(dbarr))):
        name = dbarr[x].get('name')
        image = dbarr[x].get('image_url')
        array.append(Form().form(name, image, randint(3, 10)))

    for x in range(randint(0, 15)):
        array.append(Form().form('Форма с номером {}'.format(x), None,
                                 randint(3, 10)))

    success = {"result": True, "data": array}

    return (json(success), 200) if randint(0, 10) != 5 else (error(9050), 500)