Exemplo n.º 1
0
def converter(c, f):
    """Connect c to f with constraints to convert from Celsius to Fahrenheit."""
    u, v, w, x, y = [connector() for _ in range(5)]
    multiplier(c, w, u)
    multiplier(v, x, u)
    adder(v, y, f)
    constant(w, 9)
    constant(x, 5)
    constant(y, 32)
Exemplo n.º 2
0
def thread(pid, socket):
    t = threading.currentThread()
    db_connection = db.DB(config.db_user, config.db_pass, config.db_host,
                          config.db_instance)
    bashi = connector.connector(pid, t.getName(), db_connection)
    while True:
        client, address = socket.accept()
        client.send(bashi.check_data(client.recv(4096)))
        client.close()
Exemplo n.º 3
0
    def update (self, retString = False):
        
        myConn = connector()        
        query = "INSERT INTO " + self.nome_tabela + " (order_type,price,num_coins,coin_type,date_creation) values (" + repr(self.order_type) + "," + repr(self.price) + "," + repr(self.num_coins) + "," + repr(self.coin_type) + ",TIMESTAMP '" + self.date_creation.strftime('%Y-%m-%d %H:%M:%S') + "');"

        if not retString:
            myConn.crud(query)
        else:
            return query
Exemplo n.º 4
0
 def __init__(self, config):
     if not self.getlock():
         exit()
     self.config = config
     self.headers = {'User-Agent': self.config['Headers']['headers']}
     self.connector = connector(config)
     self.downloader = downloader(self.headers,
                                  self.connector,
                                  dataDir=self.config['Main']['Data'],
                                  numProcs=4)
Exemplo n.º 5
0
    def get_open_order(self, coin_type , order_type , num_coins, price ):
        query = "select * from " + self.nome_tabela + " where "
        query += "coin_type = '" + coin_type + "'"
        query += " and order_type = '" + order_type + "'"
        query += " and price = '" + repr(price) + "'"
        query += " and num_coins = '" + repr(num_coins) + "'"
        query += " and date_not_avaible is null "

        myConn = connector()
        return myConn.execute(query)
Exemplo n.º 6
0
def create_keygen(details):
    conn=connector()
    login_datas=tuple(details.values())
    import secrets
    key=secrets.token_urlsafe(16)
    query="insert into loggeduser values('{}','{}')".format(login_datas[0],key)
    connect=conn.cursor()
    connect.execute(query)
    conn.commit()
    conn.close()
    return key
Exemplo n.º 7
0
def add_user(userid):
    try:
        conn=connector()
        status={'status':False}
        query="insert into users values {}".format(tuple(userid.values())) 
        connect=conn.cursor()
        connect.execute(query)
        conn.commit()
        conn.close()
        status['status']=True
    except:
        status['status']=False
    finally:
        return status
Exemplo n.º 8
0
def loginCheck(user_id, password):
    con = connector.connector()
    cursor = con.cursor()
    query = """select user_type from tbl_users where user_id = \'""" + user_id + """\' and user_pass = \'""" + password + """\'"""
    cursor.execute(query)
    chk = False
    for row in cursor:
        chk = True
    err = {}
    if (chk):
        err['er_no'] = row[0]
        err['er_msg'] = 'Login Successful'
    else:
        err['er_no'] = -1
        err['er_msg'] = 'Login Failed. Due to invalid user_id or password'
    return err
Exemplo n.º 9
0
    def close_old_orders(self, array_open_orders):


        if len(array_open_orders) == 0:
            return

        placeholder = "?"
        placeholders = ", ".join(placeholder for unsed in array_open_orders)
        
        now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 
        
        query = "UPDATE " + self.nome_tabela + " set date_not_avaible = "
        query += "TIMESTAMP '" + now
        query += "' where date_not_avaible is NULL and coin_type = '" + self.coin_type  + "' and oid not in (%s)"
        new_query = query % placeholders

        for i in array_open_orders:
            new_query = new_query.replace("?",repr(i),1)

        myConn = connector()
        myConn.crud(new_query)
