Skip to content

Commit

Permalink
Ready for Production!? (#36)
Browse files Browse the repository at this point in the history
* Fix calendar subscribe url

* Redirect home page to `all`

* Back button dark mode
  • Loading branch information
devinmatte authored May 5, 2024
1 parent 3bafc31 commit 07c0a2c
Show file tree
Hide file tree
Showing 13 changed files with 447 additions and 321 deletions.
3 changes: 2 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FRONTEND_HOSTNAME="mbtashutdowns.info"
FRONTEND_ZONE="mbtashutdowns.info"
FRONTEND_BUCKET="$FRONTEND_HOSTNAME"

BACKEND_HOSTNAME="shutdowns-api.labs.transitmatters.org"
BACKEND_HOSTNAME="shutdowns.labs.transitmatters.org"
BACKEND_ZONE="labs.transitmatters.org"
BACKEND_BUCKET=shutdown-tracker-backend
BACKEND_CERT_ARN="$TM_LABS_WILDCARD_CERT_ARN"
Expand Down Expand Up @@ -52,6 +52,7 @@ aws cloudformation deploy --template-file cfn/packaged.yaml --stack-name $STACK_

popd > /dev/null
aws s3 sync dist/ s3://$FRONTEND_BUCKET
aws s3 cp src/constants/shutdowns.json s3://$FRONTEND_BUCKET

# Grab the cloudfront ID and invalidate its cache
CLOUDFRONT_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items!=null] | [?contains(Aliases.Items, '$FRONTEND_HOSTNAME')].Id | [0]" --output text)
Expand Down
286 changes: 143 additions & 143 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@headlessui/react": "^1.7.19",
"@heroicons/react": "^2.1.3",
"@tanstack/react-query": "^5.31.0",
"@tanstack/react-query": "^5.34.1",
"bezier-js": "^6.1.4",
"chart.js": "^4.4.2",
"chartjs-adapter-date-fns": "^3.0.0",
Expand All @@ -31,37 +31,37 @@
"classnames": "^2.5.1",
"concurrently": "^8.2.2",
"date-fns": "^3.6.0",
"dayjs": "^1.11.10",
"react": "^18.2.0",
"dayjs": "^1.11.11",
"react": "^18.3.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-dom": "^18.3.1",
"react-responsive": "^10.0.0",
"react-scroll": "^1.9.0",
"react-toggle-dark-mode": "^1.1.1",
"zustand": "^4.5.2"
},
"devDependencies": {
"@tanstack/router-devtools": "^1.29.2",
"@tanstack/router-vite-plugin": "^1.30.0",
"@tanstack/router-devtools": "^1.31.19",
"@tanstack/router-vite-plugin": "^1.31.18",
"@types/bezier-js": "^4.1.3",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@types/react-scroll": "^1.8.10",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.6",
"postcss": "^8.4.33",
"postcss": "^8.4.38",
"prettier": "3.2.5",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^5.2.10"
"vite": "^5.2.11"
}
}
287 changes: 176 additions & 111 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ license = "MIT"
[tool.poetry.dependencies]
python = "~3.12"
requests = "2.31.0"
boto3 = "^1.34.89"
datadog_lambda = "5.92.0"
ddtrace = "2.8.2"
boto3 = "^1.34.98"
datadog_lambda = "5.94.0"
ddtrace = "2.8.3"
icalendar = "^5.0.12"

[tool.poetry.dev-dependencies]
pip = ">=23.3"
chalice = "1.31.0"
flake8 = "^7.0.0"
black = "^24.4.0"
black = "^24.4.2"

[tool.black]
line-length = 120
Expand Down
4 changes: 2 additions & 2 deletions server/.chalice/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"env": "prod"
},
"api_gateway_custom_domain": {
"domain_name": "shutdowns-api.labs.transitmatters.org",
"domain_name": "shutdowns.labs.transitmatters.org",
"tls_version": "TLS_1_2",
"certificate_arn": ""
}
}
}
}
}
51 changes: 32 additions & 19 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from datetime import datetime
from zoneinfo import ZoneInfo
from icalendar import Calendar, Event
import json
import os
from chalice import Chalice, CORSConfig, ConvertToMiddleware, Response
from datadog_lambda.wrapper import datadog_lambda_wrapper
import requests
from urllib.parse import urlencode
from chalicelib import s3

EASTERN_TIME = ZoneInfo("US/Eastern")

