Example #1
0
 def get(self):
     self.response.headers["Content-Type"] = "text/json"
     album_key = self.request.get("album_key")
     songlist_html = memcache.get("songlist_html_" + album_key)
     if songlist_html:
         self.response.out.write(json.dumps({"songListHtml": songlist_html, "generated": "memcache"}))
         return
     album = cache.getAlbum(album_key)
     self.response.headers["Content-Type"] = "text/json"
     if not album:
         self.response.out.write(
             json.dumps({"err": "An error occurred and the specified album could not be found.  Please try again."})
         )
         return
     songlist_html = template.render(
         getPath("ajax_songlist.html"), {"songList": [cache.getSong(k) for k in album.songList]}
     )
     memcache.set("songlist_html_" + album_key, songlist_html)
     self.response.out.write(
         json.dumps(
             {
                 "songListHtml": template.render(
                     getPath("ajax_songlist.html"), {"songList": [cache.getSong(k) for k in album.songList]}
                 ),
                 "generated": "generated",
             }
         )
     )
Example #2
0
 def get(self):
     self.response.headers["Content-Type"] = "text/json"
     album_key = self.request.get("album_key")
     songlist_html = memcache.get("songlist_html_" + album_key)
     if songlist_html:
         self.response.out.write(
             json.dumps({
                 'songListHtml': songlist_html,
                 'generated': 'memcache',
             }))
         return
     album = cache.getAlbum(album_key)
     self.response.headers["Content-Type"] = "text/json"
     if not album:
         self.response.out.write(
             json.dumps({
                 'err':
                 "An error occurred and the specified album could not be found.  Please try again."
             }))
         return
     songlist_html = template.render(getPath("ajax_songlist.html"), {
         'songList': [cache.getSong(k) for k in album.songList],
     })
     memcache.set("songlist_html_" + album_key, songlist_html)
     self.response.out.write(
         json.dumps({
             'songListHtml':
             template.render(getPath("ajax_songlist.html"), {
                 'songList': [cache.getSong(k) for k in album.songList],
             }),
             'generated':
             'generated',
         }))
Example #3
0
    def get(self):
        recent_songs = cache.getLastPlays(num=3)
        logging.debug(recent_songs)
        if recent_songs is not None and len(recent_songs) > 0:
            last_play = recent_songs[0]
            song, program = (cache.getSong(last_play.song_key),
                             cache.getProgram(last_play.program_key))
            song_string = song.title + " — " + song.artist
            program_title, program_desc, program_slug = (program.title,
                                                         program.desc,
                                                         program.slug)
        else:
            song, program = None, None
            song_string = "Nothing is playing"
            program_title, program_desc, program_slug = ("No show",
                                                         "No description", "")

        self.response.headers["Content-Type"] = "text/json"
        self.response.out.write(
            json.dumps({
                'song_string':
                song_string,
                'program_title':
                program_title,
                'program_desc':
                program_desc,
                'program_slug':
                program_slug,
                'top_played': ("Top artists: " +
                               ", ".join([a for a in program.top_artists[:3]])
                               if program is not None else None),
                'recent_songs_html':
                template.render(getPath("recent_songs.html"),
                                {'plays': recent_songs}),
            }))
Example #4
0
    def get(self):
        import csv

        shows = models.getPrograms()
        slug = self.request.get("show")
        datestring = self.request.get("programdate")
        selected_date = None

        if datestring:
            try:
                selected_date = datetime.datetime.strptime(datestring, "%m/%d/%Y")
                selected_date = selected_date + datetime.timedelta(hours=12)
                print selected_date.isoformat(" ")
            except:
                self.session.add_flash("The date provided could not be parsed.")
                self.redirect("/")
                return

        if slug:
            selected_program = models.getProgramBySlug(slug)
            if not selected_program:
                self.session.add_flash("There is no program for slug %s." % slug)
                self.redirect("/")
                return
            if selected_date:
                plays = models.getPlaysBetween(
                    program=selected_program,
                    after=(selected_date - datetime.timedelta(hours=24)),
                    before=(selected_date + datetime.timedelta(hours=24)),
                )
            else:
                lastplay = models.getLastPlays(program=selected_program, num=1)
                if lastplay:
                    lastplay = lastplay[0]
                    last_date = lastplay.play_date
                    plays = models.getPlaysBetween(
                        program=selected_program, after=(last_date - datetime.timedelta(days=1))
                    )
                else:
                    plays = []
        else:
            if selected_date is None:
                lastplay = cache.getLastPlay()
                if lastplay:
                    selected_date = lastplay.play_date

            if selected_date:
                print "doop"
                print selected_date.isoformat(" ")
                plays = models.getRetardedNumberOfPlaysForDate(selected_date)
            else:
                plays = cache.getLastPlays(60)

        csv_sep = "\t"
        out_data = [("Date", "Time", "Title", "Artist")]
        for p in plays:
            s = cache.getSong(p.song_key)
            out_data.append((p.play_date.isoformat(csv_sep), s.title, s.artist))

        self.response.out.write("\n".join([csv_sep.join(row) for row in out_data]))
