Created
September 20, 2013 23:22
-
-
Save ranyefet/6645214 to your computer and use it in GitHub Desktop.
Get Shabbat times from dat.gov.il
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This script created to generate a JSON of Shabbat Times from Dat.gov.il | |
* | |
* Usage: | |
* 1. Go to: http://www.dat.gov.il/religion/console/shabbat_hours.aspx | |
* 2. Open the Web Developer Console | |
* 3. Copy the code below ans paste it in and hit Enter | |
* 4. Enjoy the data | |
*/ | |
var timesScapper = { | |
// Will hold the data | |
data: [], | |
// Finds the times table | |
tableSelector: "#_ctl0_body_hours_tr table", | |
// Uses to load jQuery | |
loadJQuery: function(callback){ | |
var script = document.createElement('script') | |
,head=document.getElementsByTagName('head')[0], | |
done=false; | |
script.src='http://code.jquery.com/jquery-latest.min.js'; | |
// Attach handlers for all browsers | |
script.onload = script.onreadystatechange = function(){ | |
if ( !done && (!this.readyState || this.readyState === 'loaded' | |
|| this.readyState === 'complete') ) { | |
done=true; | |
callback(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
}, | |
// Get Week/Holiday times | |
getData: function( $tr ){ | |
var $tds = $tr.find('td'); | |
var getTdValByIndex = function(index){ | |
return jQuery.trim(jQuery($tds.get(index)).text()); | |
}; | |
var weekData = { | |
'date': getTdValByIndex(0), | |
'he_date': getTdValByIndex(1), | |
'parasha': getTdValByIndex(2), | |
'times': [ | |
{ | |
id: 1, | |
name: "Jerusalem", | |
inTime: getTdValByIndex(3), | |
outTime: getTdValByIndex(4) | |
}, | |
{ | |
id: 2, | |
name: "Tel Aviv", | |
inTime: getTdValByIndex(5), | |
outTime: getTdValByIndex(6) | |
}, | |
{ | |
id: 3, | |
name: "Be'er Sheva", | |
inTime: getTdValByIndex(7), | |
outTime: getTdValByIndex(8) | |
}, | |
{ | |
id: 4, | |
name: "Haifa", | |
inTime: getTdValByIndex(9), | |
outTime: getTdValByIndex(10) | |
} | |
] | |
}; | |
return weekData; | |
}, | |
// populate the data | |
populate: function(){ | |
var _this = this; | |
jQuery(this.tableSelector) | |
.find('tr') | |
.each(function(){ | |
var $tr = jQuery(this); | |
if( !$tr.hasClass('style20') && !$tr.hasClass('style21') ){ | |
_this.data.push(_this.getData($tr)); | |
} | |
}); | |
}, | |
setup: function(){ | |
var _this = this; | |
this.loadJQuery(function(){ | |
_this.populate(); | |
console.log(JSON.stringify(_this.data)); | |
}); | |
} | |
}; | |
timesScapper.setup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment