当前位置: 首页>>代码示例>>Python>>正文


Python Session.query方法代码示例

本文整理汇总了Python中scatterbrainz.model.meta.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scatterbrainz.model.meta.Session的用法示例。


在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getAlbumInfoAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def getAlbumInfoAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     json = {}
     albumMbid = track.album.mbid
     # get wikipedia from the release group
     wikipedia = Session.query(MBURL.url) \
                        .join(MBLReleaseGroupURL) \
                        .join(MBLink) \
                        .join(MBLinkType) \
                        .filter(MBLinkType.name=='wikipedia') \
                        .join(MBReleaseGroup) \
                        .filter(MBReleaseGroup.gid==albumMbid) \
                        .all()
     wikipedia = filter(self._filterForEnglishWiki, map(lambda x: x[0], wikipedia))
     if wikipedia:
         wurl = wikipedia[0]
         json['wikipedia'] = wurl
         json['summary'] = albumsummary.get_album_summary(Session, albumMbid, wurl)
     # get amazon from any of the releases
     amazon = Session.query(MBURL) \
                     .join(MBLReleaseURL) \
                     .join(MBLink) \
                     .join(MBLinkType) \
                     .filter(MBLinkType.name=='amazon asin') \
                     .join(MBRelease) \
                     .join(MBReleaseGroup) \
                     .filter(MBReleaseGroup.gid==albumMbid) \
                     .first()
     if amazon:
         json['amazon'] = amazon.url
     json['musicbrainz'] = 'http://musicbrainz.org/release-group/' + albumMbid
     return simplejson.dumps(json)
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:35,代码来源:hello.py

示例2: trackArtistAlbumsLOCAL

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
    def trackArtistAlbumsLOCAL(self):
        trackid = request.params['trackid']

        #note that we can do this because there is 
        #only a single foreign key matched between 
        #tracks and albums.
        artistid=Session.query(Track).filter_by(id=trackid)[0].artistid
        joined=Session.query(Track).filter_by(artistid=artistid)

        aids = []
        out = []
        for t in joined:
            aid = t.albumid
            if not aid in aids:
                aids.append(aid)
                year_re = re.compile('[0-9]{4}')
                early_year = (re.search(year_re,t.id3date)).group()
                json = {
                    'aid':aid,
                    'mbid':t.album.mbid,
                    'name':t.album.name,
                    'year':early_year
                    }
                out.append(json)
        return sjson.dumps(out)
开发者ID:steez,项目名称:scatterbrainz,代码行数:27,代码来源:getlocal.py

示例3: savePlaylistAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def savePlaylistAJAX(self):
     playlistname = request.params['name']
     trackids = simplejson.loads(request.params['trackids'])
     trackids = map(lambda x: x.replace('track_',''), trackids)
     results = Session.query(Track, MBRecording).join(MBRecording).filter(Track.id.in_(trackids)).all()
     results.sort(lambda a,b: cmp(trackids.index(a[0].id), trackids.index(b[0].id)))
     recordings = map(itemgetter(1), results)
     Session.begin()
     user_name = request.environ['repoze.what.credentials']['repoze.what.userid']
     user_id = Session.query(User).filter(User.user_name==user_name).one().user_id
     playlist = Session.query(Playlist) \
                       .filter(Playlist.owner_id==user_id) \
                       .filter(Playlist.name==playlistname) \
                       .first()
     if not trackids:
         if playlist is None:
             return '{}'
         else:
             Session.delete(playlist)
     else:
         if playlist is None:
             playlist = Playlist(user_id, playlistname)
             Session.add(playlist)
         else:
             playlist.modified = datetime.now()
         playlist.tracks = recordings
     Session.commit()
     return '{}'
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:30,代码来源:hello.py

示例4: pp2

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def pp2(self):
     artists = Session.query(Artist)
     tracks = Session.query(Track)
     paths = []
     for r in tracks:
         paths.append( os.path.join('.media', r.filepath ))
         
     return render('/hello2.html')
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:10,代码来源:hello2.py

示例5: similarTrackAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def similarTrackAJAX(self):
     id = request.params['id'].split('_')[1]
     track = Session.query(Track).filter_by(id=id).one()
     lastfmArtist = self.lastfmNetwork.get_artist(track.artist.name)
     similarArtists = lastfmArtist.get_similar()
     similarMbids = filter(lambda x: x is not None, map(lambda x: x.mbid, similarArtists))
     randomSimilarArtist = Session.query(Artist).filter(Artist.mbid.in_(similarMbids)).order_by(random()).first()
     return simplejson.dumps([rand.choice(randomSimilarArtist.tracks).toPlaylistJSON()]) \
         if randomSimilarArtist \
         else self.randomTrackAJAX()
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:12,代码来源:hello.py

