Ejemplo n.º 1
0
class Period:
	def __init__(self):
		self.data_obj = ServeData()
		self.data_obj.load_data()
		self.series_to_track = self.data_obj.return_list()
		self.series_reached = self.data_obj.return_list(False)
		
	def do_query(self):
		_p_id = Pool(processes=10)
		results = list()
		for series_name in self.series_to_track:
			prepare_name = '+'.join(series_name.split())
			results.append(_p_id.apply_async(query_data, args=(prepare_name, )))
		for result in results:
			returned_result = result.get()
			json_formatted_result = json.loads(returned_result.text)
			no_of_votes = int(json_formatted_result['imdbVotes'].replace(',', ''))
			rating = float(json_formatted_result['imdbRating'])
			if no_of_votes >= parameters.MAX_VOTES_REQD and rating >= parameters.MAX_RATING_REQD:
				self.series_reached.append(json_formatted_result['Title'])
				self.series_to_track.remove(json_formatted_result['Title'])
	
	def push_back(self):
		# Do a clean list check first
		for series_name in self.series_reached:
			if series_name in self.series_to_track:
				self.series_to_track.remove(series_name)
		# Push data back to Data guy
		self.data_obj.receive_data_from_query(self.series_to_track, self.series_reached)
		self.data_obj.save_data()
Ejemplo n.º 2
0
class Period:
    def __init__(self):
        self.data_obj = ServeData()
        self.data_obj.load_data()
        self.series_to_track = self.data_obj.return_list()
        self.series_reached = self.data_obj.return_list(False)

    def do_query(self):
        _p_id = Pool(processes=10)
        results = list()
        for series_name in self.series_to_track:
            prepare_name = '+'.join(series_name.split())
            results.append(_p_id.apply_async(query_data,
                                             args=(prepare_name, )))
        for result in results:
            returned_result = result.get()
            json_formatted_result = json.loads(returned_result.text)
            no_of_votes = int(json_formatted_result['imdbVotes'].replace(
                ',', ''))
            rating = float(json_formatted_result['imdbRating'])
            if no_of_votes >= parameters.MAX_VOTES_REQD and rating >= parameters.MAX_RATING_REQD:
                self.series_reached.append(json_formatted_result['Title'])
                self.series_to_track.remove(json_formatted_result['Title'])

    def push_back(self):
        # Do a clean list check first
        for series_name in self.series_reached:
            if series_name in self.series_to_track:
                self.series_to_track.remove(series_name)
        # Push data back to Data guy
        self.data_obj.receive_data_from_query(self.series_to_track,
                                              self.series_reached)
        self.data_obj.save_data()
Ejemplo n.º 3
0
class Viewer:
    def __init__(self):
        self.period_obj = ServeData()
        self.period_obj.load_data()

    def looper(self):
        print '\n================ THE PENULTIMATE TV TRACKER ================\n'
        while True:
            try:
                print '1. Add series to watchlist'
                print '2. View watchlist'
                print '3. View series already reached the threshold'
                print '4. Exit'
                choice = raw_input('\nEnter choice: ').strip()
                if choice == '1':
                    series_name = raw_input('\nEnter series name : ').strip()
                    there = self.period_obj.series_already_in_list(series_name)
                    if there:
                        print '\nERROR : Series already been added previously'
                    else:
                        self.period_obj.add_series_to_watchlist(series_name)

                elif choice == '2':
                    watched_list = self.period_obj.return_list()
                    if watched_list:
                        print '\nAll series currently being watched : '
                        for i, series_name in enumerate(watched_list):
                            print('%d. %s') % ((i + 1), series_name)
                    else:
                        print '\nNo series listed here currently'

                elif choice == '3':
                    destined_list = self.period_obj.return_list(False)
                    if destined_list:
                        print '\nSeries which have crossed the threshold : '
                        for i, series_name in enumerate(destined_list):
                            print('%d. %s') % ((i + 1), series_name)
                    else:
                        print '\nNo series listed here currently'

                elif choice == '4':
                    break

                else:
                    pass

                print '\n============================================================\n'
            except Exception, e:
                print 'Exception : %s\n' % (type(e).__name__, )
                break
        self.period_obj.save_data()
Ejemplo n.º 4
0
class Viewer:
	def __init__(self):
		self.period_obj = ServeData()
		self.period_obj.load_data()
	
	def looper(self):
		print '\n================ THE PENULTIMATE TV TRACKER ================\n'
		while True:
			try:
				print '1. Add series to watchlist'
				print '2. View watchlist'
				print '3. View series already reached the threshold'
				print '4. Exit'
				choice = raw_input('\nEnter choice: ').strip()
				if choice == '1':
					series_name = raw_input('\nEnter series name : ').strip()
					there = self.period_obj.series_already_in_list(series_name)
					if there:
						print '\nERROR : Series already been added previously'
					else:
						self.period_obj.add_series_to_watchlist(series_name)
				
				elif choice == '2':
					watched_list = self.period_obj.return_list()
					if watched_list:
						print '\nAll series currently being watched : '
						for i, series_name in enumerate(watched_list):
							print ('%d. %s') % ((i+1), series_name)
					else:
						print '\nNo series listed here currently'
				
				elif choice == '3':
					destined_list = self.period_obj.return_list(False)
					if destined_list:
						print '\nSeries which have crossed the threshold : '
						for i, series_name in enumerate(destined_list):
							print ('%d. %s') %((i+1), series_name)	
					else:
						print '\nNo series listed here currently'
				
				elif choice == '4':
					break
		
				else:
					pass
		
				print '\n============================================================\n'
			except Exception,e:
				print 'Exception : %s\n' % (type(e).__name__, )
				break
		self.period_obj.save_data()
Ejemplo n.º 5
0
 def __init__(self):
     self.data_obj = ServeData()
     self.data_obj.load_data()
     self.series_to_track = self.data_obj.return_list()
     self.series_reached = self.data_obj.return_list(False)
Ejemplo n.º 6
0
 def __init__(self):
     self.period_obj = ServeData()
     self.period_obj.load_data()
Ejemplo n.º 7
0
	def __init__(self):
		self.data_obj = ServeData()
		self.data_obj.load_data()
		self.series_to_track = self.data_obj.return_list()
		self.series_reached = self.data_obj.return_list(False)
Ejemplo n.º 8
0
	def __init__(self):
		self.period_obj = ServeData()
		self.period_obj.load_data()