Exemplo n.º 10
0
    def __init__(self, string, coin_type = "b", to_update = True):
        
        arrayList = []

        totalQuery = ""

        d = json.loads(string);
        for i in d['asks']:
            self.price= i[0]
            self.num_coins = i[1]
            self.order_type =  'a'
            self.coin_type = coin_type

            dic = self.get_open_order(self.coin_type,self.order_type,self.num_coins,self.price)
            boolExist = len(dic) != 0
            if to_update == True and not boolExist:
                totalQuery += self.update(True)
            elif boolExist:
                arrayList.append(dic[0][0])
        
            
        for i in d['bids']:
            self.price= i[0]
            self.num_coins = i[1]
            self.order_type =  'b'
            self.coin_type = coin_type

            dic = self.get_open_order(self.coin_type,self.order_type,self.num_coins,self.price)
            boolExist = len(dic) != 0
            if to_update == True and not boolExist:
                totalQuery += self.update(True)
            elif boolExist:
                arrayList.append(dic[0][0])
        
        self.close_old_orders(arrayList)

        if len(totalQuery) > 0:
            myConn = connector()
            myConn.crud(totalQuery)
Exemplo n.º 11
0
def establish_connection(
):  #Setup WMI Connection, Get SID, UserPath and default WINDIR
    log_buddy.write_log("Execution", "ESTABLISHING REMOTE CONNECTION..")
    global rem_con, user_sid, user_path, system_root, base_user_dir, user_appdata_dir, user_local_appdata_dir, user_roaming_appdata_dir, win_dir, win_def
    print("\nBuilding Remote Connection..\n")
    try:
        if args.password is None:
            log_buddy.write_log("Execution", "PROMPTING FOR PASSWORD")
            password = getpass.getpass(prompt="Password for " +
                                       elevated_username + ":")
            log_buddy.write_log("Execution", "RECEIVED PASSWORD FROM USER")
            log_buddy.write_log("Execution",
                                "CREATING OBJECT Connector.Connector")
            rem_con = connector.connector(target, elevated_username, password,
                                          user_target, domain)
        else:
            log_buddy.write_log("Execution", "PASSWORD PROVIDED AT STARTUP")
            rem_con = connector.connector(target, elevated_username,
                                          elevated_password, user_target,
                                          domain)
    except:
        print("CRITICAL ERROR Instantiating Connector.Connector")
        log_buddy.write_log(
            "Error", "CRITICAL ERROR Instantiating Connector.Connector")
        #print(traceback.print_exc(sys.exc_info()))
        tb = traceback.format_exc()
        log_buddy.write_log("Error", str(tb))
        exit(0)
    try:
        rem_con.create_session()
    except:
        print(
            "CRITICAL ERROR Initializing WMI Connection..does your credential have Remote Access?"
        )
        log_buddy.write_log(
            "Error",
            "CRITICAL ERROR Initializing WMI Connection..does your credential have Remote Access?"
        )
        tb = traceback.format_exc()
        log_buddy.write_log("Error", str(tb))
        exit(0)
    try:  #Prepare some paths for replacement in artifacts
        user_sid, user_path = rem_con.get_sid()
        system_root = user_path[0]
        base_user_dir = system_root + ":\\Users\\" + user_target
        user_appdata_dir = base_user_dir + "\\" + "AppData"
        user_local_appdata_dir = user_appdata_dir + "\\" + "Local"
        user_temp_dir = user_local_appdata_dir + "\\" + "Temp"
        user_roaming_appdata_dir = user_appdata_dir + "\\" + "Roaming"
        config.user_sid = user_sid
        config.user_path = user_path
        config.system_root = system_root
        config.base_user_dir = base_user_dir
        config.user_appdata_dir = user_appdata_dir
        config.user_local_appdata_dir = user_local_appdata_dir
        config.user_roaming_appdata_dir = user_roaming_appdata_dir
        config.user_temp_dir = user_temp_dir
        win_def = 0
        config.win_def = win_def
        log_buddy.write_log("Execution", "FOUND USER SID: " + user_sid)
        log_buddy.write_log("Execution", "FOUND USER PATH: " + user_path)
        log_buddy.write_log("Execution", "CALCULATED USER DIR: " + user_sid)
        log_buddy.write_log("Execution",
                            "CALCULATED USER APPDATA DIR: " + user_appdata_dir)
        log_buddy.write_log("Execution",
                            "CALCULATED USER APPDATA DIR: " + user_appdata_dir)
    except:  #NEED SID for real functionality
        print("CRITICAL ERROR Getting Target User SID..")
        log_buddy.write_log("Error",
                            "CRITICAL ERROR Getting Target User SID..")
        #print(traceback.print_exc(sys.exc_info()))
        tb = traceback.format_exc()
        log_buddy.write_log("Error", str(tb))
        exit(0)
    try:
        log_buddy.write_log("Execution",
                            "CHECKING FOR WINDIR DEFAULT LOCATION")
        win_dir = rem_con.get_windir()
        config.win_dir = win_dir
        print("Found WINDIR : " + win_dir)
        log_buddy.write_log("Execution", "FOUND DEFAULT WINDIR: " + win_dir)
    except:
        win_def = 1
        config.win_def = win_def
        print("Failed Finding default WINDIR, using " + system_root +
              ":\Windows")
        print("SOFT ERROR Finding default WINDIR, using " + system_root +
              ":\Windows")
        log_buddy.write_log(
            "Error", "SOFT ERROR Finding default WINDIR, using " +
            system_root + ":\Windows")
        tb = traceback.format_exc()
        log_buddy.write_log("Error", str(tb))
    try:
        print("Creating TEMPARTIFACT Directory on " + target)
        dir = system_root + ":\\Users\\" + elevated_username + "\TEMPARTIFACTS"
        rv = rem_con.make_dir(dir)
        if rv == 0:
            log_buddy.write_log(
                "Execution", "Successfully Created Remote TEMPARTIFACT DIR")
        else:
            print("ERROR CREATING TEMPARTIFACTS DIR")
    except:
        print("CRITICAL ERROR Creating TEMPARTIFACT DIR")
        log_buddy.write_log("Error",
                            "CRITICAL ERROR Creating TEMPARTIFACT DIR")
        tb = traceback.format_exc()
        log_buddy.write_log("Error", str(tb))
        exit(0)
    try:
        print("Mapping Network Drive..")
        result = rem_con.connect_drive()
        #print(result)
        log_buddy.write_log("Execution", target + " SUCCESSFULLY MAPPED")
        #if ("The command completed successfully." in str(result)): #RE DO THIS SECTION
        #    pass
        #else:
        #    print("CRITICAL ERROR Mapping Network Drive")
        #    log_buddy.write_log("Error","CRITICAL ERROR Mapping Network Drive")
        #    tb = traceback.format_exc()
        #    log_buddy.write_log("Error",str(tb))
        #    exit(0)
    except:
        print("CRITICAL ERROR Mapping Network Drive")
        log_buddy.write_log("Error", "CRITICAL ERROR Mapping Network Drive")
        tb = traceback.format_exc()
        log_buddy.write_log("Error", str(tb))
        exit(0)
