diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index bef2aded..ead579e4 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -2,7 +2,7 @@ name: Automatic Event Date Updater on: schedule: - - cron: "0 */4 * * *" + - cron: "0 0 * * *" workflow_dispatch: inputs: branch: diff --git a/app/api/eventsRefresher/route.ts b/app/api/eventsRefresher/route.ts new file mode 100644 index 00000000..7703470e --- /dev/null +++ b/app/api/eventsRefresher/route.ts @@ -0,0 +1,19 @@ +import { NextRequest, NextResponse } from "next/server"; +import {exec} from 'child_process'; +import path from "path"; +//api endpoint that executes google sheets python script when called (by vercel's cron job function) +let scriptPath = '/Users/gabewkung/UCSBTASA.github.io/scripts/script_2.py' +export async function GET(request: NextRequest) { + exec(`python3 ${scriptPath}`, (error, stdout, stderr) => { + if (error) { + console.error(`Error: ${error.message}`); + return NextResponse.json({status: `unsuccessful ${error.message}`}); + } + if (stderr) { + console.error(`Error: ${stderr}`); + return NextResponse.json({status: `Error: ${stderr}`}) + } + return NextResponse.json({status: "success", output: stdout}) + }) + return NextResponse.json({ message: 'cron job ran' }); +} diff --git a/app/page.tsx b/app/page.tsx index 302a7a5f..3d1c0fcc 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -5,8 +5,8 @@ import Carousel from "../components/carousel"; const Home = () => { return (
-
- +
+
); }; diff --git a/components/events.tsx b/components/events.tsx index c217045b..477c2d4e 100644 --- a/components/events.tsx +++ b/components/events.tsx @@ -2,13 +2,18 @@ import FadeInTransition from "./scroll-transition"; import events from "../data/eventData"; const Events = () => { - const formatTime = (time: string) => { - const [hours, minutes] = time.split(":"); - const hour = parseInt(hours, 10); - const amPm = hour >= 12 ? "PM" : "AM"; - const formattedHour = hour % 12 || 12; - return `${formattedHour}:${minutes} ${amPm}`; - }; + const formatTime = (timeRange: string) => { + const times = timeRange.split('-'); + const formattedTimes = times.map(time => { + const [hours, minutes] = time.split(":"); + const hour = parseInt(hours, 10); + const amPm = hour >= 12 ? "PM" : "AM"; + const formattedHour = hour % 12 || 12; + return `${formattedHour}:${minutes} ${amPm}`; + }); + return formattedTimes.join(' - '); + + }; const formatDate = (date: string) => { const options: Intl.DateTimeFormatOptions = { @@ -44,7 +49,7 @@ const Events = () => { const currentDate = new Date(); const futureDate = new Date(); futureDate.setDate(currentDate.getDate() - 1); - + const upcomingEvents = events.filter( (event) => new Date(event.date) >= futureDate ); @@ -80,7 +85,7 @@ const Events = () => {

Time: {event.customTime === "" ? ( - {event.time} PST + {formatTime(event.time)} PST ) : ( event.customTime )} diff --git a/data/eventData.ts b/data/eventData.ts index 23290086..340fed8e 100644 --- a/data/eventData.ts +++ b/data/eventData.ts @@ -1,227 +1,164 @@ const events = [ { - "title": "Speed Dating", - "day of week": "Friday", - "date": "2024-01-19", - "time": "8-9:30PM", - "location": "Lot 22/ Phelps 1160", - "customTime": "", - "ready": "Yes" - }, - { - "title": "GM #1", + "title": "99 Rising Tabling", "day of week": "Monday", - "date": "2024-01-22", - "time": "8-10PM", - "location": "TD-W 1701", + "date": "2025-9-29", + "time": "9:00-14:00", + "location": "HSSB Courtyard", "customTime": "", "ready": "Yes" }, { - "title": "Field Day", - "day of week": "Friday", - "date": "2024-01-26", - "time": "3-5PM", - "location": "Student Health Lawn", + "title": "Fall Kickoff General Meeting", + "day of week": "Thursday", + "date": "2025-10-09", + "time": "20:00-22:00", + "location": "Broida 1610", "customTime": "", "ready": "Yes" }, { - "title": "TFTI", + "title": "Big Little Pickup: Virtual Speed Dating", "day of week": "Saturday", - "date": "2024-01-27", - "time": "Overnight", - "location": "UCLA (Mesa Lawn)", - "customTime": "Overnight", - "ready": "Yes" - }, - { - "title": "Winter Big/Little Reveal", - "day of week": "Sunday", - "date": "2024-02-04", - "time": "2-4PM", - "location": "Top of Lot 22", + "date": "2025-10-11", + "time": "20:00-22:00", + "location": "Zoom", "customTime": "", "ready": "Yes" }, { - "title": "GM #2", + "title": "Big Little Pickup: In Person Speed Dating", "day of week": "Monday", - "date": "2024-02-05", - "time": "8-10PM", - "location": "TD-W 1701", + "date": "2025-10-13", + "time": "18:45-21:00", + "location": "Lot 22 Top Flor", "customTime": "", "ready": "Yes" }, { - "title": "TASA Online Game Night\n", - "day of week": "Wednesday", - "date": "2024-02-07", - "time": "8:00 PM", - "location": "Online (Discord)", + "title": "Big Little Pickup: Beach Day", + "day of week": "Tuesday", + "date": "2025-10-21", + "time": "14:00-16:00", + "location": "Goleta Beach", "customTime": "", "ready": "Yes" }, { - "title": "Mahjong Mocktails", - "day of week": "Thursday", - "date": "2024-02-08", - "time": "8-10PM ", - "location": "Girvetz 1115", - "customTime": "", - "ready": "Yes" - }, - { - "title": "NSU x TASA", + "title": "Big Little Pickup: Arts and Crafts Night", "day of week": "Friday", - "date": "2024-02-09", - "time": "5-7; 9-12AM", - "location": "Girvetz 1004", - "customTime": "", - "ready": "Yes" - }, - { - "title": "Lunar New Year Hotpot Night!", - "day of week": "Saturday", - "date": "2024-02-10", - "time": "6-9PM", - "location": "Multi Cultural Center", - "customTime": "", - "ready": "Yes" - }, - { - "title": "TASA Talks", - "day of week": "Thursday", - "date": "2024-02-15", - "time": "8-10PM", - "location": "Girvetz 1116", - "customTime": "", - "ready": "Yes" - }, - { - "title": "GM #1 w/ Hochaya", - "day of week": "Monday", - "date": "2024-04-08", - "time": "8-10PM", - "location": "TD-W 1701", - "customTime": "", - "ready": "Yes" - }, - { - "title": "TASA Talks", - "day of week": "Thursday", - "date": "2024-04-11", - "time": "8-10PM", - "location": "Girvetz 1115", + "date": "2025-10-24", + "time": "21:00-23:00", + "location": "SRB Multipurpose Room", "customTime": "", "ready": "Yes" }, { - "title": "Mahjong Night", - "day of week": "Friday", - "date": "2024-04-12", - "time": "6-8PM", - "location": "Arts 1349", + "title": "TASA x Vons Fundraiser", + "day of week": "Tuesday", + "date": "2025-11-04", + "time": "15:00-20:00", + "location": "Von's Chicken", "customTime": "", "ready": "Yes" }, { - "title": "Edible Campus Collab", - "day of week": "Saturday", - "date": "2024-04-13", - "time": "2-3PM", - "location": "St. Michael\u2019s University Church (6586 Picasso Rd)", + "title": "TASA Big Little Pickup Reveal", + "day of week": "Tuesday", + "date": "2025-11-04", + "time": "16:00-18:00", + "location": "Top of Lot 22", "customTime": "", "ready": "Yes" }, { - "title": "Maid Cafe", - "day of week": "Thursday", - "date": "2024-04-18", - "time": "6:30- 8:30PM", - "location": "ARTS 1356", + "title": "Tanghulu and Trivia Night", + "day of week": "Wednesday", + "date": "2025-11-05", + "time": "19:00-21:00", + "location": "SRB Multipurpose Room", "customTime": "", "ready": "Yes" }, { - "title": "VSA x TASA Collab", - "day of week": "Friday", - "date": "2024-04-19", - "time": "5-7PM", - "location": "ARTS 1349", + "title": "TASA Movie Night", + "day of week": "Sunday", + "date": "2025-11-09", + "time": "19:00-21:00", + "location": "TBD", "customTime": "", "ready": "Yes" }, { - "title": "TASA Talks", + "title": "TASA GM 3", "day of week": "Thursday", - "date": "2024-04-25", - "time": "8-10 PM", - "location": "girvetz 1115", + "date": "2025-11-13", + "time": "20:00-22:30", + "location": "Broida 1610", "customTime": "", "ready": "Yes" }, { - "title": "Night Market", - "day of week": "Saturday", - "date": "2024-05-04", - "time": "4-8PM", - "location": "Storke Plaza", + "title": "Fam Dumpling Kit Distribution", + "day of week": "Tuesday", + "date": "2025-11-18", + "time": "18:00-19:30", + "location": "Check TASA Messenger for details and location!", "customTime": "", "ready": "Yes" }, { - "title": "TASA Talks", - "day of week": "Thursday", - "date": "2024-05-09", - "time": "8-10 PM", - "location": "Girvetz 1115", - "customTime": "", + "title": "TASA Winter Retreat", + "day of week": "Monday", + "date": "2025-1-13", + "time": "Overnight", + "location": "Frazier Park", + "customTime": "Overnight", "ready": "Yes" }, { - "title": "GM #3: Elections", - "day of week": "Monday", - "date": "2024-05-20", - "time": "8-10 PM", + "title": "Winter GM 1 W/ Hochaya", + "day of week": "Wednesday", + "date": "2025-1-22", + "time": "20:00-22:00", "location": "TD-W 1701", "customTime": "", "ready": "Yes" }, { - "title": "TASA Talks", - "day of week": "Thursday", - "date": "2024-05-23", - "time": "8-10 PM", - "location": "Girvetz 1115", - "customTime": "", + "title": "Pickup Coloring Night!", + "day of week": "Friday", + "date": "2025-1-24", + "time": "TBD", + "location": "Arts 1353, 1356, 1349", + "customTime": "TBD", "ready": "Yes" }, { - "title": "Banquet", - "day of week": "Thursday", - "date": "2024-05-30", - "time": "7-9 PM", - "location": "Mosher Alumni House", - "customTime": "", + "title": "Field Day!", + "day of week": "Sunday", + "date": "2025-1-26", + "time": "TBD", + "location": "Student Health Lawn", + "customTime": "TBD", "ready": "Yes" }, { - "title": "Senior Appreciation", - "day of week": "Friday", - "date": "2024-05-31", - "time": "4-6 PM", - "location": "ARTS 1353", - "customTime": "", + "title": "TASA x UCLA TFTI", + "day of week": "Monday", + "date": "2025-1-27", + "time": "Overnight", + "location": "UCLA", + "customTime": "Overnight", "ready": "Yes" }, { - "title": "TASA Talks", - "day of week": "Thursday", - "date": "2024-06-06", - "time": "8-10 PM", - "location": "Girvetz 1115", + "title": "Winter GM #2", + "day of week": "Wednesday", + "date": "2025-2-5", + "time": "20:00-22:00", + "location": "TD-W 1701", "customTime": "", "ready": "Yes" } diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03d..fd36f949 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,5 +1,6 @@ /// /// +/// // NOTE: This file should not be edited // see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/scripts/script_2.py b/scripts/script_2.py old mode 100644 new mode 100755 index d77df98a..e583c98b --- a/scripts/script_2.py +++ b/scripts/script_2.py @@ -1,4 +1,4 @@ -import gspread +import gspread import pandas as pd import json import datetime @@ -12,36 +12,51 @@ def changeDate(date): if (date.rfind('-') + 2 == len(date)): date = date[0:-1] + "0" + date[-1] return str(year) + "-" + date +# date (mm-dd-yy) => day of the week +def dayOfTheWeek(date): + try: + # Check if the date string fits the format %Y-%m-%d + date_object = datetime.datetime.strptime(date, "%Y-%m-%d") + return date_object.strftime("%A") + except ValueError: + return "Invalid date format. Please use YYYY-MM-DD." # Getting current year today = datetime.date.today() year = today.year + # Communicating with Google Sheets API, open the Google Sheet -service_account_path = "service_account.json" +service_account_path = "/Users/gabewkung/Downloads/ucsb-tasa-events-spreadsheet-69ab3e8df759.json" +spreadsheet_name = "TASA Event Data 24-25" + +gc = gspread.service_account(service_account_path) +sh = gc.open(spreadsheet_name) + -gc = gspread.service_account(filename = service_account_path) -sh = gc.open("TASA Scheduling 23-24") # Get the current sheet of interest and its records -sheet_instance = sh.get_worksheet(4) +sheet_instance = sh.get_worksheet(0) records_data = sheet_instance.get_all_records() # Convert to pandas DataFrame records_df = pd.DataFrame.from_dict(records_data) # Convert DataFrame to JSON format +# debugger: records_df => columns => T: Index => values: ndarray => [0:L]: list events = [] +print(records_df.iterrows()) for index, row in records_df.iterrows(): event = { - "title": row["Event name"], - "day of week": row["Day of week"], - "date": row["Date"], - "time": row["Time"], + "title": row["Name of Event"], + "day of week": dayOfTheWeek(row["Date (YYYY-MM-DD)"]), + "date": row["Date (YYYY-MM-DD)"], + "time": (row["Start Time"] + "-" + row["End Time"]) if row["End Time"] != "" else row["Start Time"], "location": row["Location"], "customTime" : "", - "ready" : row["Ready to add to website?"] + "ready" : "Yes" } # Changing the date to YYYY-MM-DD - event["date"] = changeDate(event["date"]) + #event["date"] = changeDate(event["date"]) + # Check cases in which customTime is necessary if (len(event["time"]) > 0): if not event["time"][0].isnumeric(): diff --git a/scripts/testscript.py b/scripts/testscript.py new file mode 100644 index 00000000..efea8338 --- /dev/null +++ b/scripts/testscript.py @@ -0,0 +1,23 @@ +import gspread +import os; +import json; +from oauth2client.service_account import ServiceAccountCredentials +import pandas as pd +# problem with path, likely in macos permissions +path = '/Users/gabewkung/Downloads/ucsb-tasa-events-spreadsheet-69ab3e8df759.json' + +gp = gspread.service_account(path) +gsheet = gp.open('TASA Event Data 24-25') +worksheet = gsheet.get_worksheet(0) + +column = ['A', 'B', 'C', 'D', 'E'] + +def event(rowNum): + rowNum = str(rowNum) + for i in range(len(column)): + cell = column[i] + rowNum + print(worksheet.acell(cell).value) + +print(worksheet.row_values(20)) + + diff --git a/vercel.json b/vercel.json index 9049487a..571e713e 100644 --- a/vercel.json +++ b/vercel.json @@ -3,6 +3,13 @@ "app/api/hello/route.tsx": { "runtime": "vercel-node@2.3.0" } - } - } + }, + "crons": [ + { + "path": "/api/eventsRefresher", + "schedule": "0 0 * * *" + } + ] +} + \ No newline at end of file