示例6: randomRooAlbumAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def randomRooAlbumAJAX(self):
     album = Session.query(Album) \
                    .join(Album.artists) \
                    .filter(Artist.mbid.in_(Bonnaroo.artist_mbids)) \
                    .order_by(random()) \
                    .first()
     tracks = Session.query(Track) \
                     .filter_by(albumid=album.mbid)
     json = map(lambda x: x.toPlaylistJSON(), tracks)
     return simplejson.dumps(json)
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:12,代码来源:hello.py

示例7: _getTracksForPlaylist

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def _getTracksForPlaylist(self, id):
     playlist = Session.query(Playlist).filter(Playlist.playlist_id==id).one()
     recordings = playlist.tracks
     recording_mbids = map(lambda x: x.gid, recordings)
     tracks = Session.query(Track).filter(Track.mbid.in_(recording_mbids)).all()
     tracks.sort(lambda a,b: cmp(recording_mbids.index(a.mbid), recording_mbids.index(b.mbid)))
     filtertracks = [tracks[0]]
     for track in tracks[1:]:
         if track.mbid != filtertracks[-1].mbid:
             filtertracks.append(track)
     return filtertracks
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:13,代码来源:hello.py

示例8: searchShopAlbumAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def searchShopAlbumAJAX(self):
     mbid = request.params['mbid']
     (album, albumname, artistname) = Session.query(MBReleaseGroup, MBReleaseName, MBArtistName) \
                                             .join(MBReleaseName) \
                                             .join(MBReleaseGroup.artistcredit, MBArtistCredit.name) \
                                             .filter(MBReleaseGroup.gid==mbid) \
                                             .one()
     user_name = request.environ['repoze.what.credentials']['repoze.what.userid']
     user_id = Session.query(User).filter(User.user_name==user_name).one().user_id
     infohash = shopservice.download(Session, mbid, user_id)
     if infohash:
         return simplejson.dumps({'success' : True})
     else:
         return simplejson.dumps({'success' : False})
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:16,代码来源:hello.py

示例9: searchAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def searchAJAX(self):
     search = request.params['search']
     maxResults = 50
     artists = Session.query(Artist). \
                       filter(Artist.name.like('%'+search+'%')). \
                       join(Album) \
                       [0:maxResults]
     albums = Session.query(Album). \
                      filter(Album.name.like('%'+search+'%')) \
                      [0:maxResults]
     tracks = Session.query(Track). \
                      filter(Track.id3title.like('%'+search+'%')) \
                      [0:maxResults]
     if len(artists) == maxResults or len(tracks) == maxResults or len(albums) == maxResults:
         truncated = True
     else:
         truncated = False
     artistIdToJSON = {}
     albumsIdToJSON = {}
     for artist in artists:
         if artist.id not in artistIdToJSON:
             artistJSON = artist.toTreeJSON()
             artistIdToJSON[artist.id] = artistJSON
     for album in albums:
         if album.artist and album.artist.id not in artistIdToJSON:
             artistJSON = album.artist.toTreeJSON(children=[])
             artistIdToJSON[album.artist.id] = artistJSON
             albumJSON = album.toTreeJSON()
             artistJSON['children'].append(albumJSON)
         else:
             continue
     for track in tracks:
         if track.album and \
            track.album.artist and \
            track.album.artist.id not in artistIdToJSON:
             artistJSON = track.album.artist.toTreeJSON(children=[])
             artistIdToJSON[track.album.artist.id] = artistJSON
         else:
             continue
         if track.album and track.album.id not in albumsIdToJSON:
             albumJSON = track.album.toTreeJSON(children=[])
             artistJSON['children'].append(albumJSON)
             albumsIdToJSON[track.album.id] = albumJSON
         else:
             continue
         albumJSON['children'].append(track.toTreeJSON())
     json = artistIdToJSON.values()
     json.sort(self._compareTreeFloatVA)
     return simplejson.dumps(json)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:51,代码来源:hello.py

