Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CALENDAR_URL=
CALENDAR_OUTLOOK_DAYS=
CALENDAT_EVENT_MAXIMUM=
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.14.2
3.14
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ FROM ghcr.io/astral-sh/uv:python3.14-alpine
COPY src /jumpstart
WORKDIR /jumpstart

RUN addgroup -g 2000 jumpgroup
RUN adduser -S -u 1001 -G jumpgroup jumpstart
RUN addgroup -g 2000 jumpgroup && adduser -S -u 1001 -G jumpgroup jumpstart

RUN uv pip install --no-cache-dir -r requirements.txt --system
RUN uv pip install --no-cache-dir -r requirements.txt --system && rm requirements.txt

CMD ["echo", ":)"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--log-config", "/jumpstart/logging_config.yaml"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ This is a backend re-write of the previous jumpstart.

See it live [here](https://jumpstart.csh.rit.edu)!

## Setup

1. Setup .env

```bash
cp .env.template .env
```

adjust .env config variables as needed.


## Install

Uhhh
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ services:
container_name: Jumpstart
ports:
- "8000:8000"

environment:
- CALENDAR_URL=${CALENDAR_URL}
- CALENDAR_OUTLOOK_DAYS=${CALENDAR_OUTLOOK_DAYS}
- CALENDAT_EVENT_MAXIMUM=${CALENDAT_EVENT_MAXIMUM}
92 changes: 92 additions & 0 deletions src/api/endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from logging import getLogger, Logger

import random
import textwrap
import requests

from fastapi import APIRouter, Query
from fastapi.responses import JSONResponse

from core import calendar, slack

logger: Logger = getLogger(__name__)

router: APIRouter = APIRouter()

@router.get("/calendar")
def get_calendar() -> JSONResponse:
"""
Returns calendar data.
"""

pass


@router.get("/announcement")
def get_announcement() -> JSONResponse:
"""
Returns announcement data.
"""

pass


@router.put("/announcement")
def update_announcement() -> JSONResponse:
"""
Updates an existing announcement.
"""

pass


@router.get("/harold")
def get_harold() -> JSONResponse:
"""
Returns harold data.
"""

pass


@router.put("/harold")
def update_harold() -> JSONResponse:
"""
Updates harold data.
"""

pass


@router.get("/showerthoughts")
def showerthoughts() -> JSONResponse:
"""
Returns a random shower thought from the Reddit API.

Returns:
JSONResponse: A JSON response containing a random shower thought.
"""

response: dict = {"data": "No shower thoughts found."}

try:
logger.info("Fetching shower thoughts from Reddit API...")

reddit_data: requests.Response = requests.get(
"https://www.reddit.com/r/showerthoughts/top.json",
headers={"User-agent": "Showerthoughtbot 0.1"},
)

if len(reddit_data.json()["data"]["children"]) == 0:
logger.warning("No shower thoughts found in Reddit API response.")
return JSONResponse(response)

shower_thought: str = textwrap.fill(
(random.choice(reddit_data.json()["data"]["children"])["data"]["title"]), 50
)

response["data"] = shower_thought
except Exception as e:
logger.error(f"Error fetching shower thoughts: {e}")

return JSONResponse(response)
13 changes: 10 additions & 3 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
CALENDAR_URL = "https://calendar.google.com/calendar/ical/rti648k5hv7j3ae3a3rum8potk%40group.calendar.google.com/public/basic.ics"
CALENDAR_OUTLOOK_DAYS = 7 #The amount of days to go through
CALENDAT_EVENT_MAXIMUM = 10 #The amount of events needed to be displayed
import os
from dotenv import load_dotenv

load_dotenv()

BASE_DIR: str = os.path.dirname(os.path.abspath(__file__))

CALENDAR_URL: str | None = os.getenv("CALENDAR_URL", None)
CALENDAR_OUTLOOK_DAYS: int = int(os.getenv("CALENDAR_OUTLOOK_DAYS", "7"))
CALENDAT_EVENT_MAXIMUM: int = int(os.getenv("CALENDAT_EVENT_MAXIMUM", "10"))
2 changes: 0 additions & 2 deletions src/core/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def get_future_events_ical() -> list:
report_timing("FINISHED")
return returned_events

get_future_events_ical()

'''def get_future_events_google():
now = datetime.now()
events_result = calendar_service.events().list(
Expand Down
27 changes: 27 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,30 @@
Authors: Eli Mares,Nikolai Strong, Will Hellinger,
V1 Authors: Beckett Jenen
"""

import os

from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse


from config import BASE_DIR

from api import endpoints

app: FastAPI = FastAPI()

app.mount(
"/static",
StaticFiles(directory=os.path.join(BASE_DIR, "static")),
name="static"
)
templates = Jinja2Templates(directory=os.path.join(BASE_DIR, "templates"))

app.include_router(endpoints.router, prefix="/api")

@app.get("/", response_class=HTMLResponse)
async def read_index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
6 changes: 5 additions & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
fastapi==0.135.1
uvicorn==0.41.0
logging==0.4.9.6
jinja2==3.1.6
requests==2.32.5
dotenv==0.9.9
pyyaml==6.0.3
google-api-python-client==2.191.0
icalendar==7.0.3
recurring-ical-events==3.8.1
recurring-ical-events==3.8.1
10 changes: 5 additions & 5 deletions src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="theme-color" content="#B0197E">
<!-- Linking to stylesheets, scriptsheets, and apis -->
<link rel="stylesheet" href="https://assets.csh.rit.edu/csh-material-bootstrap/3.3.6/dist/csh-material-bootstrap.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', path='css/style.css') }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="shortcut icon" href="https://assets.csh.rit.edu/uploads/favicon.ico" type="image/x-icon">
Expand Down Expand Up @@ -83,7 +83,7 @@
$("body").css("background-image", "url(../static/css/darkmodeF.png)");
}

fetch('/calendar', {
fetch('/api/calendar', {
method: 'GET',
mode:'cors',
dataType: 'json'
Expand Down Expand Up @@ -120,7 +120,7 @@
}

function mediumUpdate(){
fetch('/showerthoughts', {
fetch('/api/showerthoughts', {
method: 'GET',
mode:'cors',
dataType: 'json'
Expand All @@ -131,7 +131,7 @@
})
.catch(err => console.log(err))

fetch('/get-announcement', {
fetch('/api/announcement', {
method: 'GET',
mode:'cors',
dataType: 'json'
Expand All @@ -144,7 +144,7 @@
}

function shortUpdate(){
fetch('/get-harold', {
fetch('/api/harold', {
method: 'GET',
mode:'cors',
dataType: 'json'
Expand Down