feat: add a basic example of scraper usage

This commit is contained in:
2025-05-17 00:41:36 +02:00
parent 8689426ae3
commit 00a30695b7
2 changed files with 14 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
from argparse import ArgumentParser
from flask import Flask, Response, render_template
from flask_apscheduler import APScheduler
from fs_scraper import scraper
from lewy_globals import colors as c
import lewy_api
import lewy_db
@@ -12,11 +13,12 @@ import time
app = Flask(__name__)
app_host = "None"
app_port = "None"
scrape = None
def setup():
# sanity check: make sure config is set
# required to make `flask --app lewy run --debug` work
global config, app_host, app_port
global config, app_host, app_port, scrape
try:
if not config['general']:
lewy_globals.setConfig(lewy_globals.configfile)
@@ -43,7 +45,7 @@ def setup():
public_facing_url = config['general']['public_facing_url']
if len(public_facing_url) >= 4 and public_facing_url[0:5].lower() == "https":
https_str = f"{c.OKBLUE}INFO: {c.ENDC} You're trying to run this web server on HTTPS, but currently it's not possible to do that!\n"
https_str = f"{c.OKBLUE}INFO:{c.ENDC} You're trying to run this web server on HTTPS, but currently it's not possible to do that!\n"
https_str += f" Please consider running this service behind a reverse proxy if you need HTTPS.\n"
print(https_str)
rewrite_sanity_check = public_facing_url.replace(f"{app_host}:{app_port}", "")
@@ -71,6 +73,7 @@ def setup():
app.add_url_rule('/api/<path:received_request>', view_func=lewy_api.api_global_catchall)
db = lewy_db.initDB(app, config)
scrape = scraper()
with app.app_context():
db.create_all()
@@ -89,6 +92,7 @@ def every5seconds():
def every2hours():
# zaktualizuj bazę danych scrapując FS
# ...
# print(scrape.pobierz_pojedyncza_strone())
return
@app.route('/<string:val>', methods=['GET'])