Esempio n. 1
0
    def _update_trackweek(self, page=1):
        print 'INSIDE _UPDATE_TRACKWEEK'
        resp = Api.user_get_toptracks_week(self.lfm_username, page)
        if page == 1:
            from lfm.tasks import update_trackweek_task
            attr = resp['toptracks'].get('@attr')
            if attr is None:
                maxpages = 2
            else:
                maxpages = int(attr.get('totalPages'))+1
            for page_num in range(2, maxpages):
                update_trackweek_task.apply_async([self.id, page_num])
        tracks = resp.get('toptracks').get('track')
        if tracks is None:
            return
        elif isinstance(tracks, list):
            for track in tracks:
                UserTrackWeek.create(self, track)
            
        elif isinstance(tracks, dict):
            Track.make_trackweek(self, tracks) #TODO: add this classmethod to the track class

        if int(resp['toptracks']['@attr']['page']) == int(resp['toptracks']['@attr']['totalPages']):
            self.updating_track_week = False
            self.tracks_week_updated_at = datetime.datetime.now()
            self.save()
Esempio n. 2
0
 def update_trackweek(self):
     print 'INSIDE UPDATE_TRACKWEEK'
     if self.updating_track_week:
         print 'WARNING: %s is already updating their trackweek. This MAY be an error?'%self
         # return False
     elif self.tracks_week_updated_at == None or datetime.datetime.now() - self.tracks_week_updated_at > datetime.timedelta(7):
         print 'Changing updating_track_week for %s'%self
         self.updating_track_week = True
         self.usertrackweek_set.all().delete()
         self.save()
         from lfm.tasks import update_trackweek_task
         update_trackweek_task.apply_async([self.id])