Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed calendar event parsing #3

Merged
merged 2 commits into from
Nov 19, 2023
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: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- Create our devpost submission text
- Move our processing to the scripts folder from the popups folder
- Implement the school's calendar for the classes
- Allow user to input semester start and end dates

### Timeline

Expand All @@ -69,7 +70,7 @@
- Install direnv following (mac can use `brew install direnv`) [its documentation](https://direnv.net/docs/installation.html)
- Set up direnv in your shell [its documentation](https://direnv.net/docs/hook.html)
- Create your `.envrc` file
- Add you client id as `export CLIENT_ID="YOUR_CLIENT_ID"` to your `.envrc` file after you set up the OAuth on [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
- Add you client id as `export CLIENT_ID=YOUR_CLIENT_ID` to your `.envrc` file after you set up the OAuth on [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
- Run `direnv allow`
- Run `npm run build`
- Go to `chrome://extensions/` in your browser
Expand Down
244 changes: 162 additions & 82 deletions popup/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,30 @@ document.getElementById('scrapeButton').addEventListener('click', async () => {
if (chrome.runtime.lastError) {
console.error('Script execution failed: ', chrome.runtime.lastError.message);
} else if (results && results.length > 0) {
const parserResults = results[0].result;
console.log('Parsed content:', parserResults);
// You can now do something with the parserResults

const courses = results[0].result;
console.log('Parsed content (courses):', courses);

// convert the courselist to a list of Google Calendar compatible events
events = []
courses.forEach(function (course) {
calendarEvents = courseToCalendarEvents(course)
calendarEvents.forEach(function(calendarEvent){
events.push(calendarEvent)
})

})
// chrome.storage.local.get('authToken', function (data) {
// if (chrome.runtime.lastError) {
// console.log('Error getting token from chrome.storage:', chrome.runtime.lastError);
// } else {
// let token = data.authToken;
// createCalendarEvent(token, parserResults);


// // add all the events to the user's Google Calendar
// events.forEach(function (calendarEvent) {
// createGCalendarEvent(token, parserResults);
// })
// }
// });
}
Expand All @@ -28,7 +43,7 @@ document.getElementById('scrapeButton').addEventListener('click', async () => {
}
});

function createCalendarEvent(authToken, event) {
function createGCalendarEvent(authToken, event) {
const calendarApiUrl = 'https://www.googleapis.com/calendar/v3/calendars/primary/events';

fetch(calendarApiUrl, {
Expand All @@ -49,6 +64,147 @@ function createCalendarEvent(authToken, event) {
});
}

function convertDateFormatToGCal(time, date) {
function convertTime12to24(time12h) {

const [time, modifier] = [time12h.substring(0, time12h.length-2), time12h.substring(time12h.length-2)];
let [hours, minutes] = time.split(':');

if (hours === '12') {
hours = '00';
}

if (modifier === 'pm') {
hours = parseInt(hours, 10) + 12;
}

return `${hours}:${minutes}`;
}

const time24 = convertTime12to24(time);

const dateTime = `${date}T${time24}:00`;

return dateTime;
}

// convert a course to a calendar event
function courseToCalendarEvents(course) {

const buildingAbbreviations = {
"AAS": "Boston University African American Studies, 138 Mountfort St, Brookline, MA 02446",
"AGG": "Agganis Arena, 925 Commonwealth Ave, Boston, MA 02215",
"ASC": "Elliot Cole Academic Support Center, 300 Ashford St, Boston, MA 02134",
"BRB": "Boston University Biology Research Building, 5 Cummington Mall, Boston, MA 02215",
"BSC": "Boston University Biological Science Center, 2 Cummington Mall, Boston, MA 02215",
"CAS": "College of Arts and Sciences, 685–725 Commonwealth Ave, Boston, MA 02215",
"CDS": "BU Faculty of Computing & Data Sciences, 645-665 Commonwealth Avenue, Boston, MA 02215",
"CFA": "College of Fine Arts, 855 Commonwealth Ave, Boston, MA 02215",
"CGS": "College of General Studies, 871 Commonwealth Ave, Boston, MA 02215",
"CNS": "Boston University Cognitive and Neural Systems Department, 677 Beacon St, Boston, MA 02215",
"COM": "College of Communication, 640 Commonwealth Ave, Boston, MA 02215",
"CRW": "Boston University DeWolfe Boathouse, 619 Memorial Dr, Cambridge, MA 02139",
"CSE": "285 Babcock St, Boston, MA 02215",
"EGL": "English Faculty Offices, 236 Bay State Road, Boston, MA 02215",
"EIB": "BU Editorial Institute, 143 Bay State Rd, Boston, MA 02215",
"EMA": "Boston University Engineering Manufacturing Annex, 730 Commonwealth Ave, Boston, MA 02215",
"EMB": "Boston University Engineering Manufacturing Building, 15 St Mary's St, Brookline, MA 02446",
"ENG": "College of Engineering, 110–112 Cummington Mall, Boston, MA 02215",
"EOP": "Center for English Language, 890 Commonwealth Avenue, Boston, MA 02215",
"EPC": "Engineering Product Innovation Center, 750 Commonwealth Ave, Brookline, MA 02446",
"ERA": "Boston University Engineering Research Annex, 48 Cummington Mall, Boston, MA 02215",
"ERB": "Boston University Engineering Research Building, 48 Cummington Mall, Boston, MA 02215",
"FAB": "BU Fenway Activities Building, 180 Riverway, Boston, MA 02215",
"FCB": "Fenway Classroom Building, 25 Pilgrim Rd, Boston, MA 02215",
"FCC": "Campus Center & Student Residence, 150 Riverway, Boston, MA 02215",
"FLR": "Boston University Peter Fuller Building, 808 Commonwealth Ave, Brookline, MA 02446",
"GMS": "Faculty Office Building (Alden Hall), 704 Commonwealth Avenue, Boston, MA 02215",
"GRS": "Graduate School of Arts and Sciences, 705 Commonwealth Ave, Boston, MA 02215",
"GSU": "George Sherman Union, 775 Commonwealth Ave, Boston, MA 02215",
"HAR": "Boston University Rafik B. Hariri Building, 595 Commonwealth Ave, Boston, MA 02215",
"HAW": "Hawes Building, 43 Hawes Street, Brookline, MA 02446",
"HIS": "History and American Studies Departments, 226 Bay State Rd, Boston, MA 02215",
"IEC": "Boston University International Programs, 888 Commonwealth Ave, Boston, MA 02215",
"IRB": "International Relations Building, 154 Bay State Rd, Boston, MA 02215",
"IRC": "International Relations Center, 152 Bay State Road, Boston, MA 02215",
"JSC": "Elie Wiesel Center for Jewish Studies, 147 Bay State Road, Boston, MA 02215",
"KCB": "Boston University Kenmore Classroom Building, 565 Commonwealth Ave, Boston, MA 02215",
"KHC": "Kilachand Honors College, 91 Bay State Rd # 115, Boston, MA 02215",
"LAW": "Boston University School of Law, 765 Commonwealth Ave, Boston, MA 02215",
"LEV": "Boston University Alan and Sherry Leventhal Center, 233 Bay State Rd, Boston, MA 02215",
"LNG": "Romance Studies/Modern Foreign Languages, 718 Commonwealth Avenue, Boston, MA 02215",
"LSE": "Boston University Life Science and Engineering Building, 24 Cummington Mall, Boston, MA 02215",
"MCH": "Boston University Marsh Chapel, 735 Commonwealth Ave, Boston, MA 02215",
"MCS": "Boston University Math and Computer Science, 111 Cummington Mall, Boston, MA 02215",
"MED": "Boston University School of Public Health, 715 Albany Street, Boston, MA 02118",
"MET": "Boston University Metropolitan College, 1010 Commonwealth Ave, Boston, MA 02215",
"MOR": "Alfred L. Morse Auditorium, 602 Commonwealth Ave, Boston, MA 02215",
"MUG": "Mugar Memorial Library, Gotlieb Archival Research Center, 771 Commonwealth Ave, Boston, MA 02215",
"PDP": "Physical Development Program, 915 Commonwealth Avenue, Boston, MA 02215",
"PHO": "Boston University Photonics Building, 6-8 St Mary's St, Boston, MA 02215",
"PLS": "Anthropology, Philosophy, Political Science, 232 Bay State Road, Boston, MA 02215",
"PRB": "Boston University Physics Research Building, 3 Cummington Mall, Boston, MA 02215",
"PSY": "Department of Psychological and Brain Sciences, 64–72–86 Cummington Mall # 149, Boston, MA 02215",
"PTH": "Boston Playwrights' Theatre, 949 Commonwealth Ave, Boston, MA 02215",
"REL": "CAS Religion, 145 Bay State Road, Boston, MA 02215",
"RKC": "Rajen Kilachand Center for Integrated Life Sciences & Engineering, 610 Commonwealth Ave, Boston, MA 02215",
"SAC": "Sargent Activities Office, 1 University Road, MA 02215",
"SAL": "Boston University Sailing Pavilion, Dr Paul Dudley White Bike Path, Boston, MA 02215",
"SAR": "Sargent College of Health and Rehabilitation Sciences, 635 Commonwealth Ave, Boston, MA 02215",
"SCI": "Metcalf Center for Science and Engineering, 590-596 Commonwealth Avenue, MA 02215",
"SDM": "Henry M. Goldman School of Dental Medicine, 100 East Newton Street, Boston, MA 02118",
"SHA": "Boston University School of Hospitality Administration, 928 Commonwealth Ave, Boston, MA 02215",
"SLB": "Science and Engineering Library, 30–38 Cummington Mall, MA 02215",
"SOC": "Department of Sociology, 96-100 Cummington Mall # 260, Boston, MA 02215",
"SPH": "Boston University School of Public Health, 715 Albany St, Boston, MA 02118",
"SSW": "School of Social Work, 264-270 Bay State Rd, Boston, MA 02215",
"STH": "School of Theology, 745 Commonwealth Ave, Boston, MA 02215",
"STO": "Stone Science Building, 675 Commonwealth Ave, Boston, MA 02215",
"THA": "Joan & Edgar Booth Theatre and College of Fine Arts Production Center, 820 Commonwealth Ave, Brookline, MA 02446",
"TTC": "Boston University Track & Tennis Center, 100 Ashford St, Boston, MA 02215",
"WEA": "Wheelock College of Education & Human Development Annex, 621 Commonwealth Avenue, Boston, MA 02215",
"WED": "Wheelock College of Education & Human Development, 2 Silber Way, Boston, MA 02215",
"YAW": "Boston University Yawkey Center for Student Services, 100 Bay State Rd, Boston, MA 02215"
};

const weekdayToInt = {
'Sun': 5,
'Mon': 6,
'Tue': 0,
'Wed': 1,
'Thu': 2,
'Fri': 3,
'Sat': 4
};

const semesterEndDate = "20231212T170000Z"


classDays = course['days'].split(',')

calendarEvents = []

classDays.forEach(function(classDay){
const firstDayofClass = "2023-09-0" + (5 + weekdayToInt[classDay])
calendarEvent = {
summary: course['code'].split(/\s+/)[1] + " " + course['type'] + " @" + course['code'].split(/\s+/)[0] + " " + course['room'],
location: buildingAbbreviations[course['location']],
recurrence: 'RRULE:FREQ=WEEKLY;UNTIL=' + semesterEndDate,
start: {
dateTime: convertDateFormatToGCal(course['start'], firstDayofClass),
timeZone: 'America/New_York'
},
end: {
dateTime: convertDateFormatToGCal(course['stop'], firstDayofClass),
timeZone: 'America/New_York'
},
}
calendarEvents.push(calendarEvent)
})

return calendarEvents
}

function parsePageContent() {
// Get the table with the course information
const courseTable = document.querySelectorAll('table')[4];
Expand Down Expand Up @@ -98,80 +254,4 @@ function parsePageContent() {
courses.push(course)
}
return courses;
}

const buildingAbbreviations = {
"AAS": "Boston University African American Studies, 138 Mountfort St, Brookline, MA 02446",
"AGG": "Agganis Arena, 925 Commonwealth Ave, Boston, MA 02215",
"ASC": "Elliot Cole Academic Support Center, 300 Ashford St, Boston, MA 02134",
"BRB": "Boston University Biology Research Building, 5 Cummington Mall, Boston, MA 02215",
"BSC": "Boston University Biological Science Center, 2 Cummington Mall, Boston, MA 02215",
"CAS": "College of Arts and Sciences, 685–725 Commonwealth Ave, Boston, MA 02215",
"CDS": "BU Faculty of Computing & Data Sciences, 645-665 Commonwealth Avenue, Boston, MA 02215",
"CFA": "College of Fine Arts, 855 Commonwealth Ave, Boston, MA 02215",
"CGS": "College of General Studies, 871 Commonwealth Ave, Boston, MA 02215",
"CNS": "Boston University Cognitive and Neural Systems Department, 677 Beacon St, Boston, MA 02215",
"COM": "College of Communication, 640 Commonwealth Ave, Boston, MA 02215",
"CRW": "Boston University DeWolfe Boathouse, 619 Memorial Dr, Cambridge, MA 02139",
"CSE": "285 Babcock St, Boston, MA 02215",
"EGL": "English Faculty Offices, 236 Bay State Road, Boston, MA 02215",
"EIB": "BU Editorial Institute, 143 Bay State Rd, Boston, MA 02215",
"EMA": "Boston University Engineering Manufacturing Annex, 730 Commonwealth Ave, Boston, MA 02215",
"EMB": "Boston University Engineering Manufacturing Building, 15 St Mary's St, Brookline, MA 02446",
"ENG": "College of Engineering, 110–112 Cummington Mall, Boston, MA 02215",
"EOP": "Center for English Language, 890 Commonwealth Avenue, Boston, MA 02215",
"EPC": "Engineering Product Innovation Center, 750 Commonwealth Ave, Brookline, MA 02446",
"ERA": "Boston University Engineering Research Annex, 48 Cummington Mall, Boston, MA 02215",
"ERB": "Boston University Engineering Research Building, 48 Cummington Mall, Boston, MA 02215",
"FAB": "BU Fenway Activities Building, 180 Riverway, Boston, MA 02215",
"FCB": "Fenway Classroom Building, 25 Pilgrim Rd, Boston, MA 02215",
"FCC": "Campus Center & Student Residence, 150 Riverway, Boston, MA 02215",
"FLR": "Boston University Peter Fuller Building, 808 Commonwealth Ave, Brookline, MA 02446",
"GMS": "Faculty Office Building (Alden Hall), 704 Commonwealth Avenue, Boston, MA 02215",
"GRS": "Graduate School of Arts and Sciences, 705 Commonwealth Ave, Boston, MA 02215",
"GSU": "George Sherman Union, 775 Commonwealth Ave, Boston, MA 02215",
"HAR": "Boston University Rafik B. Hariri Building, 595 Commonwealth Ave, Boston, MA 02215",
"HAW": "Hawes Building, 43 Hawes Street, Brookline, MA 02446",
"HIS": "History and American Studies Departments, 226 Bay State Rd, Boston, MA 02215",
"IEC": "Boston University International Programs, 888 Commonwealth Ave, Boston, MA 02215",
"IRB": "International Relations Building, 154 Bay State Rd, Boston, MA 02215",
"IRC": "International Relations Center, 152 Bay State Road, Boston, MA 02215",
"JSC": "Elie Wiesel Center for Jewish Studies, 147 Bay State Road, Boston, MA 02215",
"KCB": "Boston University Kenmore Classroom Building, 565 Commonwealth Ave, Boston, MA 02215",
"KHC": "Kilachand Honors College, 91 Bay State Rd # 115, Boston, MA 02215",
"LAW": "Boston University School of Law, 765 Commonwealth Ave, Boston, MA 02215",
"LEV": "Boston University Alan and Sherry Leventhal Center, 233 Bay State Rd, Boston, MA 02215",
"LNG": "Romance Studies/Modern Foreign Languages, 718 Commonwealth Avenue, Boston, MA 02215",
"LSE": "Boston University Life Science and Engineering Building, 24 Cummington Mall, Boston, MA 02215",
"MCH": "Boston University Marsh Chapel, 735 Commonwealth Ave, Boston, MA 02215",
"MCS": "Boston University Math and Computer Science, 111 Cummington Mall, Boston, MA 02215",
"MED": "Boston University School of Public Health, 715 Albany Street, Boston, MA 02118",
"MET": "Boston University Metropolitan College, 1010 Commonwealth Ave, Boston, MA 02215",
"MOR": "Alfred L. Morse Auditorium, 602 Commonwealth Ave, Boston, MA 02215",
"MUG": "Mugar Memorial Library, Gotlieb Archival Research Center, 771 Commonwealth Ave, Boston, MA 02215",
"PDP": "Physical Development Program, 915 Commonwealth Avenue, Boston, MA 02215",
"PHO": "Boston University Photonics Building, 6-8 St Mary's St, Boston, MA 02215",
"PLS": "Anthropology, Philosophy, Political Science, 232 Bay State Road, Boston, MA 02215",
"PRB": "Boston University Physics Research Building, 3 Cummington Mall, Boston, MA 02215",
"PSY": "Department of Psychological and Brain Sciences, 64–72–86 Cummington Mall # 149, Boston, MA 02215",
"PTH": "Boston Playwrights' Theatre, 949 Commonwealth Ave, Boston, MA 02215",
"REL": "CAS Religion, 145 Bay State Road, Boston, MA 02215",
"RKC": "Rajen Kilachand Center for Integrated Life Sciences & Engineering, 610 Commonwealth Ave, Boston, MA 02215",
"SAC": "Sargent Activities Office, 1 University Road, MA 02215",
"SAL": "Boston University Sailing Pavilion, Dr Paul Dudley White Bike Path, Boston, MA 02215",
"SAR": "Sargent College of Health and Rehabilitation Sciences, 635 Commonwealth Ave, Boston, MA 02215",
"SCI": "Metcalf Center for Science and Engineering, 590-596 Commonwealth Avenue, MA 02215",
"SDM": "Henry M. Goldman School of Dental Medicine, 100 East Newton Street, Boston, MA 02118",
"SHA": "Boston University School of Hospitality Administration, 928 Commonwealth Ave, Boston, MA 02215",
"SLB": "Science and Engineering Library, 30–38 Cummington Mall, MA 02215",
"SOC": "Department of Sociology, 96-100 Cummington Mall # 260, Boston, MA 02215",
"SPH": "Boston University School of Public Health, 715 Albany St, Boston, MA 02118",
"SSW": "School of Social Work, 264-270 Bay State Rd, Boston, MA 02215",
"STH": "School of Theology, 745 Commonwealth Ave, Boston, MA 02215",
"STO": "Stone Science Building, 675 Commonwealth Ave, Boston, MA 02215",
"THA": "Joan & Edgar Booth Theatre and College of Fine Arts Production Center, 820 Commonwealth Ave, Brookline, MA 02446",
"TTC": "Boston University Track & Tennis Center, 100 Ashford St, Boston, MA 02215",
"WEA": "Wheelock College of Education & Human Development Annex, 621 Commonwealth Avenue, Boston, MA 02215",
"WED": "Wheelock College of Education & Human Development, 2 Silber Way, Boston, MA 02215",
"YAW": "Boston University Yawkey Center for Student Services, 100 Bay State Rd, Boston, MA 02215"
};
}
15 changes: 15 additions & 0 deletions popup/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body {
width: 200px; /* Set the width you want */
height: 100px; /* Set the height you want */
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100vh; /* Use the full height of the screen */
}

#login-container {
text-align: center; /* Center text for the inner content */
}
2 changes: 2 additions & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<head>
<meta charset="UTF-8">
<title>Sign in with Google</title>

<link rel="stylesheet" href="style.css">

</head>

<body>
Expand Down
6 changes: 4 additions & 2 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ document.getElementById('google-sign-in-btn').addEventListener('click', function
// Use the token for your API calls; we'll validate the token in the background script
document.getElementById('status-message').textContent = 'Sign in successful!';

window.location.href = "parser.html";
// // Save the token to chrome.storage

// Save the token to chrome.storage

// chrome.storage.local.set({ 'authToken': token }, function () {
// // Check for errors
// if (chrome.runtime.lastError) {
// console.log('Error setting token in chrome.storage:', chrome.runtime.lastError);
// } else {
// // Change to the parser window
window.location.href = "parser.html";
// }
// });
}
Expand Down