示例10: getLyricsAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def getLyricsAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     ip = request.environ['REMOTE_ADDR']
     user_name = request.environ['repoze.what.credentials']['repoze.what.userid']
     user = Session.query(User).filter(User.user_name==user_name).one()
     Session.begin()
     play = TrackPlay(track.mbid, user, ip)
     Session.add(play)
     Session.commit()
     lyrics = lyricsservice.get_lyrics(Session, track)
     if lyrics:
         return simplejson.dumps({'lyrics' : lyrics})
     else:
         return '{}'
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:17,代码来源:hello.py

示例11: alltracks

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
    def alltracks(self):
        tracks = Session.query(Track)
        count = 0
        namefun = lambda x: x.id3title
        out = []
        this_artist_count = 0 
        last_artist = ''
        max_per_artist = 5
        for t in tracks:
            name = namefun(t)
            type = t.__class__.__name__

            this_artist = t.artistid
            if this_artist == last_artist:
                this_artist_count = this_artist_count + 1
            else:
                this_artist_count = 0
                last_artist = this_artist
            if this_artist_count < max_per_artist:
                json = {
                    'type':type,
                    'name':name,
                    'url':self.track_URL_from_id(t.id),
                    'id':t.id,
                    'albumid':t.albumid,
                    'artistid':t.artistid
                    }
                out.append(json)
                count = count + 1
                if count > 50: break

        return sjson.dumps(out)
开发者ID:steez,项目名称:scatterbrainz,代码行数:34,代码来源:getlocal.py

示例12: alltracks

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
    def alltracks(self):
        trk_total_limit = 200;
        trk_artist_limit = 10;

        tracks = Session.query(Track)
        count = 0
        namefun = lambda x: x.id3title
        out = []
        this_artist_count = 0 
        last_artist = ''
        for t in tracks:
            name = namefun(t)

            this_artist = t.artistid
            if this_artist == last_artist:
                this_artist_count = this_artist_count + 1
            else:
                this_artist_count = 0
                last_artist = this_artist
            if this_artist_count < trk_artist_limit:
                json = {
                    'track_name':name,
                    'url':self.track_URL_from_id(t.id),
                    'track_id':t.id,
                    'albumid':t.albumid,
                    'artistid':t.artistid,
                    'datatype':'track',
                    'tostring':name
                    }
                out.append(json)
                count = count + 1
                if count > trk_total_limit: break

        return sjson.dumps(out)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:36,代码来源:getlocal.py

示例13: getLyricsAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def getLyricsAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     if not track.lyrics and \
        (track.lastHitLyricWiki is None or \
         datetime.now() > track.lastHitLyricWiki + timedelta(days=10)):
         
         track.lastHitLyricWiki = datetime.now()
         
         title = track.id3title
         artist = track.id3artist
         params = {
             'artist' : artist,
             'song'   : title,
             'fmt'    : 'json',
         }
         
         url = 'http://lyrics.wikia.com/api.php?%s' % urllib.urlencode(params)
         
         html = urllib.urlopen(url).read()
         
         if not "'lyrics':'Not found'" in html:
             search = re.search("'url':'(?P<url>.*?)'",html)
             lyricurl = urllib.unquote(search.group('url'))
             lyrichtml = urllib.urlopen(lyricurl).read()
             lyrics = re.search("<div class='lyricbox'>.*?</div>(?P<lyrics>.*?)<!-- \n", lyrichtml).group('lyrics')
             lyrics = unescape(lyrics)
             track.lyrics = lyrics
         Session.begin()
         Session.commit()
     json = {}
     if track.lyrics:
         json['lyrics'] = track.lyrics
     return simplejson.dumps(json)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:36,代码来源:hello.py

示例14: randomRooTrackAJAX

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
 def randomRooTrackAJAX(self):
     track = Session.query(Track) \
                    .join(Album, Album.artists) \
                    .filter(Artist.mbid.in_(Bonnaroo.artist_mbids)) \
                    .order_by(random()) \
                    .first()
     return simplejson.dumps([track.toPlaylistJSON()])
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:9,代码来源:hello.py

示例15: index

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import query [as 别名]
    def index(self):

        # Return a rendered template
        #return render('/ben_kvp.mako')
        # or, return a string
        
        return 'Hello World - how you doing today {0}'.format(Session.query(User).first())
开发者ID:drassi,项目名称:scatterbrainz,代码行数:9,代码来源:ben_kvp.py


注:本文中的scatterbrainz.model.meta.Session.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。