Esempio n. 1
0
def inspection():
    global last_active
    dead = []

    last_active_lock.acquire()
    cur_time = time.time() * 1000  # sec to ms unixtime
    # IMPORTANT: WILL NOT WORK IN PYTHON 3
    # CHANGE TO list(last_active.items()) IF WE SWITCH
    for token, last_active_time in last_active.items():
        if last_active_time < cur_time - FATAL_TIME * 1000:
            dead.append((token, last_active_time))
            del last_active[token]
    last_active_lock.release()

    if len(dead) > 0:
        db = open_db(
            DATABASE_PATH)  # need to open because we're outside app context
        for token, last_active_time in dead:
            info('[PING] %s pronounced dead.', token)
            insert(
                db,
                WebEvent(token=token,
                         hostname=None,
                         time=int(last_active_time + ADJUSTMENT * 1000)))
        db.close()

    t = Timer(INSPECTION_INTERVAL, inspection)
    t.daemon = True
    t.start()
Esempio n. 2
0
    def applying(self, args):
        id = args["id"]
        list = []
        conn = util.open_db()

        with conn.cursor() as cursor:
            #                                           0                1                2               3               4                5
            applying_alba = "select distinct board.no,board.storename,board.start_time,board.end_time,board.local,board.local_sub from board left join getAlba on board.no = getAlba.no where getAlba.id =\'%s\'" %(id)
            cursor.execute(applying_alba)
            rows = cursor.fetchall()

            for row in rows:
                upper = util.get_local_name(cursor, util.get_upper_local(cursor, row[4]))
                lower = util.get_local_name(cursor, row[4])
                local = upper + " " + lower + " " + row[5]

                list.append({
                    "no": row[0],
                    "storename": row[1],
                    "start_time": row[2],
                    "end_time": row[3],
                    "local": local
                })

        util.close_db(conn)
        response = {"applying": list}
        print(response)
        return response
Esempio n. 3
0
    def supporter_list(self, args):
        list = []
        id = args["id"]

        conn = util.open_db()
        with conn.cursor() as cursor:
            get_board_query = "select no, storename from board where id=\'%s\';" %(id)
            cursor.execute(get_board_query)
            rows = cursor.fetchall()

            for row in rows:
                #                                            0                 1                  2                 3
                applyer_query = "select distinct member.id, member.gender, member.local_main, member.phone from member left join getAlba on member.id = getAlba.id where getAlba.no = %d" %(row[0])
                cursor.execute(applyer_query)
                x = cursor.fetchall()

                for y in x:
                    upper = util.get_local_name(cursor, util.get_upper_local(cursor, y[2]))
                    lower = util.get_local_name(cursor, y[2])
                    local = upper + " " + lower

                    list.append({
                        "no": row[0],
                        "storename" : row[1],
                        "id": y[0],
                        "gender": util.get_gender_name(cursor, y[1]),
                        "local":  local,
                        "phone": y[3]
                    })

        response = {"applyer":list}
        util.close_db(conn=conn)
        return response
Esempio n. 4
0
def game_from_fp_database(uid, content_path):
    fp_db = util.open_db()
    c = fp_db.cursor()
    c.execute('SELECT title, platform FROM game WHERE id = ?', (uid, ))
    game = c.fetchone()
    fp_db.close()
    if not game:
        raise ValueError(f'No game found by UUID: {uid}')

    title, platform = game
    return Game(uid, title, platform, content_path)
Esempio n. 5
0
    def recruitment(self, args):
        no = int(args)
        conn = util.open_db()

        with conn.cursor() as cursor:
            recruit_query_in_board = "delete from board where no=%d;" %(no)
            cursor.execute(recruit_query_in_board)
            conn.commit()

            recruit_query_in_getAlba = "delete from board where no=%d;" %(no)
            cursor.execute(recruit_query_in_getAlba)
            conn.commit()
Esempio n. 6
0
    def get_board_info(self, args):
        response = {}
        board_no = int(args["no"])
        conn = util.open_db()

        with conn.cursor() as cursor:
            query = "select * from board where no=%d;" % (board_no)
            cursor.execute(query)
            rows = cursor.fetchall()

            for row in rows:
                job = None
                job_query = "select name from data_code where id=%d;" % (
                    row[7])
                cursor.execute(job_query)
                x = cursor.fetchall()
                for i in x:
                    job = i[0]

                upper_id = util.get_upper_local(cursor, row[10])
                response.update({
                    "no":
                    row[0],
                    "title":
                    row[1],
                    "storename":
                    row[2],
                    "start_time":
                    row[3],
                    "end_time":
                    row[4],
                    "urgency":
                    row[5],
                    "job_condition":
                    row[6],
                    "job":
                    job,
                    "favorable_condition":
                    row[8],
                    "detail":
                    row[9],
                    "address":
                    util.get_local_name(cursor, upper_id) + " " +
                    util.get_local_name(cursor, row[10]) + " " + row[11],
                    "id":
                    row[12],
                    "phone":
                    row[13]
                })

        util.close_db(conn=conn)
        return response
Esempio n. 7
0
    def get_alba(self, request):
        id = request["id"]
        no = request["no"]

        if id == None or no == None:
            return exception.UNLOGINED_USER

        conn = util.open_db()
        with conn.cursor() as cursor:
            query = "insert into getAlba values(\'%s\', %d);" %(id,no)
            cursor.execute(query)
            conn.commit()

        util.close_db(conn=conn)
        return self.GET_ALBA_SUCCESS
