Skip to content

Instantly share code, notes, and snippets.

@davidawad
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidawad/5f95ff6bf8eeb5f1cfda to your computer and use it in GitHub Desktop.
Save davidawad/5f95ff6bf8eeb5f1cfda to your computer and use it in GitHub Desktop.
My proof of concept for the webreg scraper that i built with frank porco a while ago.

Proof Of Concept!

This is the html page generated by the javascript html sca ###How It Works### So you have to have webreg open and our javascript applet will let you get a .ical file that you can run on the webreg calendar view so that you can get a .ical file that you can import into google calendar.

###Constraints### it doesn't support campus or room location yet

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
(function() { var script = document.createElement("SCRIPT"); script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'; script.type = 'text/javascript'; document.getElementsByTagName("head")[0].appendChild(script); var checkReady = function(callback) { if (window.jQuery) { callback(jQuery); } else { window.setTimeout(function() { checkReady(callback); }, 100); } }; checkReady(function($) { $(function() { var courses = $('div.ca,div.cd,div.b,div.nk,div.l,div.cm,div.u'); function bake (start, end, day, name, cherry) {var cheesecake = "\nBEGIN:VEVENT\nUID:" + cherry.toString() + "\nDTSTAMP:20130331T044700Z\nORGANIZER;CN=Rutgers:MAILTO:webreg@rutgers.edu"; var date = ""; if (day == "TU") {date = "20130528T";}else if (day == "WE") {date = "20130529T"; }else if (day == "TH") {date = "20130530T"; }else if (day == "FR") {date = "20130531T"; }else if (day == "MO") {date = "20130603T";} start = "DTSTART:".concat(date.concat(start)); end = "DTEND:".concat(date.concat(end)); cheesecake = cheesecake.concat("\n" + start + "\n" + end + "\n" + "SUMMARY:" + name + "\nRRULE:FREQ=WEEKLY;UNTIL=20130815T010101Z;BYDAY=" + day + "\nEND:VEVENT"); return cheesecake; } $('tr td').each(function (index, item) { if ($(item).children().length > 0) $($($(item).children()[0]).children()[0]).attr('day', index % 5); }); var output = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN"; var number = Math.floor((Math.random()*100)+1); courses.each(function(index, course){ var class_day = $(course).attr('day'); if (class_day === '0') { class_day = "MO"; } else if (class_day === '1') { class_day = "TU"; } else if (class_day === '2') { class_day = "WE"; } else if (class_day === '3') { class_day = "TH"; } else if (class_day === '4'){ class_day = "FR"; } var class_time = $(course).find("span.time").html(); var start = class_time.split(" - ")[0]; start = time_converter(start); var end = class_time.split(" - ") [1]; var class_name = $(course).find("b").html(); end = time_converter(end); var pumpkin = bake(start, end, class_day, class_name, number); number++; output += pumpkin; console.log("Pumpkin: " + pumpkin); output += "\nEND:VCALENDAR"; var $popup = $('<div></div>'); $popup.css({ height: '50%', position: 'absolute', top: '25%', left: '25%', width: '50%', 'z-index' : 9998, }); var $textarea = $('<textarea></textarea>'); $textarea.css({ height: '90%',
width: '90%', 'z-index' : 9999, }); $popup.val("This is some text"); $textarea.val(output); $textarea.appendTo($popup); $popup.appendTo('body'); function time_converter(time) { var i = time.length - 2; var morning = true; var hours = 0; var minutes = 0; if (time.charAt(i) === 'P'){ morning = false; } time = time.substring(0, time.length - 2) ; if (time.charAt(1) === ':') { hours = Number(time.charAt(0)); time = time.substring(2, 4); } else { hours = Number(time.substring(0, 2)); time = time.substring(3, 5); } if (morning) { if (hours === 12) { hours = 0; } } else { if (!(hours === 12)) { hours += 12; } } minutes = Number(time); if (hours < 10) { hours = "0".concat(hours.toString()); } else { hours = hours.toString(); } if (minutes < 10) { minutes = "0".concat(minutes.toString()); } else { minutes = minutes.toString(); } return hours.concat(minutes.concat("00")); } }); }); }) })();
/*
//TODO: Get all the other data that you care about.
//console.log('fuck me');
// CHECK CALENDAR VIEW URL
//document.location.href.match("https://sims.rutgers.edu/webreg etc"
(function() {
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
}
else {
window.setTimeout(function() { checkReady(callback); }, 100);
}
};
checkReady(function($) {
$(function() {
var courses = $('div.ca,div.cd,div.b,div.nk,div.l,div.cm,div.u');
function bake (start, end, day, name, cherry) {//former make ical event
var cheesecake = "\nBEGIN:VEVENT\nUID:" + cherry.toString() + "\nDTSTAMP:20130331T044700Z\nORGANIZER;CN=Rutgers:MAILTO:webreg@rutgers.edu";
var date = "";
if (day == "TU") {
date = "20130528T";
}
else if (day == "WE") {
date = "20130529T";
}
else if (day == "TH") {
date = "20130530T";
}
else if (day == "FR") {
date = "20130531T";
}
else if (day == "MO") {
date = "20130603T";
}
start = "DTSTART:".concat(date.concat(start));
end = "DTEND:".concat(date.concat(end));
cheesecake = cheesecake.concat("\n" + start + "\n" + end + "\n" + "SUMMARY:" + name + "\nRRULE:FREQ=WEEKLY;UNTIL=20130815T010101Z;BYDAY=" + day + "\nEND:VEVENT");
return cheesecake;
}
$('tr td').each(function (index, item) {
if ($(item).children().length > 0)
$($($(item).children()[0]).children()[0]).attr('day', index % 5);
});
var output = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN";
var number = Math.floor((Math.random()*100)+1);
courses.each(function(index, course){
//console.log($(course).attr('day'));
var class_day = $(course).attr('day');
//console.log("class day: " + class_day);
if (class_day === '0') {
class_day = "MO";
}
else if (class_day === '1') {
class_day = "TU";
}
else if (class_day === '2') {
class_day = "WE";
}
else if (class_day === '3') {
class_day = "TH";
}
else if (class_day === '4'){
class_day = "FR";
}
var class_time = $(course).find("span.time").html();
//console.log(class_time);
var start = class_time.split(" - ")[0];
start = time_converter(start);
//console.log(time_converter(start));
var end = class_time.split(" - ") [1];
var class_name = $(course).find("b").html();
end = time_converter(end);
//console.log(class_name);
//console.log(class_day);
//console.log(bake(start, end, class_day, class_name));
var pumpkin = bake(start, end, class_day, class_name, number);
number++;
output += pumpkin;
console.log("Pumpkin: " + pumpkin);
//output += make_ical_event(start, end, class_day, class_name + " " + class_loc);
//console.log("fuck me again!!!!!!!!!----------------------");
});
output += "\nEND:VCALENDAR";
var $popup = $('<div></div>');
$popup.css({
height: '50%',
position: 'absolute',
top: '25%', //changed from 50
left: '25%',
width: '50%',
'z-index' : 9998,
});
var $textarea = $('<textarea></textarea>');
$textarea.css({
height: '90%',
width: '90%',
'z-index' : 9999,
});
$popup.val("This is some text");
$textarea.val(output);
$textarea.appendTo($popup);
$popup.appendTo('body');
function time_converter(time) {
var i = time.length - 2;
var morning = true;
var hours = 0;
var minutes = 0;
if (time.charAt(i) === 'P'){
morning = false;
}
time = time.substring(0, time.length - 2) ;
if (time.charAt(1) === ':') {
hours = Number(time.charAt(0));
time = time.substring(2, 4);
}
else {
hours = Number(time.substring(0, 2));
time = time.substring(3, 5);
}
if (morning) {
if (hours === 12) {
hours = 0;
}
}
else {
if (!(hours === 12)) {
hours += 12;
}
}
minutes = Number(time);
if (hours < 10) {
hours = "0".concat(hours.toString());
}
else {
hours = hours.toString();
}
if (minutes < 10) {
minutes = "0".concat(minutes.toString());
}
else {
minutes = minutes.toString();
}
return hours.concat(minutes.concat("00"));
}
});
});
})();
*/
</script>
<title>WebReg | View / Print Schedule</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen,print">
/* prevent IE less than 6 from seeing CSS by adding empty comment at end of import */
@import 'css/common.css'/**/;
@import 'css/wrs.css'/**/;
</style>
<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />
<!-- provide CSS to IE6 and above to fix rendering bugs; use conditional comments -->
<!--[if gte IE 6]><style type="text/css" media="screen">@import 'css/ie.css';</style><![endif]-->
</head>
<body class="schedule" id="grid">
<!-- $Id: scheduleGrid.jsp,v 1.35 2013/01/23 15:45:17 llevkovi Exp $ -->
<!-- $Id: header.jsp,v 1.9 2008/01/25 20:52:53 tako Exp $ -->
<h1 id="app-name">Web Registration System</h1>
<ul id="nav-system"
><li id="user">Logged in as ABANOUB AWAD (144003175)</li
><li id="logout"><a href="logout.htm">Log Out</a></li
></ul>
<div id="meta">
<p id="credits">SCHOOL OF ARTS AND SCIENCES | Attempting <span>8.0</span> credits | Completed <span>14.0</span> credits</p>
<h2><a href="chooseSemester.htm">Choose Semester</a> <span>&raquo;</span> Summer 2013</h2>
<!-- $Id: navTabs.html,v 1.3 2008/10/06 15:52:40 htorres Exp $ -->
<div class="tabs">
<ul
><li id="lookup"><a href="courseLookup.htm?_flowId=lookup-flow"><span>Course Lookup</span></a></li
><li id="manage"><a href="editSchedule.htm"><span>Manage Registration</span></a></li
><li id="view"><a href="viewSchedule.htm"><span>View / Print Schedule</span></a></li
></ul>
</div>
</div>
<div id="content">
<p class="filters">
<a href="#" class="print" onclick="window.print();return false;">print</a>
<b>View:</b> calendar | <a href="viewScheduleByCourse.htm">list by course</a> | <a href="viewScheduleByDay.htm">list by day</a>
</p>
<p class="filters">
<b class="legend">Campus Legend:</b> <span class="b">Busch</span> <span class="ca">College Avenue</span> <span class="cd">Cook / Douglass</span> <span class="l">Livingston</span> <span class="d">Downtown</span> <span class="cm">Camden</span> <span class="nk">Newark</span> <span class="u">Other/Unknown</span>
</p>
<table id="calendar" cellspacing="0">
<thead><tr><th class="first"></th><th class="monday">Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th>
</tr></thead>
<tbody>
<tr class="empty">
<th><div>8:00 AM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>9:00 AM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr >
<th><div>10:00 AM</div></th>
<td class="start"><div>
<div class="ca" style="height:115px; top:0px;" title="College Avenue"><span class="time">10:00 AM - 12:00 PM</span><b>CALC I MATH/PHYS</b>
<a class="ext" target="_new" href="http://rumaps.rutgers.edu/?q=3011">
MU-114</a>
<span class="print">Coll Ave</span>
</div>
</div></td>
<td class="start"><div>
<div class="ca" style="height:115px; top:0px;" title="College Avenue"><span class="time">10:00 AM - 12:00 PM</span><b>CALC I MATH/PHYS</b>
<a class="ext" target="_new" href="http://rumaps.rutgers.edu/?q=3011">
MU-114</a>
<span class="print">Coll Ave</span>
</div>
</div></td>
<td class="start"><div>
<div class="ca" style="height:115px; top:0px;" title="College Avenue"><span class="time">10:00 AM - 12:00 PM</span><b>CALC I MATH/PHYS</b>
<a class="ext" target="_new" href="http://rumaps.rutgers.edu/?q=3011">
MU-114</a>
<span class="print">Coll Ave</span>
</div>
</div></td>
<td class="start"><div>
<div class="ca" style="height:115px; top:0px;" title="College Avenue"><span class="time">10:00 AM - 12:00 PM</span><b>CALC I MATH/PHYS</b>
<a class="ext" target="_new" href="http://rumaps.rutgers.edu/?q=3011">
MU-114</a>
<span class="print">Coll Ave</span>
</div>
</div></td>
<td></td>
</tr>
<tr >
<th><div>11:00 AM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>12:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>1:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>2:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>3:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>4:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>5:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr >
<th><div>6:00 PM</div></th>
<td></td>
<td class="start"><div>
<div class="b" style="height:155px; top:0px;" title="Busch"><span class="time">6:00 PM - 8:40 PM</span><b>INTRO COMPUTER SCI</b>
<a class="ext" target="_new" href="http://rumaps.rutgers.edu/?q=3556">
WL-AUD</a>
<span class="print">Busch</span>
</div>
</div></td>
<td></td>
<td class="start"><div>
<div class="b" style="height:155px; top:0px;" title="Busch"><span class="time">6:00 PM - 8:40 PM</span><b>INTRO COMPUTER SCI</b>
<a class="ext" target="_new" href="http://rumaps.rutgers.edu/?q=3556">
WL-AUD</a>
<span class="print">Busch</span>
</div>
</div></td>
<td></td>
</tr>
<tr >
<th><div>7:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr >
<th><div>8:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>9:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="empty">
<th><div>10:00 PM</div></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<!-- $Id: footer.html,v 1.1 2008/01/25 20:52:53 tako Exp $ -->
<div id="footer">
<p>For questions, comments or suggestions contact <a href="http://rucs.camden.rutgers.edu/">Camden Help Desk</a>, <a href="http://www.ncs.rutgers.edu/helpdesk/">Newark Help Desk</a>, or <a href="http://www.nbcs.rutgers.edu/helpdesk/hdnew/">New Brunswick/Piscataway Help Desk</a>.</p>
<p>Visit web sites for <a href="http://www.camden.rutgers.edu/">Camden campus</a>, <a href="http://www.newark.rutgers.edu/">Newark campus</a>, <a href="http://nb.rutgers.edu/">New Brunswick/Piscataway campus</a>, or <a href="http://www.rutgers.edu">Rutgers University</a>.</p>
<a id="logo" href="http://www.rutgers.edu" title="go to Rutgers University home page"><img src="/webreg/images/ru_logo.gif" width="150" height="40" alt="Rutgers logo" /></a>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment