Skip to content

Commit 534c535

Browse files
authored
Merge pull request #199 from cuappdev/master
Merging master to release (Syncing Production server)
2 parents d475ac1 + acc684a commit 534c535

38 files changed

Lines changed: 1541 additions & 320 deletions

.github/workflows/deploy-dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ jobs:
3939
touch tags
4040
source tags
4141
export IMAGE_TAG=${{ steps.vars.outputs.sha_short }}
42-
echo "export IMAGE_TAG=${IMAGE_TAG}" > tags
4342
cd docker-compose
4443
docker stack rm the-stack
4544
sleep 20s
4645
sudo systemctl stop nginx
4746
sudo systemctl restart nginx
4847
docker stack deploy -c docker-compose.yml the-stack --with-registry-auth
49-
yes | docker system prune -a
48+
sleep 60s
49+
yes | docker system prune -a

.github/workflows/test.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ build/
1212
*.DS_Store
1313
.env
1414
.envrc
15-
migrations
1615
.vscode
1716
Archive
1817
scripts

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ COPY . .
66
ENV MAX_CONCURRENT_PIP=4
77
RUN pip3 install --upgrade pip
88
RUN pip3 install --exists-action w -r requirements.txt
9-
CMD python3 app.py
9+
CMD flask --app migrations db upgrade && python3 app.py

app.db

36 KB
Binary file not shown.

app.py

Lines changed: 12 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,17 @@
1-
import logging
1+
from app_factory import create_app
22
import sentry_sdk
3-
from flask import Flask, render_template
4-
from flask_apscheduler import APScheduler
5-
from flask_graphql import GraphQLView
6-
from graphene import Schema
7-
from graphql.utils import schema_printer
8-
from src.database import db_session, init_db
9-
from src.schema import Query, Mutation
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.scraper_helpers import clean_past_hours
13-
from src.scrapers.sp_hours_scraper import fetch_sp_facility
14-
from src.scrapers.equipment_scraper import scrape_equipment
15-
from src.scrapers.class_scraper import fetch_classes
16-
from src.scrapers.activities_scraper import fetch_activity
17-
from src.utils.utils import create_gym_table
18-
from src.models.openhours import OpenHours
19-
from flasgger import Swagger
3+
import os
204

5+
# Initialize Sentry only if not in local
6+
if os.environ.get('FLASK_ENV') in ["development", "production"]:
7+
sentry_sdk.init(
8+
dsn="https://2a96f65cca45d8a7c3ffc3b878d4346b@o4507365244010496.ingest.us.sentry.io/4507850536386560",
9+
traces_sample_rate=1.0,
10+
profiles_sample_rate=1.0,
11+
)
2112

22-
sentry_sdk.init(
23-
dsn="https://2a96f65cca45d8a7c3ffc3b878d4346b@o4507365244010496.ingest.us.sentry.io/4507850536386560",
24-
# Set traces_sample_rate to 1.0 to capture 100%
25-
# of transactions for tracing.
26-
traces_sample_rate=1.0,
27-
# Set profiles_sample_rate to 1.0 to profile 100%
28-
# of sampled transactions.
29-
# We recommend adjusting this value in production.
30-
profiles_sample_rate=1.0,
31-
)
32-
33-
app = Flask(__name__)
34-
app.debug = True
35-
schema = Schema(query=Query, mutation=Mutation)
36-
swagger = Swagger(app)
37-
38-
# Scheduler
39-
scheduler = APScheduler()
40-
scheduler.init_app(app)
41-
scheduler.start()
42-
43-
# Logging
44-
logging.basicConfig(format="%(asctime)s %(levelname)-8s %(message)s", level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S")
45-
46-
47-
@app.route("/")
48-
def index():
49-
return render_template("index.html")
50-
51-
52-
app.add_url_rule("/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True))
53-
54-
55-
@app.teardown_appcontext
56-
def shutdown_session(exception=None):
57-
db_session.remove()
58-
59-
60-
# Scrape hours every 15 minutes
61-
@scheduler.task("interval", id="scrape_hours", seconds=900)
62-
def scrape_hours():
63-
logging.info("Scraping hours from sheets...")
64-
65-
# Clear hours
66-
db_session.query(OpenHours).delete()
67-
68-
fetch_reg_facility()
69-
fetch_reg_building()
70-
fetch_sp_facility()
71-
clean_past_hours()
72-
73-
74-
# Scrape capacities every 10 minutes
75-
@scheduler.task("interval", id="scrape_capacities", seconds=600)
76-
def scrape_capacities():
77-
logging.info("Scraping capacities from C2C...")
78-
79-
fetch_capacities()
80-
81-
82-
# Scrape classes every hour
83-
@scheduler.task("interval", id="scrape_classes", seconds=3600)
84-
def scrape_classes():
85-
logging.info("Scraping classes from group-fitness-classes...")
86-
87-
88-
fetch_classes(10)
89-
90-
91-
# Create database and fill it with data
92-
init_db()
93-
create_gym_table()
94-
scrape_classes()
95-
scrape_hours()
96-
scrape_capacities()
97-
scrape_equipment()
98-
99-
logging.info("Scraping activities from sheets...")
100-
fetch_activity()
101-
# Create schema.graphql
102-
with open("schema.graphql", "w+") as schema_file:
103-
schema_file.write(schema_printer.print_schema(schema))
104-
schema_file.close()
13+
# Create Flask app with scrapers enabled
14+
app = create_app(run_migrations=False)
10515

10616
if __name__ == "__main__":
107-
app.run(host="127.0.0.1", port=5000)
17+
app.run(host="0.0.0.0", port=5000)

0 commit comments

Comments
 (0)