Esempio n. 8
0
    def login(self, request):
        id = request["id"]
        pwd = request["pwd"]
        isLoginSuccess = True

        conn = util.open_db()
        with conn.cursor() as cursor:
            query = "select * from member where id = %s and pwd = %s;"
            cursor.execute(query, (id, pwd))
            rows = cursor.fetchall()

            if len(rows) == 0:
                isLoginSuccess = False

        util.close_db(conn=conn)
        response = {"authonization": isLoginSuccess}
        return response
    def get_job_list(self):
        response = {}
        job_list = []

        conn = util.open_db()

        with conn.cursor() as cursor:
            query = "select name from data_code where type=%s;"
            cursor.execute(query, '직종')
            rows = cursor.fetchall()

            for row in rows:
                job_list.append(row[0])

        util.close_db(conn=conn)
        response.update({"job_list": job_list})
        return response
Esempio n. 10
0
    def get_local_list(self, local_name):
        response = {}
        local_list = []
        conn = util.open_db()

        with conn.cursor() as cursor:
            t_local_id = util.get_local_id(cursor=cursor,
                                           local_name=local_name)

            query = "select local_name from local where local_upper=%d;" % (
                t_local_id)
            cursor.execute(query)
            rows = cursor.fetchall()

            for row in rows:
                local_list.append(row[0])

        util.close_db(conn=conn)
        response.update({"local_list": local_list})
        return response
Esempio n. 11
0
    def regist_board(self, request):
        conn = util.open_db()
        job = None
        local = None

        title = request["title"]
        storename = request["storename"]
        start_time = request["start_time"]
        end_time = request["end_time"]
        urgency = int(request["urgency"])
        job_condition = request["job_condition"]
        job_name = request["job"]
        favorable_condition = request["favorable_condition"]
        detail = request["detail"]
        local_name = request["local"]
        local_sub = request["local_sub"]
        id = request["id"]
        phone = request["phone"]

        with conn.cursor() as cursor:
            job_query = "select id from data_code where name=\'%s\' and type='직종';" % (
                job_name)
            cursor.execute(job_query)
            x = cursor.fetchall()
            job = x[0][0]

            local_query = "select local_id from local where local_name=\'%s\';" % (
                local_name)
            cursor.execute(local_query)
            x = cursor.fetchall()
            local = x[0][0]

            query = "insert into board values(null, \'%s\', \'%s\', \'%s\', \'%s\', %d, \'%s\', %d, \'%s\', \'%s\', %d, \'%s\', \'%s\', \'%s\');" % (
                title, storename, start_time, end_time, urgency, job_condition,
                job, favorable_condition, detail, local, local_sub, id, phone)
            cursor.execute(query)
            conn.commit()

        util.close_db(conn=conn)
Esempio n. 12
0
    def select_home_with_unfilter(self, local_name, job_name):
        conn = util.open_db()

        with conn.cursor() as cursor:
            simple_board_list = {}
            query = "select storename, local, local_sub, start_time, end_time, urgency, no from board "
            filter = self.adjust_filter(cursor=cursor,
                                        local_name=local_name,
                                        job_name=job_name)

            if filter != None:
                query = query + filter

            query = query + ";"
            print(query)
            cursor.execute(query)
            rows = cursor.fetchall()

            simple_board_list = self.set_json(cursor, rows, simple_board_list)

        util.close_db(conn=conn)
        return simple_board_list
Esempio n. 13
0
    def sign_up(self, request):
        id = request["id"]
        pwd = request["pwd"]
        name = request["name"]
        gender_name = request["gender"]
        birthday = request["birthday"]
        phone = request["phone"]
        local_main = request["local_main"]
        local_sub = request["local_sub"]
        job_name = request["job"]

        conn = util.open_db()

        with conn.cursor() as cursor:
            if self.check_user_duplication(cursor=cursor,
                                           name=name,
                                           birthday=birthday,
                                           phone=phone):
                util.close_db(conn=conn)
                return exception.REGISTED_USER

            if self.check_id_duplication(cursor, id):
                util.close_db(conn=conn)
                return exception.ID_DUPLCATION

            gender = util.get_gender_code(cursor=cursor,
                                          gender_name=gender_name)
            local = util.get_local_id(cursor=cursor, local_name=local_main)
            job = util.get_job_id(cursor=cursor, job_name=job_name)

            query = "insert into member values(\'%s\', \'%s\', \'%s\', %d, \'%s\', \'%s\', %d, \'%s\', %d);" \
                    %(id, pwd, name, gender, birthday, phone, local, local_sub, job)
            cursor.execute(query)
            conn.commit()

        util.close_db(conn=conn)
        return {"message": "Regist OK"}
Esempio n. 14
0
        gps_long = row[2]

        # gps = '%f,%f' % (gps_lat, gps_long)
        # geocode_result = gmaps.geocode(gps)
        geocode_result = gmaps.reverse_geocode((gps_lat, gps_long))
        for c in geocode_result[0]['address_components']:
            if c['types'][0] == 'administrative_area_level_2':
                county = c['long_name']
                break

        if county:
            c = county.split(' ')
            if c[-1] == 'County':
                county = ' '.join(c[:-1])
            print 'found county: %f,%f %s' % (gps_lat, gps_long, county)
            curs.execute("UPDATE locations SET county=? WHERE id=?",
                         [county, location_id])
        else:
            print 'county not found? %f,%f' % (gps_lat, gps_long)

    conn.commit()
    curs.close()


if __name__ == '__main__':
    db = util.open_db()
    delete_locations(db)
    insert_locations(db)
    # find_counties(db)
    db.close()
Esempio n. 15
0
def run(db, arg):
    fp_db = util.open_db()
    OPERATIONS[arg](db, fp_db)