Skip to content

Commit 7742c1d

Browse files
isabellahoieIsabella Hoie
andauthored
Created Gym Scraper And Made Bug Fixes on Classes Scraper (#116)
* Created activity model and many to many relationship with gym model; added activity and gym rresolvers to the schema * added activity model to import statements on init_db() * deleted testing objects in init_db() * deleted duplicate code * Implemented PR edits in activity.py * Implemented PR edits in gym.py * Implemented PR changes in schema.py and added Price and Amenity class and price resolver in Activity class * Populated models to test * Cleaning up some merge conflicts * almost implementing Facilities * Activity model and some changes to gym * Created some of gym scraper * wrote some of gym hour scraper * Implement scraper for fitness center hours * changed some of activities * bug fixes on the scraper --------- Co-authored-by: Isabella Hoie <iah27@cornell.edu>
1 parent 7b9b366 commit 7742c1d

22 files changed

Lines changed: 503 additions & 268 deletions

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ WORKDIR /usr/src/app
55

66
COPY . .
77

8+
ENV MAX_CONCURRENT_PIP=4
9+
10+
RUN pip install --upgrade pip
811
RUN pip install -r requirements.txt

T

Whitespace-only changes.

app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from src.database import db_session, init_db
66
from src.schema import Query
77
from src.constants import create_gym_table
8+
from src.scrapers.scraper import scrape_classes
9+
from src.scrapers.gym_scraper import scrape_times
810
from src.scrapers.scraper import scrape_classes, scrape_pool_hours
911

1012

@@ -30,6 +32,7 @@ def shutdown_session(exception=None):
3032
# Create database and fill it with constants
3133
init_db()
3234
create_gym_table()
35+
scrape_times()
3336
scrape_classes(3)
3437
scrape_pool_hours()
3538

manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
22
from flask_script import Manager
33
from flask_migrate import Migrate, MigrateCommand
4-
from app import app, db
4+
from app import app#, db
55

66
# Build manager
7-
migrate = Migrate(app, db)
7+
#migrate = Migrate(app, db)
88
manager = Manager(app)
99
manager.add_command("db", MigrateCommand)
1010

schema.graphql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type ClassInstance {
2525
instructor: String!
2626
isCanceled: Boolean!
2727
isVirtual: Boolean!
28-
startTime: DateTime!
29-
endTime: DateTime!
28+
startTime: DateTime
29+
endTime: DateTime
3030
class_: Class
3131
gym: Gym
3232
}
@@ -64,8 +64,8 @@ type OpenHours {
6464
id: ID!
6565
facilityId: Int!
6666
day: Int!
67-
startTime: String!
68-
endTime: String!
67+
startTime: String
68+
endTime: String
6969
}
7070

7171
type Query {

src/constants.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
"image_url": "gyms/teagle.jpg",
6464
"facilities": [
6565
{
66-
"name": "Teagle Up",
66+
"name": "Teagle Upstairs",
6767
"type": "fitness",
6868
"hours": []
6969
},
7070
{
71-
"name": "Teagle Down",
71+
"name": "Teagle Downstairs",
7272
"type": "fitness",
7373
"hours": []
7474
},
@@ -80,4 +80,4 @@
8080
]
8181
}
8282
]
83-
}
83+
}

src/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,4 @@ def create_gym_table():
4949
db_session.merge(gym)
5050
for facility in facilities:
5151
db_session.merge(facility)
52-
for hours in fitness_hours:
53-
db_session.merge(hours)
5452
db_session.commit()

src/models/activity.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from sqlalchemy import Column, Float, String, Integer, ForeignKey, Table
2+
from sqlalchemy.orm import relationship
3+
from src.database import Base
4+
5+
def Activity(Base):
6+
__tablename__ = 'activity'
7+
8+
id = Column(Integer, primary_key = True)
9+
name = Column(String, nullable=False)
10+
activity_type = Column(Integer, ForeignKey('activitytype.id'), nullable=False)
11+
facility_id = Column(Integer, ForeignKey('facility.id'), nullable=False)
12+
prices = relationship('Price')
13+
image_url = Column(String(), nullable=False)
14+
15+
def __init__(self, **kwargs):
16+
self.id = kwargs.get('id')
17+
self.name = kwargs.get('name')
18+
self.activity_type = kwargs.get('activity_type')
19+
self.facility_id = kwargs.get('facility_id')
20+
self.image_url = kwargs.get('image_url')
21+
22+
23+
def ActivityType(Base):
24+
__tablename__ = 'activitytype'
25+
26+
id = Column(Integer, primary_key=True)
27+
name = Column(String, nullable=False)
28+
29+
def __init__(self, **kwargs):
30+
self.id = kwargs.get('id')
31+
self.name = kwargs.get('name')
32+
33+

src/models/capacity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
from sqlalchemy import Column, ForeignKey, Integer, DateTime, Float
23
from sqlalchemy.orm import backref, relationship
34
from src.database import Base

src/models/classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class ClassInstance(Base):
4343
instructor = Column(String(), nullable=False)
4444
isCanceled = Column(Boolean(), nullable=False, default=False)
4545
isVirtual = Column(Boolean(), nullable=False, default=False)
46-
start_time = Column(DateTime(), nullable=False)
47-
end_time = Column(DateTime(), nullable=False)
46+
start_time = Column(DateTime(), nullable=True)
47+
end_time = Column(DateTime(), nullable=True)
4848

4949
class_ = relationship("Class", back_populates="gyms")
5050
gym = relationship("Gym", back_populates="classes")

0 commit comments

Comments
 (0)