Пример #1
0
 def post(self):
   self.response.headers['Content-Type'] = 'text/json'
   Play.delete_key(self.request.get("play_key"), program=self.program_key)
   memcache.delete("playlist_html_%s"%self.program_key)
   self.response.out.write(json.dumps({
         'status': "Successfully deleted play."
         }))
Пример #2
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 = Play.get_last(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 = Play.get_last()
        if lastplay:
          selected_date = lastplay.play_date

      if selected_date:
        print "doop"
        print selected_date.isoformat(" ")
        plays = models.getRetardedNumberOfPlaysForDate(selected_date)
      else:
        plays = Play.get_last(num=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]))
Пример #3
0
  def get(self):
    shows = Program.get(num=1000) # TODO: NOPE
    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)
      except:
        self.session.add_flash("The date provided could not be parsed.")
        self.redirect("/")
        return

    if slug:
      selected_program = Program.get(slug=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 = Play.get_last(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 not selected_date:
        lastplay = Play.get_last()
        if lastplay:
          selected_date = lastplay.play_date

      if selected_date:
        plays = models.getPlaysForDate(selected_date)
      else:
        plays = Play.get_last(num=60)

    template_values = {
      'playlists_selected': True,
      'session': self.session,
      'plays': plays,
      'shows': shows,
      }
    self.response.out.write(template.render(get_path("playlist.html"),
                                            template_values))
Пример #4
0
  def get(self):
    slug = self.request.get("show")
    datestring = self.request.get("programdate")
    selected_date = None
    selected_program = None

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

    if slug:
      selected_program = Program.get(slug=slug)
      if not selected_program:
        self.session.add_flash("There is no program for slug %s." % slug, level="error")
        self.redirect("/playlists")
        return
      if selected_date:
        plays = Play.get_last(program=selected_program,
                              after=(selected_date -
                                     datetime.timedelta(hours=24)),
                              before=(selected_date +
                                      datetime.timedelta(hours=24)),
          num=60)
      else:
        lastplay = Play.get_last(program=selected_program)
        if lastplay:
          last_date = lastplay.play_date
          plays = Play.get_last(program=selected_program,
                                after=(last_date -
                                       datetime.timedelta(days=1)),
                                num=60)
        else:
          plays = []
    else:

      if selected_date:
        plays = Play.get_last(before=selected_date, num=60)
      else:
        plays = Play.get_last(num=60)

    template_values = {
      'playlists_selected': True,
      'session': self.session,
      'plays': plays,
      'show': selected_program,
      'datestring': datestring,
      }
    self.response.out.write(template.render(get_path("playlist.html"),
                                            template_values))
Пример #5
0
 def get(self):
   from models._raw_models import Play
   self.response.out.write("hey there")
   key = Play.query().get(keys_only=True)
   self.response.out.write(key)
   play = key.get()
   self.response.out.write(play)
Пример #6
0
  def get(self):
    ## Album list disabled until it is further optimized.
    #album_list = []
    album_list = Album.get_new(num=36)
    start = datetime.date.today() - datetime.timedelta(days=6)
    end = datetime.date.today() + datetime.timedelta(days=1)
    song_num = 10
    album_num = 10
    logging.debug("Calling get top")
    top_songs, top_albums = Play.get_top(start, end, song_num, album_num)
    posts = BlogPost.get_last(num=3)
    events = Event.get_upcoming(num=3)

    template_values = {
      'news_selected': True,
      'flash': self.flashes,
      'session': self.session,
      'album_list': album_list,
      'top_songs': top_songs,
      'top_albums': top_albums,
      'posts': posts,
      'events': events,
      }
    self.response.out.write(template.render(get_path("index.html"),
                                            template_values))
Пример #7
0
  def get(self):
    if not self.session_has_program():
      self.session.add_flash(
        "You can't chart songs until you have an associated program in the "
        "system.  Please contact a member of management immediately.")
      self.redirect("/dj/")
      return

    memcache_key = "playlist_html_%s"%self.session.get('program').get('key')
    playlist_html = memcache.get(memcache_key)
    if not playlist_html:
      playlist_html = template.render("dj_chartsong_playlist_div.html",
        {'playlist': Play.get_last(num=50,
                                   program=Program.get(self.program_key),
                                   after=(datetime.date.today())),
         }
      )
      memcache.set(memcache_key, playlist_html, 60 * 60 * 24)

    last_psa = None #Psa.get_last() # cache.getLastPsa()
    new_albums = None
    #new_song_div_html = memcache.get("new_song_div_html")
    album_songs = []
    new_song_div_html = None
    if not new_song_div_html:
      new_albums = Album.get_new() #by_artist=True)
      if new_albums:
        logging.debug(new_albums)
        album_songs = Song.get(new_albums[0].tracklist)
      new_song_div_html = template.render(
        get_path("dj_chartsong_newsongdiv.html"),
        {'new_albums': new_albums,
         'album_songs': album_songs,})
      memcache.set("new_song_div_html", new_song_div_html)

    template_values = {
      'last_psa': last_psa,
      'playlist_html': playlist_html,
      'session': self.session,
      'flash': self.flashes,
      'new_albums': new_albums,
      'album_songs': album_songs,
      'new_song_div_html': new_song_div_html,
    }
    self.response.out.write(
      template.render(get_path("dj_chartsong.html"), template_values))
Пример #8
0
 def get(self):
   start = datetime.date.today() - datetime.timedelta(days=6)
   end = datetime.date.today() + datetime.timedelta(days=1)
   song_num = 30
   album_num = 30
   songs, albums = Play.get_top(start, end, song_num, album_num)
   template_values = {
     'charts_selected': True,
     'session': self.session,
     'flash': self.flashes,
     'songs': songs,
     'albums': albums,
     'start': start,
     'end': end,
     'login': self.dj_login,
     }
   self.response.out.write(
     template.render(get_path("charts.html"), template_values))
Пример #9
0
  def post(self):
    song_num = 30
    album_num = 30

    # Parse dates
    start_date_req = self.request.get("start_date")
    if start_date_req:
      try:
        start = datetime.datetime.strptime(start_date_req, "%m/%d/%Y").date()
      except ValueError:
        self.session.add_flash(
          "Unable to parse start date. Defaulting to a week ago, today.")
        start = datetime.date.today() - datetime.timedelta(days=6)
    else:
      start = datetime.date.today() - datetime.timedelta(days=6)

    end_date_req = self.request.get("end_date")
    if end_date_req:
      try:
        end = datetime.datetime.strptime(end_date_req, "%m/%d/%Y").date()
      except ValueError:
        self.session.add_flash(
          "Couldn't parse end date. Defaulting to a week of charts.")
        end = start + datetime.timedelta(weeks=1)
    else:
      end = start + datetime.timedelta(weeks=1)

    if self.request.get("song_num"):
      song_num = int(self.request.get("song_num"))
    if self.request.get("album_num"):
      album_num = int(self.request.get("album_num"))
    songs, albums = Play.get_top(start, end, song_num, album_num)
    template_values = {
      'charts_selected': True,
      'session': self.session,
      'flash': self.flashes,
      'songs': songs,
      'albums': albums,
      'start': start,
      'end': end,
      'login': self.dj_login,
    }
    self.response.out.write(
      template.render(get_path("charts.html"), template_values))
Пример #10
0
  def get(self):
    recent_songs = Play.get_last(num=3)
    if recent_songs is not None and len(recent_songs) > 0:
      last_play = recent_songs[0]
      song, program = (last_play.song,
                       last_play.program)
      logging.error(song.raw)
      song_string = song.title
      artist_string = song.artist
      if program is not None:
        program_title, program_desc, program_slug = (program.title,
                                                     program.desc,
                                                     program.slug)
      else:
        program_title, program_desc, program_slug = ("no show",
                                                     "No description",
                                                     "")
    else:
      song, program = None, None
      song_string = "nothing"
      artist_string = "nobody"
      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,
          'artist_string': artist_string,
          'program_title': program_title,
          'program_desc': program_desc,
          'program_slug': program_slug,
          'top_played': ("Top artists: " + ", ".join(
            [a[0] for a in program.top_artists[:3]]) if
                         program is not None else None),
          'recent_songs_html': template.render(
            get_path("recent_songs.html"), {'plays': recent_songs}),
          }))