app = Chalice(app_name="shutdown-tracker")

Expand Down Expand Up @@ -36,25 +40,34 @@ def calendar():
cal.add("prodid", "-//MBTA Shutdown Calendar//transitmatters.org//")
cal.add("version", "2.0")

# get the shutdowns
with open("../src/constants/shutdowns.json", "r") as f:
shutdowns = json.load(f)
lines = shutdowns.keys()
for line in lines:
for shutdown in shutdowns[line]:
event = Event()
event_name = f"MBTA {line} Line Shutdown {shutdown['start_station']} - {shutdown['end_station']}"
event.add("name", event_name)
event.add("summary", event_name)
event.add(
"description",
f"The MBTA {line} Line will be shut down between {shutdown['start_station']} and {shutdown['end_station']}. During this time the MBTA plans to make repairs and improvements to the line.",
)
event.add("dtstart", datetime.strptime(shutdown["start_date"], "%Y-%m-%d").date())
event.add("dtend", datetime.strptime(shutdown["stop_date"], "%Y-%m-%d").date())
event.add("color", line)

cal.add_component(event)
shutdowns_file = s3.download("shutdowns.json", compressed=False)
shutdowns = json.loads(shutdowns_file)

lines = shutdowns.keys()
for line in lines:
for shutdown in shutdowns[line]:
event = Event()
event_name = (
f"MBTA {line.capitalize()} Line Shutdown | {shutdown['start_station']} - {shutdown['end_station']}"
)
event.add("name", event_name)
event.add("summary", event_name)
event.add(
"description",
f"The MBTA {line.capitalize()} Line will be shut down between {shutdown['start_station']} and {shutdown['end_station']}. During this time the MBTA plans to make repairs and improvements to the line, and hopefully improve service. Read more at {shutdown['alert']}",
)

# Handle dates (set end date to day after stop date to include the whole day in the event)
start_date = datetime.strptime(shutdown["start_date"], "%Y-%m-%d").replace(tzinfo=EASTERN_TIME)
stop_date = datetime.strptime(shutdown["stop_date"], "%Y-%m-%d").replace(
tzinfo=EASTERN_TIME
) + datetime.timedelta(days=1)
event.add("dtstart", start_date.date())
event.add("dtend", stop_date.date())

event.add("color", line)

cal.add_component(event)

response = Response(body=cal.to_ical())
response.headers["Content-Disposition"] = "attachment; filename=calendar.ics"
Expand Down
17 changes: 17 additions & 0 deletions server/chalicelib/s3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import boto3
import botocore
import zlib

BUCKET = "mbtashutdowns.info"
s3 = boto3.client("s3", config=botocore.client.Config(max_pool_connections=15))


# General downloading/uploading
def download(key, encoding="utf8", compressed=True):
obj = s3.get_object(Bucket=BUCKET, Key=key)
s3_data = obj["Body"].read()
if not compressed:
return s3_data.decode(encoding)
# 32 should detect zlib vs gzip
decompressed = zlib.decompress(s3_data, zlib.MAX_WBITS | 32).decode(encoding)
return decompressed
4 changes: 2 additions & 2 deletions server/cloudformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"TMBackendHostname": {
"Type": "String",
"Default": "shutdowns-api.labs.transitmatters.org",
"Default": "shutdowns.labs.transitmatters.org",
"AllowedPattern": "^.*\\.labs\\.transitmatters\\.org$",
"Description": "The backend api hostname for the shutdown tracker"
},
Expand Down Expand Up @@ -209,4 +209,4 @@
"Description": "URL for website hosted on S3"
}
}
}
}
2 changes: 1 addition & 1 deletion src/api/traveltimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

const APP_DATA_BASE_PATH =
process.env.NODE_ENV === 'production'
? 'https://shutdowns-api.labs.transitmatters.org'
? 'https://shutdowns.labs.transitmatters.org'
: 'http://127.0.0.1:5000';

export const getCurrentDate = (): string => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Shutdowns/ShutdownDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ const ShutdownDetails = ({
// Back button to exit the details page
const PageBackButton = () => {
return (
<div className="flex flex-row items-center cursor-pointer" onClick={handleBack}>
<div
className="flex flex-row items-center cursor-pointer dark:text-white"
onClick={handleBack}
>
<ArrowLeftIcon className="h-4 px-1" />
<h3>Back</h3>
</div>
Expand Down
Loading

0 comments on commit 07c0a2c

Please sign in to comment.