Пример #1
0
        source_id = data["source_id"]
        with app.app_context():
            citation = (db.session.query(Citations).filter(
                Citations.source_id == source_id).one())
            citation.is_cited = False
            db.session.commit()

        log.debug(
            "Removed citation from bibliography with source ID <%s> for <%s>",
            source_id,
            email,
        )
    else:
        log.warning("No login found")


@app.route("/")
@app.route("/about")
@app.route("/bibliography")
@app.route("/future")
@app.route("/home")
@app.route("/login")
@app.route("/pricing")
@app.route("/project")
def index():
    return render_template("index.html")


if __name__ == "__main__":
    run_app(app)
Пример #2
0
    """
    Отправка JSON со статистикой комментариев по городам
    """
    json_obj = select_filter_all(
        row_name='region_id',
        row_val=city_num,
        db_name="city"
    )
    return Response(
        json.dumps(json_obj),
        content_type='application/json'
    )


@get('/media/(?P<filename>.+)')
def media(request, filename):
    """
    Подрузка файлов из директории media
    """
    return serve_static_file(request, filename, root=MY_ROOT)


# Маленький невидимый такой костылек
def get_item(obj, attr):
    a = obj.__getitem__(attr)
    return a

run_app()


Пример #3
0
# TODO argparse or config
DEBUG = Config.FLASK_DEBUG
# DEBUG = True


def shutdown_sched(scheduler: BackgroundScheduler):
    print("[INFO] Shutting down BG scheduler")
    scheduler.shutdown()


# https://stackoverflow.com/a/25519547/8608146
if not DEBUG or os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
    # store the session once
    store_session()
    # send very first ping request
    send_ping_req()

    scheduler = BackgroundScheduler()
    scheduler.add_job(func=send_ping_req, trigger="interval", seconds=60)
    print("[INFO] Starting Background Scheduler...")
    scheduler.start()
    # Shut down the scheduler when exiting the app
    atexit.register(lambda: shutdown_sched(scheduler))

if __name__ == '__main__':
    app.config['UPLOAD_FOLDER'] = os.path.join(up_one, 'data')
    print(app.config['UPLOAD_FOLDER'], app.static_folder, app.static_url_path)
    app.debug = True
    run_app(app=app, host='0.0.0.0', port=8080, debug=DEBUG)
Пример #4
0
 def run(self, host="127.0.0.1", port=8082):
     run_app(host=host, port=port)
Пример #5
0
            json_obj.append(i)
    return Response(json.dumps(json_obj), content_type='application/json')


@get('/stat=(?P<city_num>\d+)/json')
def send_json_stat_city(request, city_num):
    """
    Отправка JSON со статистикой комментариев по городам
    """
    json_obj = select_filter_all(row_name='region_id',
                                 row_val=city_num,
                                 db_name="city")
    return Response(json.dumps(json_obj), content_type='application/json')


@get('/media/(?P<filename>.+)')
def media(request, filename):
    """
    Подрузка файлов из директории media
    """
    return serve_static_file(request, filename, root=MY_ROOT)


# Маленький невидимый такой костылек
def get_item(obj, attr):
    a = obj.__getitem__(attr)
    return a


run_app()
Пример #6
0
    default='./data',
    help='Main Directory which the server uses as storage (default: ./data)',
)
parser.add_argument(
    '-p',
    '--port',
    type=int,
    default=3000,
    help='Flask port (default: 3000)',
)

args = parser.parse_args()
dirname = os.path.abspath(args.dir)

# create the dir
try:
    os.makedirs(dirname)
except FileExistsError:
    pass
except Exception as e:
    print(e)

if not os.access(args.dir, os.R_OK):
    raise argparse.ArgumentTypeError(f"No such directory {dirname}")

# print(args)

app.config['UPLOAD_FOLDER'] = dirname
app.debug = True
run_app(host='0.0.0.0', port=8080, debug=True)