def get(self): auth = BasicAuthHandler("user", "password") api = API(auth, source="3990552168") timeline = api.user_timeline(count=1, page=1)[0] tweet = Tweet.all().get() if not tweet: tweet = Tweet(text=timeline.text, date=timeline.created_at) tweet.text = timeline.text tweet.date = timeline.created_at tweet.put()
def get(self): # Get text chosen randomly from DataBase query = Tweet.all() # If there is no bot text if not query.count(): return tweets = query.fetch(query.count()) tweet = tweets[randint(0, query.count() - 1)] # Tweet the text wkm = Wakametter(ACCESS["key"], ACCESS["secret"]) try: wkm.tweet(tweet.text) except TweepError: pass
def initialize(self, request, response): webapp.RequestHandler.initialize(self, request, response) os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from model import g_blog,User self.blog = g_blog self.login_user = users.get_current_user() self.is_login = (self.login_user != None) self.loginurl=users.create_login_url(self.request.uri) self.logouturl=users.create_logout_url(self.request.uri) self.is_admin = users.is_current_user_admin() self.tweet = Tweet.all().get(); if self.is_admin: self.auth = 'admin' self.author=User.all().filter('email =',self.login_user.email()).get() if not self.author: self.author=User(dispname=self.login_user.nickname(),email=self.login_user.email()) self.author.isadmin=True self.author.user=self.login_user self.author.put() elif self.is_login: self.author=User.all().filter('email =',self.login_user.email()).get() if self.author: self.auth='author' else: self.auth = 'login' else: self.auth = 'guest' try: self.referer = self.request.headers['referer'] except: self.referer = None self.template_vals = {'self':self,'blog':self.blog,'current':self.current,'tweet':self.tweet}
def get(self): # Make new session when there is no session. if not self.session.get("user"): new_id = binascii.hexlify(os.urandom(8)) me = Wakametter(ACCESS["key"], ACCESS["secret"]).me self.session["user"] = {"id" : new_id, "name": me.screen_name, "icon": me.profile_image_url } # Get User user = self.session.get("user") # Get texts of twitter-bot query = Tweet.all().order("-date") tweets = query.fetch(query.count()) # Render template_values = { "user_name": user["name"], "icon_src" : user["icon"], "tweets" : tweets } self.render("home.html", template_values)