Anonymous avatar Anonymous committed 40c1ed6

Implemented search

Comments (0)

Files changed (2)

pyepisoder/episoder.py

 		return shows.fetchall()
 
 	def getEpisodes(self, basedate=datetime.date.today(), n_days=0):
+		result = self.conn.execute("""
+			SELECT show_id, show_name, title, season, num, airdate,
+			prodnum, totalnum FROM episodes NATURAL JOIN shows WHERE
+			airdate >= ? AND airdate <= ? ORDER BY airdate ASC
+			""", [basedate, basedate + datetime.timedelta(n_days)])
+
+		shows = []
 		episodes = []
-		result = self.conn.execute('SELECT show_id, show_name, title,' +
-			'season, num, airdate, prodnum, totalnum FROM ' +
-			'episodes NATURAL JOIN shows WHERE airdate >= ? AND ' +
-			'airdate <= ? ORDER BY airdate ASC', [basedate,
-				basedate + datetime.timedelta(n_days)])
+
+		for item in result.fetchall():
+			show = Show(item[1], item[0])
+			if show in shows:
+				show = shows[shows.index(show)]
+			else:
+				shows.append(show)
+
+			airdate = datetime.datetime.strptime(item[5],"%Y-%m-%d")
+
+			episode = Episode(show, item[2], item[3], item[4],
+				airdate.date(), item[6], item[7])
+			episodes.append(episode)
+
+		return episodes
+
+	def search(self, options):
+		search = options['search']
+
+		result = self.conn.execute("""
+			SELECT show_id, show_name, title, season, num, airdate,
+			prodnum, totalnum FROM episodes NATURAL JOIN shows WHERE
+			title LIKE "%%%s%%" OR show_name LIKE "%%%s%%" ORDER BY
+			airdate ASC
+			""" % (search, search))
 
 		shows = []
 		episodes = []
 		self.total = int(total)
 
 	def _setAirDate(self, airdate):
-		self._airdate = airdate.isoformat()
+		# meh, hack to make sure that we actually get a date object
+		airdate.isoformat()
+		self._airdate = airdate
 
 	def _getAirDate(self):
 		return self._airdate

pyepisoder/plugins.py

 			startdate = options['date']
 			n_days = options['days']
 
-		episodes = store.getEpisodes(startdate, n_days)
+		if options['search']:
+			episodes = store.search(options)
+		else:
+			episodes = store.getEpisodes(startdate, n_days)
 
 		for episode in episodes:
 			if episode.airdate == yesterday:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.