Esempio n. 1
0
    def get(self):
        logging.info("Received a GET Request")

        iterator = memcache.get('iterator')     #Get value of iterator in memcache
        total = memcache.get('total')           #Get value of total in memcache

        if iterator is None:                    # In case there is no iterator, make an iterator and initialise with value 0
            iterator = 0
            memcache.add('iterator',iterator)

        if total is None:                       # In case there is no total in the memcache, get total from datastore and add to memcache
            db_total = Total.all().get()
            total = db_total.total
            memcache.add('total', total)

        iterator = iterator + 1                 #Incrementing the iterator and reset if equal to max
        if(iterator >= total+1):
            iterator = 1

        memcache.set('iterator', iterator)
        logging.info("New Iterator Value " + str(iterator))
        # Now get the corresponding id from ListSeries

        lsquery = ListSeries.all()
        lsquery.filter("slno =", iterator)
        serial = lsquery.get()
        
        stvid = serial.tvid
        logging.info("IMDb ID " + stvid)
        self.response.write(stvid)   

        episode = getNextEp(stvid)

        epNum = episode["episode"]
        seaNum = episode["season"]
        epName = episode["title"]
        epStat = episode["status"]
        epRely = episode["rely"]
        epComments = episode['comments']
        
        if epRely == 3:                                 # No air date present
            epDate = 'Unavailable'
        else:
            epDate = episode["original air date"]   

        if epStat != 99:
            logging.info("Episode Number " + str(epNum))
            logging.info("Season Number " + str(seaNum))
            logging.info("Episode Title " + epName)
            logging.info("Status " + str(epStat))
            logging.info("Reliable " + str(epRely))
            logging.info("Next Episode date " + epDate)
            logging.info("Comments " + epComments)
        else:
            logging.warn("There is no information about the next episode. Probably the series has been terminated.")
            logging.info("Last Known Episode Number " + str(epNum))
            logging.info("Last Known Season Number " + str(seaNum))
            logging.info("Last Known Episode Title " + epName)
            logging.info("Status " + str(epStat))
            logging.info("Reliable " + str(epRely))
            logging.info("Last Known Episode date " + epDate)
            logging.info("Comments " + epComments)

        Ser = Series.all()
        Ser.filter('tvid = ', str(stvid))
        ser1 = Ser.get()

        logging.info("entry extracted from datastore")

        ser1.status = epStat
        ser1.rely = epRely
        ser1.epname = epName
        ser1.epinfo = str(seaNum) + "." + str(epNum)
        ser1.epdate = epDate
        ser1.up_cycle = ser1.up_cycle + 1
        ser1.comments = epComments

        ser1.put()

        logging.info(" Updated data written to Datastore")
Esempio n. 2
0
    def post(self):
        data = self.request.params
        if 'auth' not in data.keys():
            self.response.write('Unauthorised Request.')
            logging.error('Unauthorised Request.')
        else:
            auth = data['auth']
            if auth != 'NarutoStark':
                self.response.write('Unauthorised Request.')
                logging.error('Unauthorised Request.')
            else:
                logging.info('Recieved an Entry')

                # Get total number of series in use from memcache. If unavailable try datastore
                mem_total = memcache.get('total')
                db_total_entry = Total.all().get()
                if db_total_entry is not None:
                    db_total = db_total_entry.total
                    logging.debug('old db_total = ' + str(db_total))
                else:
                    db_tot = Total(total = 0)
                    db_tot.put()
                    logging.debug('added 0 to Total database')
                    mem_total = 0
                    db_total_entry = Total.all().get()
                logging.debug('old mem_total = ' + str(mem_total))
                if mem_total is None and (db_total_entry is None or db_total is None):
                    total = 1
                elif mem_total is None:
                    total = db_total + 1
                    logging.debug('No total in memcache. Using datastore')
                else:
                    total = mem_total + 1
                    logging.debug('total found in memcache')
                # End
                
                title   = data['title']
                tvid    = data['tvid']
                slno    = total
                logging.info('title = ' + str(title))
                logging.info('tvid = ' + str(tvid))

                # Put the given series in ListSeries after checking if its already present
                lsquery = ListSeries.all()
                lsquery.filter('tvid =', tvid)
                lsout = lsquery.get()
                if lsout is None:
                    listseries = ListSeries(tvid=tvid, title=title)
                    listseries.slno = slno
                    listseries.put()
                    logging.info('Entry put in ListSeries database')
                    # End

                    # Put the given series in Series after checking if its already present
                    # If already present then, reset the values
                    squery = Series.all()
                    squery.filter('tvid =', tvid)
                    sout = squery.get()
                    if sout is not None:
                        db_series = sout
                    else:
                        db_series = Series(tvid=tvid, title=title)
                    db_series.status    = -1            #Default
                    db_series.rely      = 99            #Default
                    db_series.epname    = 'None'        #Default
                    db_series.epinfo    = '0.0'         #Default
                    db_series.epdate    = 'dd mm yyyy'  #Default
                    db_series.up_cycle  = 0             #Default
                    db_series.comments  = 'No Comments' #Default
                    db_series.put()
                    logging.info('Entry put in Series database')
                    #End

                    # Now put the updated value in datastore and memcache
                    logging.debug('slno = ' + str(total))
                    db_total_entry.total = total
                    db_total_entry.put()
                    memcache.set('total', total)
                    logging.debug('Put new total in memcache and db')
                    # End
                    
                    self.response.write(title + ' put into the database.\n')
                else:
                    self.response.write('The series is already present in ListSeries database')
                    logging.error('Series already in ListSeries database')