Skip to content

Commit

Permalink
feat: tidy docker-compose, turn sunjad url into environment var
Browse files Browse the repository at this point in the history
  • Loading branch information
Veivel committed Jul 15, 2024
1 parent efd8432 commit 40c6bbc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
15 changes: 11 additions & 4 deletions courseUpdater/courseApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
from main.models import Course
from django.conf import settings as django_settings
import logging
import environ

def update_courses():
env = environ.Env()
print("UPDATE CALLED")
json = _get_courses_json()

url_ik = env("SUNJAD_BASE_URL") + '/susunjadwal/api/majors/60f4f2b38cd53dc0e3b371b9/all_courses'
_update_courses_on_url(url_ik)
url_si = env("SUNJAD_BASE_URL") + '/susunjadwal/api/majors/60f505258cd53dc0e3b371d4/all_courses'
_update_courses_on_url(url_si)

def _update_courses_on_url(url: str):
json = _fetch_courses_json(url)
logging.info("Sunjad courses response: {}".format(json))

if json is not None:
Expand All @@ -15,9 +24,7 @@ def update_courses():
course = getCourse(course_json)
course.save()

def _get_courses_json():
url = django_settings.SUNJAD_BASE_URL + 'susunjadwal/api/courses'

def _fetch_courses_json(url: str):
r = requests.get(url)

try:
Expand Down
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ version: "3.9"
services:
postgres:
container_name: ulas-pg
image: postgres:alpine
image: postgres:15-alpine
volumes:
- ./data/db:/var/lib/postgresql/data
- ulas_db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
restart: unless-stopped
restart: unless-stopped

volumes:
ulas_db:
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SUNJAD_BASE_URL=https://api.susunjadwal.cs.ui.ac.id | <container name>

DJANGO_SETTINGS_MODULE=UlasKelas.settings
SECRET_KEY=xxx
SENTRY_DSN=https://xxx.ingest.sentry.io/xxx
Expand Down
2 changes: 1 addition & 1 deletion sso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

DEFAULTS = {
"SSO_UI_URL": "https://sso.ui.ac.id/cas2/",
"SUNJAD_BASE_URL": " https://api.susunjadwal.cs.ui.ac.id/",
"SSO_UI_FORCE_SERVICE_HTTPS": False,
# notice: SUNJAD_BASE_URL is now an .env variable
}


Expand Down

0 comments on commit 40c6bbc

Please sign in to comment.