Exemplo n.º 1
0
class SpotifyTrack(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField()

    href = WhamTextField(null=True)
    popularity = WhamIntegerField(null=True)
    track_number = WhamIntegerField(null=True)
    uri = WhamTextField(null=True)
    type = WhamTextField(null=True)
    preview_url = WhamTextField(null=True)
    artists = WhamManyToManyField('SpotifyArtist', related_name='tracks')

    class WhamMeta(SpotifyMeta):
        endpoint = 'tracks'

        class Search:
            endpoint = 'search'
            params = {'type': 'track'}
            results_path = ('tracks', 'items')

    class Meta:
        db_table = 'spotify_track'

    def __unicode__(self):
        return self.name
Exemplo n.º 2
0
class TwitterUser(WhamModel):

    id = WhamIntegerField(primary_key=True)
    text = WhamTextField()

    screen_name = WhamTextField(unique=True, wham_can_lookup=True)

    #this is dodgy, because this should really be a oneToMany field which you have
    # to specify as a FK on the other model (which can be annoying!)
    tweets = WhamManyToManyField(
        #https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
        # user_id=23234
        'Tweet',
        related_name='users',
        wham_endpoint='statuses/user_timeline',
        wham_pk_param='user_id',
        wham_params={
            'count': 200,
            'exclude_replies': 'true',
            'include_rts': 'false',
        })

    class Meta:
        db_table = 'twitter_user'

    class WhamMeta(TwitterMeta):
        endpoint = 'users/show'
        url_pk_type = 'querystring'
        url_pk_param = 'user_id'

        #https://api.twitter.com/1.1/users/show.json?screen_name=rsarver

    def __unicode__(self):
        return self.screen_name
Exemplo n.º 3
0
class DeezerTrack(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    title = WhamTextField(
    )  #TODO: this shouldn't be required if json property is same as django fieldname

    rank = WhamIntegerField(null=True)
    bpm = WhamFloatField(null=True)
    track_position = WhamIntegerField(null=True)

    # examples:
    # id: 3135556,
    # readable: true,
    # title: "Harder Better Faster Stronger",
    # isrc: "GBDUW0000059",
    # link: "http://www.deezer.com/track/3135556",
    # duration: 225,
    # track_position: 4,
    # disk_number: 1,
    # rank: 757802,
    # explicit_lyrics: false,
    # preview: "http://cdn-preview-5.deezer.com/stream/51afcde9f56a132096c0496cc95eb24b-3.mp3",
    # bpm: 123.5,
    # gain: -6.48,
    # available_countries: [],
    # artist: {},
    # album: {},
    # type: "track"

    class Meta:
        db_table = 'deezer_track'

    class WhamMeta(DeezerMeta):
        endpoint = 'track'

        # does not currently work as Wham search is currently limited to name__icontains #TODO
        # class Search:
        #     endpoint = 'search/track'
        #     results_path = ('data',)
        #     fields = ('title',) #actually only uses one for now

    def __unicode__(self):
        return self.title
Exemplo n.º 4
0
class Tweet(WhamModel):

    id = WhamIntegerField(primary_key=True)
    text = WhamTextField()
    created_at = WhamDateTimeField(wham_format=CREATED_AT_FORMAT)

    retweet_count = WhamIntegerField(null=True)
    favourites_count = WhamIntegerField(null=True)

    class Meta():
        ordering = ('-created_at', )

    class WhamMeta(TwitterMeta):
        endpoint = 'statuses/show'

    def __unicode__(self):
        return self.text

    def _repr_html_(self):
        return render_to_string('wham/twitter/ipython_notebook/tweet.html',
                                {'tweet': self})
Exemplo n.º 5
0
class SpotifyArtist(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField()

    href = WhamTextField(null=True)
    popularity = WhamIntegerField(null=True)
    uri = WhamTextField(null=True)

    albums = WhamManyToManyField(
        'SpotifyAlbum',
        related_name='artists',
        wham_endpoint='artists/{{id}}/albums',
        wham_results_path=('items',)
    )

    # TODO:
    # tracks = WhamManyToManyField(
    #     'SpotifyTrack',
    #     # related_name='artists',
    #     wham_endpoint='artists/{{id}}/albums',
    #     wham_results_path=('items',)
    # )

    class Meta:
        db_table = 'spotify_artist'

    class WhamMeta(SpotifyMeta):
        endpoint = 'artists'

        # i reckon this stuff should really be in Manager, as it has more to do with filter()
        # which is a Manager method

        class Search:
            endpoint = 'search'
            params = {'type': 'artist'}
            results_path = ('artists', 'items')

    def __unicode__(self):
        return self.name
Exemplo n.º 6
0
class SpotifyAlbum(WhamModel):

    # objects = WhamManager()

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField()

    release_date = WhamTextField(null=True)
    popularity = WhamIntegerField(null=True, wham_detailed=True)

    class Meta:
        db_table = 'spotify_album'

    class WhamMeta(SpotifyMeta):
        endpoint = 'albums'
        # search_endpoint = 'search'
        # search_extra_params = {'type': 'album'}
        # search_results_path = ('albums', 'items')


    def __unicode__(self):
        return self.name
Exemplo n.º 7
0
class SoundcloudTrack(WhamModel):

    id = models.CharField(max_length=255, primary_key=True)
    title = WhamTextField()

    track_type = WhamTextField(null=True)
    stream_url = WhamTextField(null=True)
    playback_count = WhamIntegerField(null=True)

    class Meta:
        db_table = 'soundcloud_track'

    class WhamMeta(SoundcloudMeta):
        url_postfix = '.json'

        endpoint = 'tracks/'
        class Search:
            endpoint = 'tracks'
            fields = ('title',)


    def __unicode__(self):
        return self.title
Exemplo n.º 8
0
class EventbriteEvent(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField(wham_result_path=('name', 'text'))
    resource_uri = WhamTextField()
    url = WhamTextField()
    capacity = WhamIntegerField()
    venue = WhamForeignKey(
        EventbriteVenue, null=True
    )  #this should be a foreign key! But we only support m2m so far.

    class WhamMeta(EventbriteMeta):
        endpoint = 'events'

        class Search:
            endpoint = 'events/search'
            results_path = ('events', )

    class Meta:
        db_table = 'eventbrite_event'

    def __unicode__(self):
        return self.name