Пример #11
0
  def post(self):
    if self.request.get("submit") == "Chart Song":
      # Charting a song, not a PSA or ID
      track_artist = self.request.get("artist").encode("latin1", 'replace')
      trackname = self.request.get("trackname").encode("latin1", 'replace')
      isNew = int(self.request.get("isNew"))
      if isNew > 0:
        # if it's "new", the album should be in the datastore already with
        # a valid key.
        album = Album.get(self.request.get("album_key"))
        if not album:
          self.session.add_flash(
            "Missing album information for new song, please try again.")
          self.redirect("/dj/chartsong/")
          return
        # likewise, the song should be in the datastore already with a
        # valid key.
        song = Song.get(self.request.get("song_key"))
        if not song:
          self.session.add_flash(
            "An error occurred trying to fetch the song, please try again.")
          self.redirect("/dj/chartsong/")
          return
        logging.debug(song)
        trackname = song.title
        track_artist = song.artist
        Play.new(song=song, program=self.program_key,
                 play_date=datetime.datetime.now(), is_new=True,
                 artist=album.artist).put()
      else:
        # a song needs to have an artist and a track name
        if not track_artist or not trackname:
          self.session.add_flash(
            "Missing track information, please fill out both fields.")
          self.redirect("/dj/chartsong/")
          return
        song = Song.new(title=trackname, artist=track_artist)
        song.put()

        Play.new(song=song, program=self.program_key,
                 play_date=datetime.datetime.now(), isNew=False,
                 artist=track_artist).put()
      memcache_key = "playlist_html_%s"%self.session.get('program').get('key')
      playlist_html = template.render(
        "dj_chartsong_playlist_div.html",
        {'playlist': Play.get_last(
          program=self.program_key,
          after=(datetime.datetime.now() - datetime.timedelta(days=1)))})
      memcache.set(memcache_key, playlist_html, 60 * 60 * 24)
      ArtistName.try_put(track_artist)

      try:
        # last.fm integration
        lastfm_username = "******"
        lastfm_password = "******"
        lastfm_api_key = "59925bd7155e59bd39f14adcb70b7b77"
        lastfm_secret_key = "6acf5cc79a41da5a16f36d5baac2a484"
        network = pylast.get_lastfm_network(api_key=lastfm_api_key,
          api_secret=lastfm_secret_key,
          username=lastfm_username,
          password_hash=pylast.md5(lastfm_password))
        scrobbler = network.get_scrobbler("tst", "1.0")
        scrobbler.scrobble(track_artist, trackname, int(time.time()),
          pylast.SCROBBLE_SOURCE_USER, pylast.SCROBBLE_MODE_PLAYED, 60)
        self.session.add_flash(
          "%s has been charted and scrobbled to Last.FM,"
          " and should show up below."%trackname)
      except:
        # just catch all errors with the last.fm; it's not that important that
        # everything get scrobbled exactly; plus this is like the #1 source
        # of errors in charting songs.
        self.session.add_flash(
          "%s has been charted, but was not scrobbled to Last.FM"%
          trackname)
      self.redirect("/dj/chartsong/")
      return
      # End of song charting.
    elif self.request.get("submit") == "Station ID":
      # If the DJ has recorded a station ID
      station_id = models._raw_models.StationID(program=self.program_key,
                                    play_date=datetime.datetime.now())
      station_id.put()
      self.session.add_flash("Station ID recorded.")
      self.redirect("/dj/chartsong/")
      return
    elif self.request.get("submit") == "PSA":
      # If the DJ has recorded a PSA play
      psa_desc = self.request.get("psa_desc")
      Psa.new(desc=psa_desc, program=self.program_key).put()
      self.session.add_flash("PSA recorded.")
      self.redirect("/dj/chartsong/")
      return