1+ import logging , schedule , time
12from flask import Flask , render_template
23from flask_graphql import GraphQLView
34from graphene import Schema
45from graphql .utils import schema_printer
56from src .database import db_session , init_db
7+ from src .models .capacity import Capacity
8+ from src .models .openhours import OpenHours
69from src .schema import Query
7- from src .constants import create_gym_table
8- from src .scrapers .scraper import scrape_classes
9- from src .scrapers .gym_scraper import scrape_times
10- from src .scrapers . scraper import scrape_classes , scrape_pool_hours
10+ from src .scrapers . capacities_scraper import fetch_capacities
11+ from src .scrapers .reg_hours_scraper import fetch_reg_building , fetch_reg_facility
12+ from src .scrapers .sp_hours_scraper import fetch_sp_facility
13+ from src .utils . utils import create_gym_table
1114
1215
1316app = Flask (__name__ )
@@ -29,12 +32,22 @@ def shutdown_session(exception=None):
2932 db_session .remove ()
3033
3134
32- # Create database and fill it with constants
35+ def scrape_sheets ():
36+ logging .info ("Scraping from sheets..." )
37+
38+ # Fetch Hours
39+ fetch_reg_facility ()
40+ fetch_reg_building ()
41+ fetch_sp_facility ()
42+
43+ # Fetch Capacities
44+ fetch_capacities ()
45+
46+
47+ # Create database and fill it with data
3348init_db ()
3449create_gym_table ()
35- scrape_times ()
36- scrape_classes (3 )
37- scrape_pool_hours ()
50+ scrape_sheets ()
3851
3952# Create schema.graphql
4053with open ("schema.graphql" , "w+" ) as schema_file :
@@ -44,3 +57,9 @@ def shutdown_session(exception=None):
4457# Should only be used for dev
4558if __name__ == "__main__" :
4659 app .run (host = "127.0.0.1" , port = 5000 ) # For Dev Purposes only (use start_server.sh for release)
60+
61+ # Schedule the scraping to run every 10 minutes
62+ schedule .every (10 ).minutes .do (scrape_sheets )
63+ while True :
64+ schedule .run_pending ()
65+ time .sleep (60 )
0 commit comments