Ejemplo n.º 1
0
    def get_json(self):
        if is_new(self.update_datetime, timedelta(minutes=5)):
            return self.info_json

        # else update by calling api
        sp = get_spotify_object()
        new_json_info = sp.current_user()

        self.info_json = new_json_info
        self.update_datetime = datetime.utcnow()

        db.session.commit()

        return self.info_json
Ejemplo n.º 2
0
    def get_json(self):
        if is_new(self.timestamp, timedelta(hours=1)):
            return self.info_json

        # else update by calling api
        sp = get_spotify_object()
        new_json_info = sp.current_user_top_tracks(limit=50,
                                                   time_range='long_term')

        self.info_json = new_json_info
        self.timestamp = datetime.utcnow()
        db.session.commit()

        print("---in db, updating user top tracks info...")

        return self.info_json
Ejemplo n.º 3
0
    def get_json(self):
        if is_new(self.timestamp, timedelta(minutes=5)):
            return self.info_json

        # else update by calling api
        sp = get_spotify_object()
        new_json_info = sp.current_user_recently_played(limit=50)

        self.info_json = new_json_info
        self.timestamp = datetime.utcnow()

        db.session.commit()

        print("---in db, updating user recent tracks info...")

        return self.info_json
Ejemplo n.º 4
0
    def __get_json(self):
        if is_new(self.timestamp, timedelta(weeks=1)):
            return self.info_json

        # else update by calling api
        sp = get_spotify_object()
        new_info_json = sp.album(self.album_id)

        self.timestamp = datetime.utcnow()
        self.info_json = new_info_json
        self.album_name = new_info_json['name']

        # since the caller is itself, do commit itself
        db.session.commit()

        print("---in db, updating album info...")

        return self.info_json