Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
0
class Person(WhamModel):

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

    class WhamMeta(FreebaseMeta):
        endpoint = 'topic'
Esempio n. 4
0
class FacebookUser(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    username = WhamTextField(unique=True)
    name = WhamTextField()
    gender = WhamTextField()
    first_name = WhamTextField()
    last_name = WhamTextField()

    class Meta:
        db_table = 'facebook_user'

    class WhamMeta(FacebookMeta):
        endpoint = ''

    def __unicode__(self):
        return self.name
Esempio n. 5
0
class FreebaseMusicbrainzArtist(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField(wham_result_path=('property', '/type/object/name',
                                           'values', 0, 'value'))
    origin_text = WhamTextField(wham_result_path=('property',
                                                  '/music/artist/origin',
                                                  'values', 0, 'text'))
    place_of_birth = WhamTextField(
        wham_result_path=('property', '/people/person/place_of_birth',
                          'values', 0, 'text'))

    class WhamMeta(FreebaseMeta):
        endpoint = 'topic/authority/musicbrainz/artist'


# country/place for band is in:
#   /music/artist/origin
# country/place for solo performer is

#/people/person/place_of_birth

# also of use (solo artist)
# /music/artist/active_end: {},
# /music/artist/active_start: {},
# /music/artist/album: {},
# /music/artist/contribution: {},
# /music/artist/genre: {},
# /music/artist/track: {},
# /music/artist/track_contributions: {},

#(band stuff)
# /music/artist/active_end: {},
# /music/artist/active_start: {},
# /music/artist/album: {},
# /music/artist/concert_tours: {},
# /music/artist/genre: {},
# /music/artist/home_page: {},
# /music/artist/label: {},
# /music/artist/origin: {},
# /music/artist/track: {},
# /music/musical_group/member: {},
Esempio n. 6
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
Esempio n. 7
0
class ProgrammingLanguage(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField(wham_result_path=('property', '/type/object/name',
                                           'values', 0, 'value'))

    # language_designers = models.ManyToManyField('Person')

    class WhamMeta(FreebaseMeta):
        endpoint = 'topic'

    def __unicode__(self):
        return self.name
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
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
Esempio n. 11
0
class MusicbrainzArtist(WhamModel):

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


    class WhamMeta(MusicbrainzMeta):
        endpoint = 'artist/'

    class Meta:
        db_table = 'musicbrainz_artist'

    def __unicode__(self):
        return self.name
Esempio n. 12
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
Esempio n. 13
0
class LastFmArtist(WhamModel):

    name = WhamTextField(primary_key=True)

    mbid = WhamCharField(
        max_length=255, null=True, wham_can_lookup=True
    )  #this *would* be unique & not nullable, but lasfm doesn't always know it

    class Meta:
        db_table = 'lastfm_artist'

    class WhamMeta(LastFmMeta):
        endpoint = ''
        params = {'method': 'artist.getInfo'}
        detail_base_result_path = ('artist', )
        url_pk_type = 'querystring'
        url_pk_param = 'artist'

    def __unicode__(self):
        return self.name
Esempio n. 14
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})
Esempio n. 15
0
class EventbriteVenue(WhamModel):

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

    city = WhamTextField(wham_result_path=('address', 'city'), null=True)
    country = WhamTextField(wham_result_path=('address', 'country'), null=True)
    region = WhamTextField(wham_result_path=('address', 'region'), null=True)
    address_1 = WhamTextField(wham_result_path=('address', 'address_1'),
                              null=True)
    address_2 = WhamTextField(wham_result_path=('address', 'address_2'),
                              null=True)
    country_name = WhamTextField(wham_result_path=('address', 'country_name'),
                                 null=True)

    class Meta:
        db_table = 'eventbrite_venue'

    def __unicode__(self):
        return self.name