def create_app(): """ create and configure the app""" app = Flask(__name__, instance_relative_config=True) app.config.from_envvar("PORT_SCANNER_CFG") CORS(app) app.config['CORS_HEADERS'] = 'Content-Type' try: os.makedirs(app.instance_path) except OSError: pass print(app.config) init_database(app.config["SQLALCHEMY_DATABASE_URI"]) @app.route('/scan', methods=['GET', 'POST']) @cross_origin(allow_headers=['Content-Type']) def scan_hosts_ports(): app.logger.info(f"Received request data {request.data}") resp = scan_hosts(request.data, app.config["SQLALCHEMY_DATABASE_URI"], app.config["THREADS_NUMBER"], app.logger) response = jsonify(resp["data"]) return response, resp["status_code"] #@app.after_request #def after_request(response): # response.headers.add('Access-Control-Allow-Origin', '*') # response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') # response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS') # return response return app
class Handler: app = app app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False CORS(app) db = init_database(app) migrate = Migrate(app, db) app.app_context().push() app.register_blueprint(playlists_handler) app.register_blueprint(track_handler) app.register_blueprint(user_handler) def __init__(self): return None
from telebot import types import config from db import init_database bot = telebot.TeleBot(config.token) start_keyboard = types.ReplyKeyboardMarkup(True, True) btn1 = types.KeyboardButton('Новое напоминание') start_keyboard.add(btn1) @bot.message_handler(commands=["start"]) def start_answer(message): bot.send_message(message.chat.id, 'Привет, я помогу тебе вспомнить всё', reply_markup=start_keyboard) @bot.message_handler(content_types=["text"]) def fill_database(message): chat_id = message.chat.id if message.text == 'Новое напоминание': bot.send_message(chat_id, "Enter time") t = input() if __name__ == '__main__': init_database() bot.infinity_polling()
'''Server''' import sqlite3 import uuid import db from flask import Flask, jsonify, render_template, request, Response, redirect import psutil APP = Flask(__name__) APP.secret_key = uuid.uuid1() CONN = db.init_database() @APP.route('/monitor', methods=['GET']) def get_page_monitor(): '''Get page monitor''' print(request.cookies) if 'token' in request.cookies: token = request.cookies.get('token') if db.valid_token(CONN, token): return render_template('monitor.html') return redirect("http://127.0.0.1:5000/signin") @APP.route('/signin', methods=['GET']) def get_page_signin(): '''Get page signin''' return render_template('signin.html') @APP.route('/signin.do', methods=['POST']) def do_signin():
def setUp(self): db.init_database('test.db')
import sys import os reload(sys) sys.setdefaultencoding('utf-8') #开启多线程 env.parallel = 'true' #检查数据库完整性和数据库文件状态 #db.check_database_status() try: db.check_database_status() except: print "init database!" db.init_database() from base_commond import * #构建命令参数列表 def main(): parser = OptionParser() parser.add_option("--add", action="store", dest="addserver", nargs=4) parser.add_option("--check", action="store", dest="check_server_status") parser.add_option("--change_password", action="store", dest="change_password", nargs=2) parser.add_option("--display", action="store", dest="display_server_info")
def init(): db.init_database() pass
import subprocess import sys import os reload(sys) sys.setdefaultencoding('utf-8') #开启多线程 env.parallel = 'true' #检查数据库完整性和数据库文件状态 #db.check_database_status() try: db.check_database_status() except: print "init database!" db.init_database() from base_commond import * #构建命令参数列表 def main(): parser = OptionParser() parser.add_option("--add", action = "store", dest = "addserver", nargs = 4 ) parser.add_option("--check", action = "store", dest = "check_server_status") parser.add_option("--change_password", action = "store", dest = "change_password", nargs = 2) parser.add_option("--display",action = "store", dest = "display_server_info") parser.add_option("--get", action = "store", dest = "file",nargs = 3) parser.add_option("--import", action = "store", dest = "importconfig", nargs = 1) parser.add_option("--push", action = "store", dest = "file", nargs = 3)
def init(): init_database() if (not exists(DATASET_DIRECTORY)): mkdir(DATASET_DIRECTORY)
from db import connect_database, init_database conn = connect_database('admin', 'postgres', '127.0.0.1', '5432', 'flask_api') init_database(conn)