Skip to content

Commit

Permalink
Automatically runs chartwells_query script when container is started.
Browse files Browse the repository at this point in the history
  • Loading branch information
That-Thing committed Nov 2, 2024
1 parent e764635 commit 8d09d8b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
FROM gradle:7.6.0-jdk17 AS build

# Set the working directory
WORKDIR /app

# Copy the Gradle configuration and source code
COPY build.gradle settings.gradle /app/
COPY src /app/src

# Build the application
RUN gradle bootJar --no-daemon

FROM eclipse-temurin:17-jdk-alpine

# Set the working directory
# Install Python and dcron
RUN apk update && apk add python3 py3-pip dcron py3-requests

WORKDIR /app

# Copy the JAR file from the build stage
# Copy JAR and Python script
COPY --from=build /app/build/libs/*.jar app.jar
COPY chartwells_query.py /app/chartwells_query.py

# Add crontab file and set permissions
COPY crontab.txt /etc/crontabs/root

# Make entrypoint executable
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Expose port
EXPOSE 8080

# Rub
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
ENTRYPOINT ["/entrypoint.sh"]
17 changes: 14 additions & 3 deletions chartwells_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import json
from datetime import datetime, timezone, timedelta
import time
import os

#used to access the chartwells api from the viewpoint of a user normal
headers = {
'User-Agent': 'Mozilla/5.0'
}

#database_path = "database.db"
database_path = "Database/dish.db"
# Conditional to determine if the script is running in a docker container
if os.getenv("RUNNING_IN_DOCKER") == "true":
database_path = "/data/dish.db"
else:
database_path = "Database/dish.db"

date_today = datetime.now(timezone(timedelta(hours=-4))).strftime('%Y-%m-%d')
date_tomorrow = (datetime.now(timezone(timedelta(hours=-4))) + timedelta(1)).strftime('%Y-%m-%d')
Expand All @@ -22,12 +26,19 @@
#used to grab meal data for a given location, period, and date
meal_data_request = "https://api.dineoncampus.com/v1/location/{location}/periods/{period}?platform=0&date={date}"

dining_locations = {"Wadsworth":"64b9990ec625af0685fb939d"}#,"McNair":"64a6b628351d5305dde2bc08","DHH":"64e3da15e45d430b80c9b981"}
dining_locations = {}

def main():
db_conection = sqlite3.connect(database_path)
db_cursor = db_conection.cursor()

# Get locations from database
db_cursor.execute("SELECT * FROM locations")
rows = db_cursor.fetchall()
for row in rows:
print("DEBUG: " + row[0] + " " + row[1])
dining_locations[row[0]] = row[1]

for date in dates:
for location in dining_locations:
print(f"Grabbing periods for {date} {location}")
Expand Down
1 change: 1 addition & 0 deletions crontab.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 */2 * * * python3 /app/chartwells_query.py >> /var/log/cron.log 2>&1
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ services:
environment:
SPRING_DATASOURCE_URL: "jdbc:sqlite:/data/dish.db"
SPRING_PROFILES_ACTIVE: "docker"
RUNNING_IN_DOCKER: "true"
volumes:
- ./Database:/data
12 changes: 12 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Run at startup
python3 /app/chartwells_query.py

# Start dcron
crond -b

touch ./debug.file

# Start DISH
java -jar /app/app.jar

0 comments on commit 8d09d8b

Please sign in to comment.