Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * slice and dice the list at http://en.wikipedia.org/wiki/List_of_situation_comedies
- */
- /*
- * country regexes
- */
- var usOnlyRgx = /united states/i;
- /*
- * other combos can be added in the parnethesis
- * for usAndUk separated by pipe symbols ("|")
- */
- var usAndUkRgx = /(united states|united kindom)/i;
- /* this is cheating a little - just lok for some alpha characters (ie: not blank) */
- var globalRgx = /[a-z]+/i;
- /* some storage */
- var result = [];
- var strResult = [];
- /* regex for splitting up the year (grumbles at mixed dash and mdash use...) */
- var yearRgx = /([0-9]{4})([\-–]([0-9]{4}|present))?/i;
- /*
- * This jQuery selector is funky to be very specific.
- * We are grabbing the middle column for each table row
- * because it's easy to look at previous and next siblings
- * to get the other two values.
- */
- $('#bodyContent .wikitable:first tbody:first tr td:nth-child(2)').each(function(idx, ele){
- var $country = $(ele);
- var country = $country.text()+'';
- var title = $country.prev().text()+'';
- var years = ($country.next().text()+'').match(yearRgx);
- var start, end;
- /*
- * replace the variable used in this condition to
- * change your country selection
- */
- if(!(usOnlyRgx).test(country)) {
- return;
- }
- /*
- * get the year range from our regular expression matches
- */
- start = typeof years[1] === 'string' ? parseInt(years[1], 10) : 0;
- if(typeof years[3] === 'string') {
- end = years[3].toLowerCase() === 'present' ? 2015 : parseInt(years[3], 10);
- } else {
- end = start;
- }
- if(start < 1990 && end < 1990) {
- //console.log('SKIP 1990 '+title, years);
- return;
- }
- if(start > 1999 && end > 1999) {
- //console.log('SKIP 2000 '+title, years);
- return;
- }
- /*
- * Add to our storage var as an object.
- * Really, you can do what you want here, but I'm going for objects.
- */
- result.push({
- 'title': title,
- 'country': country,
- 'start': start,
- 'end': end
- })
- /* for example, you could concat everything into a string */
- strResult += title+' ['+country+' '+start+' to '+end+']\n';
- //console.log('Added '+title, start+' to '+end);
- });
- console.log('strResult', strResult);
- console.log('result', result);
Advertisement
Add Comment
Please, Sign In to add comment