Beispiel #1
0
  def post(self):
    status = self.request.get('status')
    phone = self.request.get('phone')
    count = int(self.request.get('count'))

    tuser = TwitterUser.get_by_phonenumber(phone)
    if tuser == None:
      logging.warning("Could not fetch tuser based on phone number %s",phone)
      return

    client = OAuthClient('twitter', self)
    try:
      info = client.post('/statuses/update', 'POST', (200,401,403), tuser, status=status)
      if 'error' in info:
        logging.warning("Submiting failed as credentials were incorrect (user:%s) %s", tuser.user, info['error'])
        tuser.lastError = "Twitter returned '%s' for your last update. You may be over limit or may have to register with SMSTweet again" % info['error']
        tuser.put()
      else:
        logging.debug("updated the status for user %s", tuser.user)
        Tweet.save_tweet(info)

    except (urlfetch.DownloadError, ValueError), e:
      logging.warning("Update:update (%d) could not be fetched. %s " % (count,e))
      if count > 10:
        logging.error("Tried updating the message 10 times. Finally giving up.")
      else:
        # Try again
        taskqueue.add(url = '/tasks/post_message', params = { 'phone' : phone, 'count' : count + 1, 'status' : status })
Beispiel #2
0
    def get(self):
        tusers = TwitterUser.all().filter("tweetCount >", 0).order("-tweetCount").fetch(40)
        tweets = Tweet.all().order("-created_at").fetch(10)
        regexp = re.compile("@(\w+)")
        for t in tweets:
            t.status = regexp.sub(r"<a href='/user/\1'>@\1</a>", t.status)

        values = {"highestTweeters": tusers, "tweets": tweets}
        self.response.out.write(template.render("stats.html", values))
Beispiel #3
0
    def get(self, user=""):
        tuser = tweets = None
        if user == "":
            self.redirect("/stats")
            return

        tusers = TwitterUser.all().filter("user = "******"screen_name = ", tuser.user).order("-created_at").fetch(10)

            regexp = re.compile("@(\w+)")
            for t in tweets:
                t.status = regexp.sub(r"@<a href='/user/\1'>\1</a>", t.status)
            values = {"tuser": tuser, "tweets": tweets}
            self.response.out.write(template.render("tuser.html", values))
        else:
            self.redirect("http://twitter.com/%s" % user)