def insert_new_tag(tid): # 一般以16进制八位字符串给出 tid = int('0x{}'.format(tid), 16) # 首先获取所有地址集合,计算集合的MEX值作为新地址 db = conn() c = db.cursor() rs = c.execute('SELECT addr FROM tag').fetchall() a = set() for row in rs: a.add(row[0]) addr = -1 for i in range(TAG_ADDR_OFFSET, TAG_ADDR_MAX + 1): if i not in a: addr = i break db.close() # 然后插入 db = conn() c = db.cursor() c.execute('INSERT INTO tag (tid, addr, is_active) VALUES (?, ?, 0)', (tid, addr)).fetchall() db.commit() db.close() # 更改新标签地址 pipe.call('3 {}'.format(addr)) # 发出确认声音 Process(target=handshake, args=(addr, )).start() return True
def periodic_check(): while True: time.sleep(10) # 首先获取服务器端基站是否激活,如果没激活则待检查集合为空 db = conn() c = db.cursor() rs = c.execute('SELECT v FROM config WHERE k = "active" LIMIT 1') base_active = rs.fetchone()[0] db.close() # 获取所有需要被检查的TAG,以及所有TAG tags_need_check = set() tags = [] db = conn() c = db.cursor() rs = c.execute('SELECT tid, is_active, is_online FROM tag') for item in rs.fetchall(): # 只有当基站和TAG都被激活,并且TAG在线的情况下,才需要被检查 if base_active and item[1] and item[2]: tags_need_check.add(item[0]) # 添加进tags tags.append(item[0]) db.close() # 获取所有当前在线的TAG db = conn() c = db.cursor() cur = int(time.time()) rs = c.execute('SELECT tid FROM record WHERE record_time >= ?', (cur - 10, )) available_tags = set(x[0] for x in rs.fetchall()) db.close() # 逐个设置TAG是否online db = conn() c = db.cursor() for tag in tags: is_online = 1 if tag in available_tags else 0 c.execute('UPDATE tag SET is_online = ? WHERE tid = ?', (is_online, tag)) db.commit() db.close() # 计算所有TAG与可用TAG的差集 dead_tags = tags_need_check - available_tags # 如果差集不为空,向推送给服务器 if len(dead_tags) == 0: continue requests.post( URL_DEAD_TAGS, { 'dead_tags': json.dumps( list('{0:08X}'.format(tag).upper() for tag in dead_tags)), 'base_id': BASE_ID, 'key': KEY_DEAD_TAGS })
def sale(self): theStartPage = self.itemStart.get() theEndPage = self.itemEnd.get() WhatPosition = self.number.get() try: showinfo(title='状态', message='点击开始下载') a = load.go(WhatPosition, theStartPage, theEndPage) if a == 'ok': whentime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) try: db.conn(WhatPosition, whentime) except: showinfo(title='错误', message='数据库错误') showinfo(title='状态', message='下载完成') self.root.destroy() root = Tk() root.title('小程序') # AnalysisG(root,'C:\\Users\\Dell\\Desktop\\爬虫代码\\php.xlsx') root.mainloop() else: showinfo(title='错误', message='您使用次数过多,ip暂时被停封,不用担心,换个ip或者等待一段时间就可以') except: showinfo(title='错误', message='请正确输入起始页与终止页')
def technology(self): theStartPage = self.itemStart.get() theEndPage = self.itemEnd.get() WhatPosition = self.number.get() try: showinfo(title='状态', message='点击开始下载') filename = os.path.abspath('') + '\\' + WhatPosition + '.xlsx' a = load.go(WhatPosition, theStartPage, theEndPage) if a == 'ok': whentime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) try: db.conn(WhatPosition, whentime) except: showinfo(title='错误', message='数据库错误') showinfo(title='状态', message='下载完成') self.root.destroy() root = Tk() root.title('小程序') AnalysisG(root, filename) root.mainloop() else: showinfo(title='错误', message='您使用次数过多,ip暂时被停封,不用担心,换个ip或者等待一段时间就可以') except: showinfo(title='错误', message='请正确输入起始页与终止页')
def create_room(self, direction): c = db.conn().cursor() # see if room already exists new_room_id = self.room_exists(direction) #if room does not exist, create it if new_room_id == 0: coords = self.get_coords_from_dir(direction) c.execute('insert into rooms (title, desc, x, y, z) values ("default title", "default desc", ?, ?, ?)', coords) new_room_id = c.lastrowid else: print "A room already exists at this map location, using existing room." if self.door_exists(direction): print "An exit already exists in that direction!" return # create the door to the room c.execute('insert into doors (src_room_id, dest_room_id, dir) values (?,?,?)', (self.current_room.room_id, new_room_id, direction)) #create the door from the new room back to this one c.execute('insert into doors (src_room_id, dest_room_id, dir) values (?,?,?)', (new_room_id, self.current_room.room_id, opposite_dir[direction])) db.conn().commit() # refresh the current room self.current_room = Room(self.current_room.room_id) print "Room created to the " + direction
def init(timestamp = None): global nodes, edges if nodes == None : nodes = 'nodes_' + timestamp if edges == None : edges = 'edges_' + timestamp nodes = Nodes(db.metadata(), db.conn(), nodes) edges = Edges(db.metadata(), db.conn(), edges) nodes.edges = edges
def init(timestamp=None): global current, next if not current: current = "swap_current_" + timestamp if not next: next = "swap_next_" + timestamp current = Stack(db.metadata(), db.conn(), current) next = Stack(db.metadata(), db.conn(), next)
def getColumns(tableId): conn = db.conn() cursor = conn.cursor() cursor.execute(get_table_columns_cmd, [make_table_name(tableId)]) return [i[0] for i in cursor.fetchall()]
def modifyColumn(tableId, oldCol, newCol, userId): if oldCol == 'id': abort(400, 'Cannot remove this column') cols = getColumns(tableId) if oldCol not in cols: abort(400, 'Column not found') cmd = modify_column_cmd.format(make_table_name(tableId), oldCol, newCol) conn = db.conn() cursor = conn.cursor() cursor.execute(cmd) cursor.execute(check_tracking_cmd, [tableId]) if cursor.fetchall() == tracking_disabled: return args = [ tableId, 0, "Column '" + oldCol + "'", "Column '" + newCol + "'", userId, time(), 6 ] cursor.execute(insert_history_cmd, args) conn.commit()
def removeColumn(tableId, name, userId): if name == 'id': abort(400, 'Cannot remove this column') remove = remove_column_cmd.format(make_table_name(tableId), name) conn = db.conn() cursor = conn.cursor() try: cursor.execute(remove) cursor.execute(check_tracking_cmd, [tableId]) if cursor.fetchall() == tracking_disabled: return args = [tableId, 0, "Column '" + name + "'", "", userId, time(), 5] cursor.execute(insert_history_cmd, args) conn.commit() except MySQLdb.OperationalError as err: print(err) abort(400, 'This column does not exist') except Exception as e: print(e) abort(500, 'Error in remove column')
def create(data): conn = db.conn() cursor = conn.cursor() create_cmd = '''INSERT INTO Event (eventName, startTime, endTime, location, description, reminder, reminderTime) VALUES (%s, %s, %s, %s, %s, %s, %s);''' table_cmd = '''CREATE TABLE event_%s ( userId int(11) NOT NULL UNIQUE PRIMARY KEY''' check_in_table_cmd = '''CREATE TABLE check_in_event_{} (userId int(11) NOT NULL UNIQUE PRIMARY KEY);''' args = [ data['name'], data['startTime'], data['endTime'], data['location'], data['desc'], int(data['reminder']), int(data['reminderTime']) ] cursor.execute(create_cmd, args) table_id = cursor.lastrowid args = [cursor.lastrowid] for col in data['questions']: table_cmd += ', `%s` varchar(256)' args.append(col) table_cmd += ');' cursor.execute(table_cmd, args) cursor.execute(check_in_table_cmd.format(table_id)) conn.commit() return True
def details(id, userId): conn = db.conn() cursor = conn.cursor() select_cmd = 'SELECT * FROM Event WHERE eventId = %s;' rsvp_cmd = 'SELECT * FROM event_%s WHERE userId = %s;' cursor.execute(select_cmd, [id]) res = cursor.fetchone() if res is None: abort(400, "Event does not exist") cursor.execute(rsvp_cmd, [int(id), userId]) rsvp = {} rsvp['questions'] = [] ret = cursor.fetchone() if ret == None: rsvp['response'] = False for i in range(1, len(cursor.description)): rsvp['questions'].append(cursor.description[i][0].replace( '\'', '')) else: rsvp['response'] = True rsvp['answers'] = [] for i in range(1, len(cursor.description)): rsvp['questions'].append(cursor.description[i][0].replace( '\'', '')) rsvp['answers'].append(ret[i]) return res, rsvp
def on_delete(self, req, resp, object_name, pk): wait_for_schema() check_table(object_name) check_pk(object_name, pk) with db.conn() as conn: delete_table_row(conn, object_name, pk) resp.status = falcon.HTTP_204
def run(self): publisher = ZmqPublisher.get_instance() call(['youtube-dl', '-f', 'mp4', '-o', self.location, self.uri]) with db.conn(settings['database']) as conn: update(conn, self.asset_id, {'asset_id': self.asset_id, 'is_processing': 0}) publisher.send_to_ws_server(self.asset_id)
def get_all_user_messages(user_id): conn = db.conn() cursor = conn.cursor() empty_dict = {} try: cursor.execute(get_user_groups, [user_id, user_id]) out = cursor.fetchall() group_set = set() return_dict = {} for pair in out: if pair[0] is not user_id: group_set.add(pair[0]) else: group_set.add(pair[0]) for user in pair: if str(user) == user_id: continue cursor.execute(get_to_messages_in_group, [user_id, user]) to_messages = cursor.fetchall() cursor.execute(get_from_messages_in_group, [user, user_id]) from_messages = cursor.fetchall() single_dict = to_messages + from_messages sorted_tuple = sorted(single_dict, key=lambda x: x[0]) name = (get_user_name(user), user) return_dict[name] = sorted_tuple print(return_dict) return return_dict except: return empty_dict
def basic_search(): conn = db.conn() cursor = conn.cursor() cursor.execute(basic_search_cmd) out = cursor.fetchall() return out
def get_user_tickets(id): conn = db.conn() cursor = conn.cursor() cursor.execute(get_user_tickets_cmd, [id]) out = cursor.fetchall() print(out) return out
def get_user_id(email): conn = db.conn() cursor = conn.cursor() cursor.execute(email_cmd, [email]) out = cursor.fetchall() return str(out[0][0])
def get_user_name(id): conn = db.conn() cursor = conn.cursor() cursor.execute(user_name_cmd, [id]) out = cursor.fetchall() name = out[0][0] + " " + out[0][1] return name
def is_active(): db = conn() c = db.cursor() rs = c.execute('SELECT v FROM config WHERE k = "active" LIMIT 1') res = rs.fetchone()[0] == 'true' db.close() return res
def run(db_filename): #connect to the DB or create emtpy global conn x = [] conn = db.conn(db_filename) sensors = db.get_sensors(conn) for s in sensors: x.append( threading.Thread(target=sensor.sensor_ping, kwargs={ 'host': s[3], 'count': 1, 'timeout': 1, 'interval': 0.2, 'sleep_time': 1, 'output': False, 'log_db': True, 'db_name': db_filename, 'sensor_id': s[0] })) for i in x: i.start() for i in x: i.join() conn.close()
def get_detailed_med(id): conn = db.conn() cursor = conn.cursor() cursor.execute(get_detailed_med_cmd, [id]) info = cursor.fetchall() return info
def test_reset_password_full(self): user = self.fake_user_object() response = self.post('/user/forgotPassword', dict(email=user['email'])) user['id'] = auth.jwt.check_jwt(user['jwt']) with app.app_context() as context: sql_stmt = '''select link from Links where userId=%s;''' conn = db.conn() cursor = conn.cursor() cursor.execute(sql_stmt, [user['id']]) token = cursor.fetchone()[0] response = self.post( '/user/resetPassword', dict(email=user['email'], newPassword='******', token=token)) self.assertEqual(response.status_code, 200) response = self.post( '/user/login', dict(email=user['email'], password='******')) self.assertEqual(response.status_code, 200)
def rsvp(data): conn = db.conn() cursor = conn.cursor() rsvp_cmd = '''INSERT INTO event_%s VALUES (''' check_in_rsvp_cmd = '''INSERT INTO check_in_event_%s (userId) values (%s);''' check_in_cmd = '''INSERT INTO CheckIn (userId, eventId) values (%s, %s);''' args = [int(data['id']), data['userId']] rsvp_cmd += "%s" for resp in data['answers']: args.append(resp) rsvp_cmd += ", %s" rsvp_cmd += ");" try: cursor.execute(rsvp_cmd, args) cursor.execute(check_in_rsvp_cmd, [int(data['id']), int(data['userId'])]) cursor.execute(check_in_cmd, [int(data['userId']), int(data['id'])]) except MySQLdb.ProgrammingError: abort(400, "Event does not exist") except MySQLdb.OperationalError: abort(400, "Answers don't match Questions") except MySQLdb.IntegrityError: abort(400, "User has already RSVP-ed to this event") conn.commit() return True
def cal(user_id): conn = db.conn() cursor = conn.cursor() cursor.execute(cal_cmd, [user_id]) res = cursor.fetchall() output = [] for x in res: row = {} row['medication_id'] = x[2] row['day_to_take'] = x[3] row['time_to_take'] = x[4] row['run_out_date'] = x[5] if row['time_to_take'].hour >= 0 and row['time_to_take'].hour <=5: row['time_to_take'] = row['time_to_take'] - datetime.timedelta(hours = 5) if row['day_to_take'] == 0: row['day_to_take'] = 6 else: row['day_to_take'] -= 1 row['time_to_take'] = row['time_to_take'] + datetime.timedelta(hours = 5) now_time = datetime.datetime.now() number = datetime.datetime.today().weekday() #print(number, x[3]) if x[5] > now_time: output.append(row) return output
def test_register_no_phone(self): response = self.post('/user/register', dict( firstName='Bob', lastName='User', email='*****@*****.**', password='******' )) self.assertEqual(response.status_code, 200) with app.app_context() as context: data = response.get_json() user_id = auth.jwt.check_jwt(data['auth']) find_user = '''select * from Users where userId = %s;''' conn = db.conn() cursor = conn.cursor() cursor.execute(find_user, [user_id]) user = cursor.fetchall() self.assertEqual(1, len(user)) user = user[0] self.assertIn('Bob', user) self.assertIn('User', user) self.assertIn('*****@*****.**', user) self.assertIn(auth.hash_password('password123', '*****@*****.**'), user)
def get_id_from_role(role_list): conn = db.conn() cursor = conn.cursor() users = ','.join(['%s'] * len(role_list)) cursor.execute(get_id_from_role_cmd % users, tuple(role_list)) return cursor.fetchall()
def deactivate(tid): addr = tid2addr(tid) db = conn() c = db.cursor() c.execute('UPDATE tag SET is_active = 0 WHERE addr = ?', (addr, )) db.commit() db.close()
def get_user_emails(user_list): conn = db.conn() cursor = conn.cursor() users = ','.join(['%s'] * len(user_list)) cursor.execute(get_user_emails_cmd % users, tuple(user_list)) return cursor.fetchall()
def get_readers_pos(): db = conn() c = db.cursor() rs = c.execute('SELECT pos_x, pos_y FROM reader') tmp = [] for row in rs.fetchall(): tmp.append({'x': row[0], 'y': row[1]}) return tmp
def clear(): conn = db.conn() cursor = conn.cursor() for table in tables_to_clear: cursor.execute("TRUNCATE TABLE {};".format(table)) conn.commit()
def select_knowledge(code): conn = db.conn() # 查看添加对象是否存在 result = db.select(conn, "select * from t_code where code = ?", (code,)) if result is None: return {"code": "-1", "message": "record is not exist"} db.close(conn) return {"code": result[0], "name": result[1], "type": result[2]}
async def knowledge_select(knowledge: Knowledge): conn = db.conn() # 查看添加对象是否存在 result = db.select(conn, "select * from t_code where code = ?", (knowledge.code,)) if result is None: return {"code": "-1", "message": "record is not exist"} db.close(conn) return {"code": "0", "message": "success", "data": {"code": result[0], "name": result[1], "type": result[2]}}
def addEntry(name, file, position): conn = db.conn() cursor = conn.cursor() cursor.execute(""" INSERT INTO `website`.`jobs` (`name`, `file`, `position`) VALUES (%s, %s, %s);""", [name, file, position]) conn.commit() conn.close()
def on_get(self, req, resp, object_name): wait_for_schema() check_table(object_name) limit, offset = check_pagination(req) with db.conn() as conn: order_by = check_order_by(object_name, req) resp.body = to_json(get_table_query_rows(conn, object_name, req.params, limit, offset, order_by)) resp.status = falcon.HTTP_200
def on_get(self, req, resp, object_name): wait_for_schema() args = {x:req.params[x] for x in req.params if x in schema.FUNCTIONS[object_name]["parameters"]} check_function(object_name, args) limit, offset = check_pagination(req) with db.conn() as conn: order_by = check_order_by(schema.SCHEMA[schema.FUNCTIONS[object_name]["type"]], req) resp.body = to_json(get_function_rows(conn, object_name, args, limit, offset, order_by)) resp.status = falcon.HTTP_200
def on_put(self, req, resp, object_name): wait_for_schema() check_table(object_name) with db.conn() as conn: objs = from_json(req.stream.read()) if not isinstance(objs, list): resp.body = to_json(insert_table_row(conn, object_name, objs)) else: resp.body = to_json(insert_table_rows(conn, object_name, objs)) resp.status = falcon.HTTP_204
def door_exists(self, direction): c = db.conn().cursor() c.execute('select count(1) from doors where src_room_id = ? and dir = ?', (self.current_room.room_id, direction)) room_count = c.fetchone()[0] if room_count != 0: return True else: return False
def on_get(self, req, resp, object_name, pk): wait_for_schema() with db.conn() as conn: check_table(object_name) check_pk(object_name, pk) row = get_table_row(conn, object_name, pk) if row: resp.body = to_json(row) resp.status = falcon.HTTP_200 else: raise_not_found()
def on_post(self, req, resp, object_name, pk): wait_for_schema() check_table(object_name) check_pk(object_name, pk) with db.conn() as conn: obj = from_json(req.stream.read()) update_table_row(conn, object_name, pk, obj) row = get_table_row(conn, object_name, pk) if row: resp.body = to_json(row) resp.status = falcon.HTTP_200 else: raise_not_found()
def setup(): global HOME, arch, db_conn HOME = getenv('HOME', '/home/pi') arch = machine() signal(SIGUSR1, sigusr1) signal(SIGUSR2, sigusr2) load_settings() db_conn = db.conn(settings['database']) sh.mkdir(SCREENLY_HTML, p=True) html_templates.black_page(BLACK_PAGE)
def room_exists(self, direction): coords = self.get_coords_from_dir(direction) c = db.conn().cursor() c.execute('select count(*) from rooms where x = ? and y = ? and z = ?', coords) count = c.fetchone()[0] if count != 0: c.execute('select room_id from rooms where x = ? and y = ? and z = ?', coords) room_id = c.fetchone()[0] return room_id else: return 0
def __init__(self, room_id): # get the room from database c = db.conn().cursor() c.execute('select room_id, title, desc, x, y, z from rooms where room_id = ?', (room_id,)) # there's probably a better way to do this row = c.fetchone() self.room_id = row[0] self.title = row[1] self.desc = row[2] self.x = row[3] self.y = row[4] self.z = row[5] c.execute('select dir, dest_room_id from doors where src_room_id = ?', (self.room_id,)) self.exits = {} for row in c: self.exits[row[0]] = row[1]
def __init__(self): self.db = conn() self.url = "http://exame.abril.com.br/economia/noticias/as-100-contas-mais-influentes-de-economia-no-twitter" self.api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
return 'Sorry, this page does not exist!' ################################ # Static ################################ @route('/static/:path#.+#', name='static') def static(path): return static_file(path, root='static') if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings.get_asset_folder()): mkdir(settings.get_asset_folder()) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings.get_database()) as conn: global db_conn db_conn = conn with db.cursor(db_conn) as c: c.execute(queries.exists_table) if c.fetchone() is None: c.execute(assets_helper.create_assets_table) run(host=settings.get_listen_ip(), port=settings.get_listen_port(), reloader=True)
def save(self): c = db.conn().cursor() c.execute('update rooms set title=?, desc=? where room_id=?', (self.title, self.desc, self.room_id)) db.conn().commit()
def get_region_services(self, region): mysql_uri = region.get('mysql_uri') services = get_services(conn(mysql_uri)) return services
def draw_map(): # set the bounds of the map (2 square radius around current room) x_min = roomMan.current_room.x - 2 x_max = roomMan.current_room.x + 2 y_min = roomMan.current_room.y - 1 y_max = roomMan.current_room.y + 2 sql = 'select rooms.room_id, doors.dir, rooms.x, rooms.y from doors \ inner join rooms on (doors.src_room_id = rooms.room_id) \ where rooms.z = ? \ and rooms.x between ? and ? \ and rooms.y between ? and ? \ order by rooms.room_id, rooms.y desc, rooms.x' c = db.conn().cursor() db_rows = c.execute(sql, (roomMan.current_room.z, x_min, x_max, y_min, y_max)) room_data = {} # loop through results and build a dictionary of exit value lists for row in db_rows: # key in the form of "x,y" key = str(row[2]) + ',' + str(row[3]) if( key in room_data ): room_data[key].append(row[1]) else: room_data[key] = [row[1]] # print a title for the map if roomMan.current_room.z >= 0: print "Map of floor " + str(roomMan.current_room.z+1) else: print "Map of basement level " + str(math.fabs(roomMan.current_room.z)) for y in reversed(range(y_min, y_max)): line1 = '' line2 = '' line3 = '' for x in range(x_min, x_max): key = str(x) + ',' + str(y) if key in room_data: is_current_room = (x == roomMan.current_room.x and y == roomMan.current_room.y) room_map = roomMan.get_room_map(room_data[key], is_current_room) else: room_map = (' ', ' ', ' ') line1 += room_map[0] line2 += room_map[1] line3 += room_map[2] print line1 print line2 print line3 print " # = room" print " * = You are here"
return 'Sorry, this page does not exist!' ################################ # Static ################################ @route('/static/:path#.+#', name='static') def static(path): return static_file(path, root='static') if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings['assetdir']): mkdir(settings['assetdir']) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings['database']) as conn: global db_conn db_conn = conn with db.cursor(db_conn) as c: c.execute(queries.exists_table) if c.fetchone() is None: c.execute(assets_helper.create_assets_table) run(host=settings.get_listen_ip(), port=settings.get_listen_port(), fast=True, reloader=True)
order by routines.routine_name, parameters.ordinal_position; """, [settings.DB_SCHEMA, settings.DB_USER]) for r in c: routine_name, routine_data_type, parameter_name, parameter_data_type, routine_comments = r if routine_name in functions: routine = functions[routine_name] else: if routine_data_type not in schema: continue routine = { "comments" : routine_comments, "endpoint" : "/function/%s/" % routine_name, "type" : routine_data_type, "parameters" : collections.OrderedDict(), "methods" : ["GET", "POST"] } if parameter_name: routine["parameters"][parameter_name] = parameter_data_type functions[routine_name] = routine return schema, functions, pks if db.DB_ONLINE: log.debug("Start retrieve schema") with db.conn() as conn: SCHEMA, FUNCTIONS, PKS = get_schema(conn) log.debug("Finish retrieve schema")
def mistake404(code): return "Sorry, this page does not exist!" ################################ # Static ################################ @route("/static/:path#.+#", name="static") def static(path): return static_file(path, root="static") if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings["assetdir"]): mkdir(settings["assetdir"]) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings["database"]) as conn: global db_conn db_conn = conn with db.cursor(db_conn) as c: c.execute(queries.exists_table) if c.fetchone() is None: c.execute(assets_helper.create_assets_table) run(host=settings.get_listen_ip(), port=settings.get_listen_port(), fast=True, reloader=True)
if __name__ == "__main__": # Bring up load screen toggle_load_screen(True) # Install signal handlers signal.signal(signal.SIGUSR1, sigusr1) signal.signal(signal.SIGUSR2, sigusr2) # Before we start, reload the settings. reload_settings() global db_conn db_conn = db.conn(settings.get_database()) # Create folder to hold HTML-pages html_folder = '/tmp/screenly_html/' if not path.isdir(html_folder): makedirs(html_folder) # Set up HTML templates black_page = html_templates.black_page() # Fire up the browser run_browser = load_browser() logging.debug('Getting browser PID.') browser_pid = run_browser.pid
if __name__ == "__main__": HOME = getenv('HOME', '/home/pi/') # Bring up load screen toggle_load_screen(True) # Install signal handlers signal.signal(signal.SIGUSR1, sigusr1) signal.signal(signal.SIGUSR2, sigusr2) # Before we start, reload the settings. reload_settings() global db_conn db_conn = db.conn(settings['database']) # Create folder to hold HTML-pages html_folder = '/tmp/screenly_html/' if not path.isdir(html_folder): makedirs(html_folder) # Set up HTML templates black_page = html_templates.black_page() # Fire up the browser run_browser = load_browser() logging.debug('Getting browser PID.') browser_pid = run_browser.pid
def setUp(self): self.assertEmpty = functools.partial(self.assertEqual, []) self.conn = db.conn(':memory:') with db.commit(self.conn) as cursor: cursor.execute(assets_helper.create_assets_table)
def on_get(self, req, resp, object_name): wait_for_schema() check_table(object_name) with db.conn() as conn: resp.body = to_json(get_table_query_row_count(conn, object_name, req.params)) resp.status = falcon.HTTP_200