예제 #1
0
파일: main.py 프로젝트: sglickman/WBOR
 def get(self):
   q = self.request.get("query")
   artists = ArtistName.autocomplete(q)
   self.response.out.write(json.dumps({
         'query': q,
         'suggestions': artists,
         }))
예제 #2
0
파일: main.py 프로젝트: sglickman/WBOR
  def get(self):
    labels = Permission.PERMISSIONS
    try:
      seth = Dj.get_by_email("*****@*****.**")
    except NoSuchEntry:
      seth = Dj.new(fullname='Seth Glickman',
                    email='*****@*****.**', username='******',
                    password='******')
      seth.put()
      hchaps = Dj.new(fullname='Harrison Chapman',
                      email="*****@*****.**", username="******",
                      password="******")

      program = Program.new(
        title='Seth\'s Show', slug='seth',
        desc='This is the show where Seth plays his favorite music.',
        dj_list=[seth.key],
        page_html='a <b>BOLD</b> show!')
      program.put()
    for l in labels:
      try:
        permission = Permission.get_by_title(l)
      except NoSuchEntry:
        permission = Permission.new(l, [])
        permission.put()
      finally:
        if seth.key not in permission.dj_list:
          permission.add_dj(seth.key)
          permission.put()
    if not BlogPost.get_last(num=3):
      post1 = BlogPost.new(
        title="Blog's first post!",
        text="This is really just filler text on the first post.",
        slug="first-post", post_date=datetime.datetime.now())
      post1.put()
      time.sleep(2)
      post2 = BlogPost.new(
        title="Blog's second post!",
        text="More filler text, alas.",
        slug="second-post", post_date=datetime.datetime.now())
      post2.put()
      contactspage = BlogPost.new(
        title="Contacts Page",
        text="This is a dummy stub for the contacts page. Lorem ipsum whatnot",
        slug="contacts-page", post_date=datetime.datetime.now())
      contactspage.put()
    artists = [
      "Bear In Heaven",
      "Beck",
      "Arcade Fire",
      "Andrew Bird",
      "The Antlers",
      "Arcade Fire",
      "The Beach Boys",
      "Brian Wilson",
      "The Beatles",
      "Beethoven",
      "Beirut",
      "Belle & Sebastian",
      "Benji Hughes",
      "Club 8",
      "Crayon Fields",
      ]
    for a in artists:
      if not (ArtistName._RAW.query()
              .filter(ArtistName._RAW.artist_name == a)
              .fetch(1, keys_only=True)):
        ar = ArtistName.new(artist_name=a)
        ar.put()
    self.session.add_flash("Permissions set up, ArtistNames set up, "
                           "Blog posts set up, DJ Seth entered.")
    self.redirect('/')
예제 #3
0
파일: dj.py 프로젝트: hchapman/WBOR
  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