Exemplo n.º 12
0
def check_aadhar(aadharid):
    conn=connector()
    query="select * from users where aadhar='{}'".format(aadharid)
    connect=conn.cursor()
    return connect.execute(query)
Exemplo n.º 13
0
def login(details):
    conn=connector()
    login_datas=tuple(details.values())
    query="select * from users where email='{}' and password='******'".format(login_datas[0],login_datas[1])
    connect=conn.cursor()
    return connect.execute(query)
Exemplo n.º 14
0
 def update (self):
     
     myConn = connector()        
     query = "INSERT INTO " + self.nome_tabela + " (high,low,vol,last,buy,sell,date) values (" + repr(self.high) + "," + repr(self.low) + "," + repr(self.vol) + "," + repr(self.last) + "," + repr(self.buy) + "," + repr(self.sell) + ",TIMESTAMP '" + datetime.datetime.fromtimestamp(self.date).strftime('%Y-%m-%d %H:%M:%S') + "');"
     myConn.crud(query);
Exemplo n.º 15
0
def converter(p, v, n, t):
    u = connector()
    multiplier(p, v, u)
    multiplier(n, t, u)
Exemplo n.º 16
0
from connector import connector
from constraint import adder, multiplier, constant

def converter(c, f):
    """Connect c to f with constraints to convert from Celsius to Fahrenheit."""
    u, v, w, x, y = [connector() for _ in range(5)]
    multiplier(c, w, u)
    multiplier(v, x, u)
    adder(v, y, f)
    constant(w, 9)
    constant(x, 5)
    constant(y, 32)

