Commits

Anonymous committed 21abda2

Comments (0)

Files changed (5)

 ========================
  * Realized that the previous attempt at improving episoder was flawed
  * Rewrote the whole thing in python
+ * Wrote a brand new tv.com parser
+ * Small fixes in the epguides.com parser
  * Parsed data is now stored in an sqlite3 database
 
 v0.5.0-RC2 (06 Nov 2008)
   -i			ignore date
   -n <days>		number of future days to show (default: 2),
 			relative to the date set with -d
-  -s <string>		search database for string (NOT IMPLEMENTED YET)
+  -s <text>		search database for text (NOT IMPLEMENTED YET)
 
 Note that -i overrules -d and -n
 

extras/episoder_helper_epguides.awk

 /^ *[0-9]+\./ {
 	totalep = substr ($1, 0, index($1, "."))
 	gsub (/\.$/, "", totalep)
-	epnum = substr($0, 10, 2)
+	epnum = substr($0, index($0, "-")+1, 2)
+
 	if (epnum < 10) {
 		epnum = 0 substr(epnum, 2, 1)
 	}

pyepisoder/episoder.py

 		return episodes
 
 	def addEpisode(self, show, episode):
-		num = episode['episode']
-		airdate = episode['airdate']
-		season = episode['season']
-		title = episode['title']
-		totalnum = episode['totalepnum']
-		prodnum = episode['prodnum']
+		num = episode.episode
+		airdate = episode.airdate
+		season = episode.season
+		title = episode.title
+		totalnum = episode.total
+		prodnum = episode.prodnum
 
 		self.conn.execute('INSERT INTO episodes VALUES (?, ?, ?, ?,' +
 				'?, ?, ?)', [show, num, airdate, season, title,
 class Episode(object):
 	def __init__(self, show, title, season, episode, airdate, prodnum,
 			total):
-		self.title = title
-		self.season = season
+		self.show = show
+		self.title = str(title)
+		self.season = int(season)
 		self.episode = int(episode)
 		self.airdate = airdate
 		self.prodnum = str(prodnum)
-		self.total = total
-		self.show = show
+		self.total = int(total)
+
+	def _setAirDate(self, airdate):
+		self._airdate = airdate.isoformat()
+
+	def _getAirDate(self):
+		return self._airdate
+
+	def _setSeason(self, season):
+		self._season = int(season)
+
+	def _getSeason(self):
+		return self._season
+
+	def _setEpisode(self, episode):
+		self._episode = int(episode)
+
+	def _getEpisode(self):
+		return self._episode
+
+	def _setTotal(self, total):
+		self._total = int(total)
+
+	def _getTotal(self):
+		return self._total
 
 	def __str__(self):
 		return "%s %dx%02d: %s" % (self.show.name, self.season,
 				self.episode, self.title)
 
+	airdate = property(_getAirDate, _setAirDate)
+	season = property(_getSeason, _setSeason)
+	episode = property(_getEpisode, _setEpisode)
+	total = property(_getTotal, _setTotal)
+
 class Show(object):
 	def __init__(self, name, id=-1):
 		self.name = name

pyepisoder/plugins.py

 import datetime
 
 from BeautifulSoup import BeautifulSoup
+from episoder import Episode
 
 def all():
 	return {
 class EpguidesParser(object):
 	def __init__(self):
 		self.logger = logging.getLogger('EpguidesParser')
-		self.awkfile = '/home/stefan/projects/episoder/trunk/episoder/plugins/episoder_helper_epguides.awk'
+		self.awkfile = '/home/stefan/projects/episoder/branches/0.5/extras/episoder_helper_epguides.awk'
 		self.awk = '/usr/bin/awk'
 
 	def __str__(self):
 
 		for episode in episodes:
 			self.logger.debug('Found episode %s' % episode['title'])
-			self.store.addEpisode(show_id, episode)
+			self.store.addEpisode(show_id, Episode(show_id,
+					episode['title'],
+					episode['season'],
+					episode['episode'],
+					episode['airdate'],
+					episode['prodnum'],
+					episode['totalepnum']
+				))
 
 class TVComDummyParser(object):
 	def __str__(self):
 		return re.match('http://(www.)?tv.com/\w+/show/\d+/?', url)
 
 	def parse(self, source, store):
+		self.store = store
+		self.episodes = {}
+		self.show = None
+		# need to get episode.html?season=All and
+		# episode.html?season=All&shv=guide
 		url = source['url']
 
 		if 'name' in source:
 	def parseFile(self, filename, store, name=None):
 		self.store = store
 		self.episodes = {}
+		self.show = None
 
 		file = open(filename)
 		data = file.read()
 			self.logger.debug('This is a guide view page')
 			self.parseGuideViewPage(soup)
 
+		show_id = self.store.addShow(self.show)
+		for key in self.episodes:
+			self.store.addEpisode(show_id, self.episodes[key])
+
+		self.store.commit()
+
 	def parseListViewPage(self, soup):
+		h1 = soup.find('h1')
+		show_name = h1.contents[0]
+		self.show = show_name
+		self.logger.debug('Got show "%s"' % show_name)
+
 		elements = soup.findAll('tr', { 'class': 'episode' })
 
 		for element in elements:
 					(totalepnum, id))
 
 			if not id in self.episodes:
-				self.episodes[id] = {}
+				#self.episodes[id] = {}
+				self.episodes[id] = Episode(None, None, 0,
+					0, datetime.date.today(), None, 0)
 
-			self.episodes[id]['prodnum'] = prodnum
-			self.episodes[id]['totalepnum'] = totalepnum
+			self.episodes[id].prodnum = prodnum
+			self.episodes[id].total = totalepnum
 
 	def parseGuideViewPage(self, soup):
 		h1 = soup.find('h1')
 		show_name = h1.contents[0]
+		self.show = show_name
 		self.logger.debug('Got show "%s"' % show_name)
 
 		elements = soup.findAll('li',
 
 			season = result.group(1)
 			episode_num = result.group(2)
-			airdate = result.group(3)
+			airdate = datetime.datetime.strptime(result.group(3),
+					"%m/%d/%Y").date()
 
 			h3 = element.find('h3')
 			link = h3.find('a')
 			id = int(parts[-2])
 
 			if not id in self.episodes:
-				self.episodes[id] = {}
-			self.episodes[id]['season'] = season
-			self.episodes[id]['episode'] = episode_num
-			self.episodes[id]['airdate'] = airdate
-			self.episodes[id]['title'] = title
+				self.episodes[id] = Episode(None, None, 0,
+					0, datetime.date.today(), None, 0)
 
-			self.logger.debug('Found episode %s (%d)' %
-					(title, id))
+			self.episodes[id].season = season
+			self.episodes[id].episode = episode_num
+			self.episodes[id].airdate = airdate
+			self.episodes[id].title = title
+
+			self.logger.debug('Found episode %s (%d)' % (title, id))
 
 class ConsoleRenderer(object):
 	DEFAULT='\033[30;0m'