Ejemplo n.º 1
0
def signup_user(number, name, self_signed=True):
    number = trim_number(number)
    if len(number) != 10:
        raise Exception("Phone Number must have length equal to 10")
    is_present, user = is_user_present(number)
    if not is_present:
        with open_db_connection(True) as cursor:
            cursor.execute(
                'insert into finderdb.dbo.userNode(name,number,self_signed,contacts_synced,created_on, modified_on) '
                'values(?,?,?,?,?,?)', name, number, self_signed, 0,
                datetime.datetime.now(), datetime.datetime.now())
    else:
        if not user["selfSigned"]:
            with open_db_connection(True) as cursor:
                cursor.execute(
                    "update finderdb.dbo.userNode set self_signed=1 , name = ? where number like ?",
                    name, number)
    return {"number": number, "name": name, "selfSigned": True}
Ejemplo n.º 2
0
def is_user_present(username):
    with open_db_connection() as cursor:
        cursor.execute('select name from users where username like ?',
                       username)
        row = cursor.fetchone()
        if row is None:
            return False
        else:
            return True
Ejemplo n.º 3
0
def login_user(user_json):
    with open_db_connection() as cursor:
        row = cursor.execute(
            'select username, name from users where username like ? and password like ?',
            user_json["username"], user_json["password"]).fetchone()
        if row is None:
            raise InvalidLoginDetailsException()
        else:
            return {"name": row[1], "username": row[0]}, 200
Ejemplo n.º 4
0
def insert_review(review):
    if is_user_present(review["username"]):
        with open_db_connection(True) as cursor:
            cursor.execute(
                'insert into reviews(title, description, videoUrl, thumbnailUrl, afLink, username)'
                ' values(?, ?, ?, ?, ?, ?)', review['title'],
                review['description'], review['videoUrl'],
                review['thumbnailUrl'], review['afLink'], review['username'])
        return review, 200
    else:
        raise UserNotFoundException()
Ejemplo n.º 5
0
def is_user_present(number):
    number = trim_number(number)
    with open_db_connection() as cursor:
        cursor.execute(
            'select user_id,name,number,self_signed from finderdb.dbo.UserNode where number like ?',
            number)
        row = cursor.fetchone()
        if row is None:
            return False, None
        return True, {
            'userId': row.user_id,
            'name': row.name,
            'number': row.number,
            'selfSigned': row.self_signed
        }
Ejemplo n.º 6
0
def get_common_contacts_of_length_1(source_number, destination_number):
    results = []
    with open_db_connection() as cursor:
        cursor.execute(
            "select node2.number as number, node2.name as name from UserNode node1, knowsEdge edge1, "
            "knowsEdge edge2, UserNode node2, UserNode node3 Where match(node1-(edge1)->node2-("
            "edge2)->node3) and node1.number like ? and node2.number not like ? and node3.number like ?",
            source_number, source_number, destination_number)
        rows = cursor.fetchall()
        for row in rows:
            edges = list()
            # edges.append(get_edges(source_number, source_number, 0))
            edges.append(get_edges(row.number, row.name, 1))
            # edges.append(get_edges(destination_number, destination_number, 2))
            results.append(
                get_result_object(source_number, destination_number, edges))
    return results
Ejemplo n.º 7
0
def signup_user(user_json):
    with open_db_connection(True) as cursor:
        query = "If EXISTS ( " + generate_query(
            "select", "users", ["username"],
            [user_json["username"]]) + " )BEGIN " + generate_query(
                "select", "users", ["username"],
                [user_json["username"]]) + " END ELSE BEGIN " + generate_query(
                    "insert", "users", ["name", "username", "password"], [
                        user_json["name"], user_json["username"],
                        user_json["password"]
                    ]) + " END"
        print query
        row = cursor.execute(query)
        if row.rowcount == -1:
            raise UserAlreadyExistException()
        else:
            del user_json["password"]
            return user_json, 200
Ejemplo n.º 8
0
def insert_user_util(name, number, self_signed):
    with open_db_connection(True) as cursor:
        cursor.execute(
            'insert into finderdb.dbo.userNode(name,number,self_signed) values(?,?,?)',
            name, number, self_signed)
Ejemplo n.º 9
0
def execute_query(query):
    with open_db_connection(True) as cursor:
        cursor.execute(query)
Ejemplo n.º 10
0
import sqlalchemy
import math

from sqlalchemy.types import Integer, Text, Boolean, DateTime, NVARCHAR, Float

import datetime
from os import sys

from ast import literal_eval

import settings
import request_data
import database

# APP_INFO_TABLE = 'dirty_app_info'
engine, conn = database.open_db_connection()


raw_data_dtype={
 'type': NVARCHAR(256),
 'game_name': NVARCHAR(256),
 'steam_appid': Integer,
 'required_age': Integer,
 'is_free': Boolean,
 'short_description': Text,
 'supported_languages': Text,
 'website': Text,
 'developers': Text,
 'publishers': Text,
 # 'dlc': Text,
 'controller_support': Boolean,