Ejemplo n.º 1
0
    def get(self):
      playlist_key = self.request.get('playlist')
      q = PlaylistHeader.gql('WHERE playlist = :1', playlist_key)
      if q.count() == 0:
          return
      head = q.fetch(1)[0]

      q = PlaygrubAccount.gql('WHERE service = :1', 'bit.ly')
      if q.count(1) == 0:
          return
      bitly_account = q.fetch(1)[0]

      play_url = pghost+urllib.quote('#xspf='+pghost+head.playlist+'.xspf')
      login = bitly_account.user
      password = bitly_account.password
      shorten_url = 'http://api.bit.ly/shorten?version=2.0.1&login='******'&apiKey='+password+'&history=1&longUrl='+play_url
      result = urlfetch.fetch(shorten_url, payload=None, method=urlfetch.GET, headers={})
      # logging.error('bitly result -> %s', result.content)
      sre = re.compile('.*shortUrl.*(http.*)"')
      search = sre.search(result.content)
      if not search:
          return
      shortened_url = search.group(1)
      # logging.error('shortened_url -> %s', shortened_url)


      q = PlaygrubAccount.gql('WHERE service = :1','twitter')
      if q.count(1) == 0:
          return
      twitter_account = q.fetch(1)[0]


      message = head.title + ' ' + shortened_url
      login = twitter_account.user
      password = twitter_account.password
      payload= {'status' : message.encode('utf-8'),  'source' : 'Playgrub'}
      payload = urllib.urlencode(payload)

      base64string = base64.encodestring('%s:%s' % (login, password))[:-1]
      headers = {'Authorization': "Basic %s" % base64string}

      url = "http://twitter.com/statuses/update.xml"
      result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST, headers=headers)
      # logging.error('twitter result -> %s', result.content)

      self.response.headers['Content-Type'] = 'text/plain'
      self.response.out.write(result.content)
Ejemplo n.º 2
0
    def get(self):
        delete = self.request.get("delete")
        if delete:
            account = db.get(delete)
            account.delete()

        q = PlaygrubAccount.all()
        accounts = q.fetch(100)

        template_values = {"accounts": accounts}
        path = os.path.join(os.path.dirname(__file__), "html/admin_accounts.html")
        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 3
0
    def post(self):
        service = self.request.get("service")
        user = self.request.get("user")
        password = self.request.get("password")

        q = PlaygrubAccount.gql("where service = :1", service)
        if q.count(1) > 0:
            account = q.fetch(1)[0]
        else:
            account = PlaygrubAccount()

        account.service = service
        account.user = user
        account.password = password
        db.put(account)

        q = PlaygrubAccount.all()
        accounts = q.fetch(100)

        template_values = {"accounts": accounts}
        path = os.path.join(os.path.dirname(__file__), "html/admin_accounts.html")
        self.response.out.write(template.render(path, template_values))