示例#1
0
def main():
    while True:
        faceCon, faceCur = connectDB(db_key)
        bigDataCon, bigDataCur = connectDB(big_data_key)
        lastTime = get_start_time(time_type_key)
        print('lastTime: ', lastTime)
        if not lastTime:
            return

        # 获取最新的更新时间
        now = datetime.now()
        now_time = now.strftime("%Y-%m-%d %H:%M:%S")
        try:
            getFaceInfo(lastTime, faceCon, faceCur, bigDataCon, bigDataCur)
            set_start_time(time_type_key, now_time)
        except Exception as e:
            print(e)
            bigDataCon.rollback()
        else:
            pass
        finally:
            pass

        faceCon.close()
        bigDataCon.close()
        print("begin to sleep 10 seconds")
        print("-----------------------------")
        time.sleep(10)
示例#2
0
def resolveUsernameCollisions(path, dry_run=False):
    """ Resolves all username collisions. New usernames are not disallowed
		and are not duplicates of other unique or duplicate usernames.
		If ran in dry_run mode then prints out all changes instead of updating
		the DB.

		Args:
			- path: String of Path to Database file
			- dry_run: Boolean for Dry Run Mode
	"""
    conn = connectDB(path)
    c = conn.cursor()
    s = conn.cursor()

    unique, duplicates = getUsernames(conn)
    disallowed = getDisallowedNames(conn)

    query = ''' SELECT USERS.id, USERS.username
				FROM  USERS
				JOIN ( SELECT username, COUNT(username) 
					   FROM USERS
					   GROUP BY username
					   HAVING COUNT(username) > 1
					 ) as duplicates
				WHERE USERS.username = duplicates.username
				ORDER BY USERS.username
			'''
    # change query to ORDER BY USERS.id for in order

    for row in c.execute(query):
        iD, name = row[0], row[1]
        counter = duplicates[name]
        if counter > 0:
            # we have seen this duplicate before
            newName = name + str(counter)
            while newName in duplicates or newName in unique or newName in disallowed:
                # check if the New Name would cause another collisions
                counter += 1
                newName = name + str(counter)

            if dry_run:
                print(iD, name + " => " + "[" + newName + "]")
            else:
                updateName(s, iD, newName)

            duplicates[name] = counter + 1

        else:
            # we have seen this duplicate for the first time
            if dry_run:
                print(iD, name + " => " + "[" + name + "]")

            duplicates[name] += 1

    conn.commit()  # commit changes/updates to DB

    s.close()
    c.close()
    conn.close()
示例#3
0
def resolveDisallowedUsers(path, dry_run=False):
    """ Changes usernames matching disallowed words (i.e. grailed, settings)
		into new usernames. New Usernames will not be duplicates or disallowed.
		Dry Run Mode prints out all changes and does not commit them to the DB.
	
		Args:
			- path: String of Path to Database file
			- dry_run: Boolean for Dry Run Mode 
	"""
    conn = connectDB(path)
    c = conn.cursor()
    s = conn.cursor()

    query = ''' SELECT USERS.id, USERS.username
			    FROM USERS
			    JOIN DISALLOWED_USERNAMES
			    WHERE USERS.username = DISALLOWED_USERNAMES.invalid_username
			    ORDER BY USERS.username
			'''
    # change query to ORDER BY USERS.id for in order

    disallowed = getDisallowedNames(
        conn)  # prevents new name being disallowed.
    allowed = getAllowedNames(conn)  # prevents duplicate new names

    duplicates = {}  # hashmap to save time on duplicates

    for row in c.execute(query):
        # Gets all rows from USERS Table with Disallowed usernames
        iD, name = row[0], row[1]
        if name not in duplicates:
            counter = 1
        else:
            counter = duplicates[name]

        newName = name + str(counter)

        while newName in disallowed or newName in allowed:
            # newName cannot be a duplicate or another disallowed sequence
            counter += 1
            newName = name + str(counter)

        duplicates[name] = counter + 1

        if dry_run:
            print(iD, name + ' => ' + '[' + newName + ']')
        else:
            updateName(s, iD, newName)

    c.close()
    s.close()
    conn.commit()
    conn.close()
示例#4
0
def main():
    while True:
        carCon, carCur = connectDB(db_key)
        bigDataCon, bigDataCur = connectDB(big_data_key)
        lastTime = get_start_time(time_type_key)
        print('lastTime: ', lastTime)
        if not lastTime:
            return

        # 获取最新的更新时间
        now = datetime.now()
        now_time = now.strftime("%Y-%m-%d %H:%M:%S")

        getTaxiInfo(lastTime, carCon, carCur, bigDataCon, bigDataCur)
        set_start_time(time_type_key, now_time)

        carCon.close()
        bigDataCon.close()
        print("begin to sleep 10 seconds")
        print("-----------------------------")
        time.sleep(10)
示例#5
0
def findDisallowedUsers(path):
    """ Finds all users with disallowed usernames and print them in
		format: {id} {name}. 

		Args:
			- path: String of Path to Database file

		Returns:
			None
	"""
    conn = connectDB(path)
    c = conn.cursor()
    query = ''' SELECT USERS.id, USERS.username
			    FROM USERS
			    JOIN DISALLOWED_USERNAMES
			    WHERE USERS.username = DISALLOWED_USERNAMES.invalid_username
			    ORDER BY USERS.id 
			'''

    for row in c.execute(query):
        print(row[0], row[1])  # prints id and name

    c.close()
    conn.close()
示例#6
0
def returnDisallowedUsers(path):
    """ Returns all users with disallowed usernames as a list.

		Args:
			- path: String of Path to Database file

		Returns:
			- [row]: List of Tuples in form ({id}, {username})
	"""
    conn = connectDB(path)
    c = conn.cursor()
    query = ''' SELECT USERS.id, USERS.username
			    FROM USERS
			    JOIN DISALLOWED_USERNAMES
			    WHERE USERS.username = DISALLOWED_USERNAMES.invalid_username
			    ORDER BY USERS.id 
			'''

    c.execute(query)
    row = c.fetchall()  # List of Tuples ({id}, {username})
    c.close()
    conn.close()

    return row
示例#7
0
文件: app.py 项目: aerok/iProxy
def beforeRequest():
    g.db = connectDB()