Example #5
0
    def get(self):
        recent_songs = cache.getLastPlays(num=3)
        logging.debug(recent_songs)
        if recent_songs is not None and len(recent_songs) > 0:
            last_play = recent_songs[0]
            song, program = (cache.getSong(last_play.song_key), cache.getProgram(last_play.program_key))
            song_string = song.title + " — " + song.artist
            program_title, program_desc, program_slug = (program.title, program.desc, program.slug)
        else:
            song, program = None, None
            song_string = "Nothing is playing"
            program_title, program_desc, program_slug = ("No show", "No description", "")

        self.response.headers["Content-Type"] = "text/json"
        self.response.out.write(
            json.dumps(
                {
                    "song_string": song_string,
                    "program_title": program_title,
                    "program_desc": program_desc,
                    "program_slug": program_slug,
                    "top_played": (
                        "Top artists: " + ", ".join([a for a in program.top_artists[:3]])
                        if program is not None
                        else None
                    ),
                    "recent_songs_html": template.render(getPath("recent_songs.html"), {"plays": recent_songs}),
                }
            )
        )
Example #6
0
    def get(self):
        import csv
        shows = models.getPrograms()
        slug = self.request.get("show")
        datestring = self.request.get("programdate")
        selected_date = None

        if datestring:
            try:
                selected_date = datetime.datetime.strptime(
                    datestring, "%m/%d/%Y")
                selected_date = selected_date + datetime.timedelta(hours=12)
                print selected_date.isoformat(" ")
            except:
                self.session.add_flash(
                    "The date provided could not be parsed.")
                self.redirect("/")
                return

        if slug:
            selected_program = models.getProgramBySlug(slug)
            if not selected_program:
                self.session.add_flash("There is no program for slug %s." %
                                       slug)
                self.redirect("/")
                return
            if selected_date:
                plays = models.getPlaysBetween(
                    program=selected_program,
                    after=(selected_date - datetime.timedelta(hours=24)),
                    before=(selected_date + datetime.timedelta(hours=24)))
            else:
                lastplay = models.getLastPlays(program=selected_program, num=1)
                if lastplay:
                    lastplay = lastplay[0]
                    last_date = lastplay.play_date
                    plays = models.getPlaysBetween(
                        program=selected_program,
                        after=(last_date - datetime.timedelta(days=1)))
                else:
                    plays = []
        else:
            if selected_date is None:
                lastplay = cache.getLastPlay()
                if lastplay:
                    selected_date = lastplay.play_date

            if selected_date:
                print "doop"
                print selected_date.isoformat(" ")
                plays = models.getRetardedNumberOfPlaysForDate(selected_date)
            else:
                plays = cache.getLastPlays(60)

        csv_sep = "\t"
        out_data = [("Date", "Time", "Title", "Artist")]
        for p in plays:
            s = cache.getSong(p.song_key)
            out_data.append(
                (p.play_date.isoformat(csv_sep), s.title, s.artist))

        self.response.out.write("\n".join(
            [csv_sep.join(row) for row in out_data]))
Example #7
0
File: api.py Project: hchapman/WBOR
 def get(self, key):
   song = cache.getSong(key)
   if song:
     self.json_respond(song.to_json())
Example #8
0
 def get(self, key):
     song = cache.getSong(key)
     if song:
         self.json_respond(song.to_json())