feat: add a basic example of scraper usage
This commit is contained in:
@@ -7,9 +7,15 @@ class scraper:
|
||||
'x-fsign': 'SW9D1eZo'
|
||||
}
|
||||
|
||||
def __init__:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def pobierzDaneNajlepszegoSportowcaNaSwiecie() -> dict:
|
||||
def pobierzDaneNajlepszegoSportowcaNaSwiecie(self) -> dict:
|
||||
response = requests.get('https://3.flashscore.ninja/3/x/feed/plm_MVC8zHZD_0', headers=headers)
|
||||
return json.loads(response.text)
|
||||
|
||||
def pobierz_pojedyncza_strone(self, zewnetrzne_id_sportowca: str = "MVC8zHZD", nr_strony: int = 0) -> dict:
|
||||
if len(zewnetrzne_id_sportowca) != 8:
|
||||
raise ValueError("Zewnętrzne ID sportowca powinno być długości 8!")
|
||||
response = requests.get(f'https://3.flashscore.ninja/3/x/feed/plm_{zewnetrzne_id_sportowca}_{nr_strony}', headers=self.headers)
|
||||
return json.loads(response.text)
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user