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
8 changes: 7 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ CALENDAR_OUTLOOK_DAYS=
CALENDAR_EVENT_MAXIMUM=
CALENDAR_CACHE_REFRESH=
CALENDAR_TIMEZONE=

WATCHED_CHANNELS=
SLACK_API_TOKEN=
SLACK_JUMPSTART_MESSAGE=
SLACK_JUMPSTART_MESSAGE=

WIKI_API=
WIKIBOT_USER=
WIKIBOT_PASSWORD=
WIKI_CATEGORY=
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# TODO
- Add a link the mkDocs we do

# Jumpstart V2: Electric Boogaloo
# Jumpstart

![image](./docs/images/jumpstart_transparant.png)

![Static Badge](https://img.shields.io/badge/%40gravy-made_by?style=flat-square&logo=github&labelColor=%230d1117&color=%23E11C52&link=https%3A%2F%2Fgithub.com%2FNikolaiStrong)


A graphical interface that displays important information at the entrance of CSH.
This is a backend re-write of the previous jumpstart.
A graphical interface that displays information in the elevator lobby of Computer Science House.
All information displayed has been authorized to been shown.

This project uses Python, [FastAPI](https://fastapi.tiangolo.com/), HTML/CSS, and Javascript.
See it live [here](http://jumpstart-squared.cs.house/)!

See it live [here](https://jumpstart.csh.rit.edu)!
## Installing
1. Clone and cd into the repo: git clone https://github.com/WeatherGod3218/jumpstartV2
>> (OPTIONAL): Make another branch if your working on a large thing!

## Setup
1. Make sure you have docker installed
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ services:
- CALENDAR_OUTLOOK_DAYS=${CALENDAR_OUTLOOK_DAYS}
- CALENDAR_EVENT_MAXIMUM=${CALENDAR_EVENT_MAXIMUM}
- CALENDAR_TIMEZONE=${CALENDAR_TIMEZONE}

- WATCHED_CHANNELS=${WATCHED_CHANNELS}
- SLACK_API_TOKEN=${SLACK_API_TOKEN}
- SLACK_JUMPSTART_MESSAGE=${SLACK_JUMPSTART_MESSAGE}

- WIKI_API=${WIKI_API}
- WIKIBOT_USER=${WIKIBOT_USER}
- WIKIBOT_PASSWORD=${WIKIBOT_PASSWORD}
- WIKI_CATEGORY=${WIKI_CATEGORY}
53 changes: 14 additions & 39 deletions src/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
import httpx
import random
import textwrap
import asyncio

from fastapi import APIRouter, Request, Form
from fastapi.responses import JSONResponse

from core import slack, cshcalendar
from core import slack, cshcalendar, wikithoughts

logger: Logger = getLogger(__name__)
router: APIRouter = APIRouter()


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

Returns:
JSONResponse: A JSON response containing the calendar data.
"""

get_future_events_ical: tuple[cshcalendar.CalendarInfo] = asyncio.run(
cshcalendar.get_future_events()
)
get_future_events_ical: tuple[
cshcalendar.CalendarInfo
] = await cshcalendar.get_future_events()
formatted_events: dict = cshcalendar.format_events(get_future_events_ical)

return JSONResponse(formatted_events)
Expand Down Expand Up @@ -58,14 +57,14 @@ async def slack_events(request: Request) -> JSONResponse:

try:
logger.info("Received Slack event!")


body: dict = await request.json()
if request.headers.get("content-type") == "application/json":
body: dict = await request.json()


if body.get("type") == "url_verification":
return JSONResponse({"challenge": body.get("challenge")})

body: dict = await request.json()
if not body:
return JSONResponse({"challenge": body.get("challenge")})

Expand Down Expand Up @@ -129,38 +128,14 @@ async def message_actions(payload: str = Form(...)) -> JSONResponse:
return JSONResponse({"status": "success"}, status_code=200)


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

Returns:
JSONResponse: A JSON response containing a random shower thought.
JSONResponse: A JSON response containing a random Wiki thought.
"""
returned_page_data: dict[str, str] = await wikithoughts.get_next_display()
return JSONResponse(returned_page_data)

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

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

async with httpx.AsyncClient() as client:
reddit_data: httpx.Response = await client.get(
"https://www.reddit.com/r/showerthoughts/top.json",
headers={"User-agent": "Showerthoughtbot 0.1"},
)

reddit_json = reddit_data.json()

if len(reddit_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_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)
5 changes: 5 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
CALENDAR_TIMEZONE: str = os.getenv("CALENDAR_TIMEZONE", "America/New_York")
CALENDAR_CACHE_REFRESH: int = int(os.getenv("CALENDAR_CACHE_REFRESH", "10"))

WIKI_API: str | None = os.getenv("WIKI_API", None)
WIKIBOT_USER: str | None = os.getenv("WIKIBOT_USER", None)
WIKIBOT_PASSWORD: str | None = os.getenv("WIKIBOT_PASSWORD", None)
WIKI_CATEGORY: str = os.getenv("WIKI_CATEGORY", "JobAdvice")

if SLACK_API_TOKEN in (None, ""):
raise Exception("Missing SLACK_API_TOKEN")

Expand Down
Loading
Loading