Guest User

Get the sitcoms

a guest
Jun 5th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * slice and dice the list at http://en.wikipedia.org/wiki/List_of_situation_comedies
  3. */
  4.  
  5. /*
  6. * country regexes
  7. */
  8. var usOnlyRgx = /united states/i;
  9. /*
  10. * other combos can be added in the parnethesis
  11. * for usAndUk separated by pipe symbols ("|")
  12. */
  13. var usAndUkRgx = /(united states|united kindom)/i;
  14. /* this is cheating a little - just lok for some alpha characters (ie: not blank) */
  15. var globalRgx = /[a-z]+/i;
  16.  
  17. /* some storage */
  18. var result = [];
  19. var strResult = [];
  20.  
  21. /* regex for splitting up the year (grumbles at mixed dash and mdash use...) */
  22. var yearRgx = /([0-9]{4})([\-–]([0-9]{4}|present))?/i;
  23.  
  24. /*
  25. * This jQuery selector is funky to be very specific.
  26. * We are grabbing the middle column for each table row
  27. * because it's easy to look at previous and next siblings
  28. * to get the other two values.
  29. */
  30. $('#bodyContent .wikitable:first tbody:first tr td:nth-child(2)').each(function(idx, ele){
  31.   var $country = $(ele);
  32.   var country = $country.text()+'';
  33.   var title = $country.prev().text()+'';
  34.   var years = ($country.next().text()+'').match(yearRgx);
  35.   var start, end;
  36.  
  37.   /*
  38.   * replace the variable used in this condition to
  39.   * change your country selection
  40.   */
  41.   if(!(usOnlyRgx).test(country)) {
  42.     return;
  43.   }
  44.  
  45.   /*
  46.   * get the year range from our regular expression matches
  47.   */
  48.   start = typeof years[1] === 'string' ? parseInt(years[1], 10) : 0;
  49.   if(typeof years[3] === 'string') {
  50.     end = years[3].toLowerCase() === 'present' ? 2015 : parseInt(years[3], 10);
  51.   } else {
  52.     end = start;
  53.   }
  54.  
  55.   if(start < 1990 && end < 1990) {
  56.     //console.log('SKIP 1990 '+title, years);
  57.     return;
  58.   }
  59.  
  60.   if(start > 1999 && end > 1999) {
  61.     //console.log('SKIP 2000 '+title, years);
  62.     return;
  63.   }
  64.  
  65.   /*
  66.   * Add to our storage var as an object.
  67.   * Really, you can do what you want here, but I'm going for objects.
  68.   */
  69.   result.push({
  70.     'title': title,
  71.     'country': country,
  72.     'start': start,
  73.     'end': end
  74.   })
  75.  
  76.   /* for example, you could concat everything into a string */
  77.   strResult += title+' ['+country+' '+start+' to '+end+']\n';
  78.  
  79.   //console.log('Added '+title, start+' to '+end);
  80. });
  81.  
  82. console.log('strResult', strResult);
  83. console.log('result', result);
Advertisement
Add Comment
Please, Sign In to add comment