celsius = connector('Celsius')
fahrenheit = connector('Fahreheit')
converter(celsius, fahrenheit)
celsius['set_val']('user', 25)
fahrenheit['set_val']('user', 212)
celsius['forget']('user')
fahrenheit['set_val']('user', 212)
Exemplo n.º 17
0
 def initConnector(self, scalper):
     user = self.users.find_one({"user": scalper['user']})
     client = connector(user['api'], user['secret'], scalper['symbol'])
     return client
Exemplo n.º 18
0
from connector import connector
from constraint import multiplier


def converter(p, v, n, t):
    u = connector()
    multiplier(p, v, u)
    multiplier(n, t, u)


p = connector('p')
v = connector('v')
n = connector('n')
t = connector('t')
converter(p, v, n, t)
p['set_val']('user', 25)
v['set_val']('user', 30)
n['set_val']('user', 35)
p['forget']('user')
v['forget']('user')
n['forget']('user')
Exemplo n.º 19
0
 def initConnector(self, scalper):
     client = connector(self.api_key, self.secret_key, scalper['symbol'])
     return client
Exemplo n.º 20
0
def check_email(emailid):
    conn=connector()
    query="select * from users where email='{}'".format(emailid)
    connect=conn.cursor()
    return connect.execute(query)    
Exemplo n.º 21
0
 def update (self):
     
     myConn = connector()        
     query = "INSERT INTO " + self.nome_tabela + " (tid,price,amount,type,date,coin_type) values (" + repr(self.trade_id) + "," + repr(self.price) + "," + repr(self.amount) + "," + repr(self.type_trade) + ",TIMESTAMP '" + datetime.datetime.fromtimestamp(self.date).strftime('%Y-%m-%d %H:%M:%S') + "','" + self.coin_type  + "');"
     myConn.crud(query);
Exemplo n.º 22
0
 def __init__(self, booksCallback=None):
     self.database = connector.connector(booksCallback)
     self.scraper = scraper.scraper()
Exemplo n.º 23
0
 def exists (self):
     
     query = "select * from " + self.nome_tabela + " where tid = '" + repr(self.trade_id) + "' and coin_type = '" + self.coin_type  + "';"
     myConn = connector()
     d = myConn.execute(query)
     return len(d) > 0
Exemplo n.º 24
0
    return: new_results where the objects have been re-ranked using category similarity scores as well.
    '''

    def rerank(self, results, user):
        cat = self.collect_categories(results)
        u_cv = self.create_user_cv(user, cat)
        a_cvs = self.create_all_article_cvs(results, cat)
        cosine_scores = self.cosine_sim(u_cv, a_cvs)
        for r in results:
            r['_score'] = self.alpha * r['_score'] + (
                1 - self.alpha) * cosine_scores[r['_id']]
        return results


if __name__ == '__main__':
    user = {'categories': ['Auto racing']}
    comp = Comparator(0.6)
    conn = connector(hostname='http://localhost:9200', index_name='articles')
    results = conn.search('australia')
    for d in results:
        del d['_source']['text']
    print('Original:')
    for d in results:
        print(d['_source']['title'], d['_score'])

    new_results = comp.rerank(results, user)
    new_results.sort(key=lambda x: x['_score'], reverse=True)
    print('New:')
    for d in new_results:
        print(d['_source']['title'], d['_score'])
Exemplo n.º 25
0
print('Hello, my master!\n')

import connector

spider=connector.connector()
info_msg = 'You seaching \"{0}\" in {1} in deep level {2}'.format(
    spider.data['What'], spider.data['Where'].keys()[0], spider.data['How_deep'])
print(info_msg)
spider.deep_search()
print('I\'m quiting')