예제 #1
0
 def post(self):
   logging_now()
   client = twitter_oauth_handler.OAuthClient('twitter', self)
   if client.get_cookie():
       client = twitter_oauth_handler.OAuthClient('twitter', self)
       info = client.get('/account/verify_credentials')
       username = info['screen_name']
       logging.info(username)
       gpid = self.request.get("gpid")
       if re.search(r"\d*",gpid).group():
           #buzztopic = "http://buzz.googleapis.com/feeds/%s/public/posted" % gpid
           buzztopic = "https://www.googleapis.com/buzz/v1/activities/%s/@public" % gpid
           #topic = "http://www.google.com/reader/public/atom/user/%s/state/com.google/broadcast" % grid
           logging.info(gpid)
           issync = self.request.get("mode")
           buzzlink = self.request.get("buzzlink")
           gruser = is_user(username)
           if issync == "subscribe":
               if gruser:
                   gruser.buzztopic = buzztopic
                   gruser.buzzlink = buzzlink
                   gruser.put()
               else:
                   logging.info("new user")
                   gruser = GRUser(key_name='Key_Twitter_'+username,username = username,buzztopic = buzztopic)
                   gruser.buzzlink = buzzlink
                   gruser.put()
           elif gruser:
               logging.info(issync)
               logging.debug("用户退订")
               logging.debug(gruser.username) 
               #gruser.put()  
               #return                                           
           payload = {"hub.mode":issync,"hub.verify":"sync","hub.callback":"http://reader2twitter.appspot.com/buzzpush","hub.topic":buzztopic}
           payload= urllib.urlencode(payload)
           url = "http://pubsubhubbub.appspot.com/subscribe"
           try:
               result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST)
               logging.info(result.status_code)
               if result.status_code == 204 or result2.status_code == 204:  
                   logging.info("%s success" % issync)  
                   if issync == "unsubscribe":
                       self.response.out.write('You have stopped sync. Any suggestion to <a href="http://twitter.com/gr2t">gr2t</a>?')
                   else:
                       self.response.out.write("You sync is established. Wish you can share this tool in greader:) <a href=\"javascript:var%20b=document.body;var%20GR________bookmarklet_domain='http://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}\">click to share</a>")
               else:
                   logging.info("向hub订阅Publisher失败")
                   self.response.out.write('Please <a href="/buzz">retry</a>')
           except:
               logging.info("和hub连接失败")
               self.response.out.write('Please <a href="/buzz">retry</a>')
       else:
           logging.info("google reader id格式错误")
           self.response.out.write('Please use Google Profile <b>number</b> ID,<a href="/buzz">retry</a>')
   else:
       logging.info("没有oauth认证")
       self.response.out.write('Please <a href="/buzz">sign in</a>')
 def get(self):
   auth_client = _oauth(self)
   if not auth_client.get_cookie():
       self.response.out.write('请<a href="/oauth/weibo/login">登录</a>')   
       return
   try:
       username =  auth_client.get_username()
   except:
       self.redirect('/oauth/weibo/login')
       return
   gruser = GRUser.get_by_key_name('Key_Weibo_%s' % username)
   template_value = {}
   if gruser:
       mygruser = {}
       mygruser["username"]=gruser.username
       mygruser["format"]=gruser.format
       mygruser["bitlykey"]=gruser.bitlykey
       mygruser["bitlylogin"]=gruser.bitlylogin        
       mygruser["synctype"]={}
       mygruser["readerid"]=""
       if gruser.topic:
           mygruser["readerid"] = gruser.topic.replace("http://www.google.com/reader/public/atom/user/","")
           mygruser["readerid"] = mygruser["readerid"].replace("/state/com.google/broadcast","")
       if not gruser.synctype:
           mygruser["synctype"] = {"all":"checked","comment":"","Note":""}    
       elif gruser.synctype == "all":
           mygruser["synctype"] = {"all":"checked","comment":"","Note":""}
       elif gruser.synctype == "comment":
           mygruser["synctype"] = {"all":"","comment":"checked","Note":""}
       else:
           mygruser["synctype"] = {"all":"","comment":"","Note":"checked"}       
       template_value = {"gruser":mygruser}         
   self.response.out.write(template.render('syncweibo.html', template_value))
예제 #3
0
def get_user_by_topic(topic):
    """return the user who subscribe the topic
    parameter:topic"""
    query = GRUser.all().filter("topic = ",topic)
    if query.count() == 0:
        return False
    else:
        return query  
예제 #4
0
def is_user(username):
    query = GRUser.all().filter("username = ",username)
    if query.count()==0:
        return None
    else:
        for gruser in query:
            return gruser
            break 
예제 #5
0
def get_user_by_buzztopic(topic):
    """return the user who subscribe the topic
    parameter:topic"""
    if '?' in topic:
      topic = topic[:topic.find('?')]
    query = GRUser.all().filter("bt = ",topic)
    if query.count() == 0:
        return False
    else:
        return query  
 def post(self):
   auth_client = _oauth(self)
   if auth_client.get_cookie():
       username = auth_client.get_username()
       logging.info(username)
       grid = self.request.get("grid")
       if re.search(r"\d*",grid).group():
           topic = "http://www.google.com/reader/public/atom/user/%s/state/com.google/broadcast" % grid
           issync = self.request.get("mode")
           gruser = GRUser.get_by_key_name('Key_Weibo_%s' % username)
           if issync == "subscribe":
               synctype = self.request.get("synctype")
               logging.info(synctype)
               if gruser:
                   gruser.topic = topic
                   gruser.synctype = synctype
                   gruser.unsubscribe = False
                   gruser.put()
               else:
                   logging.info("新用户")
                   gruser = GRUser(key_name='Key_Weibo_'+username,username = username,topic = topic)
                   gruser.put()
           elif gruser:
               logging.debug("用户退订")
               logging.debug(gruser.username)
               gruser.unsubscribe = True
               gruser.put()  
               return                
           payload = {"hub.mode":issync,"hub.verify":"sync","hub.callback":"http://reader2twitter.appspot.com/subscriber","hub.topic":topic}
           payload= urllib.urlencode(payload)
           url = "http://pubsubhubbub.appspot.com/subscribe"
           try:
               result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST)#, headers=headers)
               logging.info(result.status_code)
               if result.status_code == 204:  
                   logging.info("%s success" % issync)  
                   if issync == "unsubscribe":
                       self.response.out.write('同步已被停止。如果有问题,请联系<a href="http://t.sina.com.cn/kangye">开发者</a>。')
                   else:
                       self.response.out.write("同步已设置成功。<a href=\"javascript:var%20b=document.body;var%20GR________bookmarklet_domain='http://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}\">点击测试</a>")
               else:
                   logging.info("向hub订阅Publisher失败")
                   self.response.out.write('请<a href="/weibo/greader.settings">重试</a>')
           except:
               logging.info("和hub连接失败")
               self.response.out.write('请<a href="/weibo/greader.settings">重试</a>')
       else:
           logging.info("google reader id格式错误")
           self.response.out.write('请试用Google Reader<b>数字</b>ID,<a href="/weibo/greader.settings">重试</a>')
   else:
       logging.info("没有oauth认证")
       self.response.out.write('请<a href="/oauth/weibo/login">登录</a>')
예제 #7
0
 def get(self):
     client = twitter_oauth_handler.OAuthClient('twitter', self)
     
     if not client.get_cookie():
         self.redirect('/')
         return
     
     info = client.get('/account/verify_credentials')
     
     if not info:
       self.response.out.write('Error occured when conmunicating with Twitter. Please <a href="/">try again</a>.')
     else:
       username = info['screen_name']
       gruser = is_user(username)
       language = get_language(self)
       if not gruser:
           gruser = GRUser(key_name='Key_Twitter_'+username,username = username, oauth = True)
           gruser.put()
           logging.debug("New Twitter-Login user.")
           logging.info(username)
       else:
           gruser.oauth = True
           gruser.put()
       if language == "cn":
           self.redirect('/cnuser')
       else:
           self.redirect('/enuser')
 def get(self):
     auth_client = _oauth(self)
     if not auth_client.get_cookie():
         self.redirect('/')
         return
     
     username =  auth_client.get_username()
     if not username:
       self.response.out.write('Error occured when conmunicating with Twitter. Please <a href="/">try again</a>.')
     else:
       gruser = GRUser.get_by_key_name('Key_Weibo_%s' % username)
       if not gruser:
           gruser = GRUser(key_name='Key_Weibo_'+username,username = username, oauth = True)
           gruser.put()
           logging.debug("New Weibo-Login user.")
           logging.info(username)
       else:
           gruser.oauth = True
           gruser.put()
       self.redirect('/weibo/greader.settings')
예제 #9
0
 def post(self):
   logging_now()
   client = twitter_oauth_handler.OAuthClient('twitter', self)
   if client.get_cookie():
       client = twitter_oauth_handler.OAuthClient('twitter', self)
       try:
           info = client.get('/account/verify_credentials')
       except DownloadError, e:
           self.response.out.write("Twitter connection error. Please retry:)")
       if not info:
           self.response.out.write('Twitter connection error. Please <a href="/">retry</a>:)')
       username = info['screen_name']
       logging.info(username)
       #self.response.out.write("登录成功")
       grid = self.request.get("grid")
       if re.search(r"\d*",grid).group():
           topic = "http://www.google.com/reader/public/atom/user/%s/state/com.google/broadcast" % grid
           logging.info(grid)
           issync = self.request.get("mode")
           gruser = is_user(username)
           if issync == "subscribe":
               format = self.request.get("format")
               synctype = self.request.get("synctype")
               bitlylogin = self.request.get("bitlylogin")
               bitlykey = self.request.get("bitlykey")                
               logging.info(synctype)
               if gruser:
                   gruser.topic = topic
                   gruser.format = format
                   gruser.synctype = synctype
                   gruser.bitlylogin = bitlylogin
                   gruser.bitlykey = bitlykey
                   gruser.unsubscribe = False
                   gruser.put()
               else:
                   logging.info("new user")
                   gruser = GRUser(key_name='Key_Twitter_'+username,username = username,topic = topic, format = format)
                   gruser.put()
           elif gruser:
               logging.info(issync)
               logging.debug("用户退订")
               logging.debug(gruser.username) 
               gruser.unsubscribe = True
               gruser.put()  
           payload = {"hub.mode":issync,"hub.verify":"sync","hub.callback":"http://reader2twitter.appspot.com/subscriber","hub.topic":topic}
           payload= urllib.urlencode(payload)
           url = "http://pubsubhubbub.appspot.com/subscribe"
           try:
               result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST)
               if result.status_code == 204:
                   fetch_queue = taskqueue.Queue("fetch-old")
                   task = taskqueue.Task(url='/fetchold',params=dict(topic=topic))
                   fetch_queue.add(task)  
                   logging.info("%s success" % issync)              
                   if issync == "unsubscribe":
                       self.response.out.write('You have stopped sync. Any suggestion to <a href="http://twitter.com/gr2t">gr2t</a>?')
                   else:
                       self.response.out.write("You sync is established. Wish you can share this tool in greader:) <a href=\"javascript:var%20b=document.body;var%20GR________bookmarklet_domain='http://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}\">click to share</a>")
                       
               else:
                   logging.info("向hub订阅Publisher失败")
                   self.response.out.write('Please <a href="/enuser">retry</a>')
           except:
               logging.info("和hub连接失败")
               self.response.out.write('Please <a href="/enuser">retry</a>')
       else:
           logging.info("google reader id格式错误")
           self.response.out.write('Please use Google Reader <b>number</b> ID,<a href="/enuser">retry</a>')
예제 #10
0
 def post(self):
   client = twitter_oauth_handler.OAuthClient('twitter', self)
   if client.get_cookie():
       client = twitter_oauth_handler.OAuthClient('twitter', self)
       info = client.get('/account/verify_credentials')
       username = info['screen_name']
       logging.info(username)
       #self.response.out.write("登录成功")
       grid = self.request.get("grid")
       if re.search(r"\d*",grid).group():
           topic = "http://www.google.com/reader/public/atom/user/%s/state/com.google/broadcast" % grid
           issync = self.request.get("mode")
           gruser = is_user(username)
           if issync == "subscribe":
               format = self.request.get("format")
               synctype = self.request.get("synctype")
               bitlylogin = self.request.get("bitlylogin")
               bitlykey = self.request.get("bitlykey")                
               logging.info(synctype)
               if gruser:
                   gruser.topic = topic
                   gruser.format = format
                   gruser.synctype = synctype
                   gruser.bitlykey = bitlykey
                   gruser.bitlylogin = bitlylogin
                   gruser.unsubscribe = False
                   gruser.put()
               else:
                   logging.info("新用户")
                   #basestring = base64.encodestring('%s:%s' % (username, password))[:-1]
                   gruser = GRUser(key_name='Key_Twitter_'+username,username = username,topic = topic, format = format)
                   gruser.put()
           elif gruser:
               logging.debug("用户退订")
               logging.debug(gruser.username)
               gruser.unsubscribe = True
               gruser.put()  
               return                
               #gruser.delete()            
           payload = {"hub.mode":issync,"hub.verify":"sync","hub.callback":"http://reader2twitter.appspot.com/subscriber","hub.topic":topic}
           payload= urllib.urlencode(payload)
           url = "http://pubsubhubbub.appspot.com/subscribe"
           try:
               result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST)
               logging.info(result.status_code)
               if result.status_code == 204:  
                   logging.info("%s success" % issync)  
                   if issync == "unsubscribe":
                       self.response.out.write('You have stopped sync. Any suggestion to <a href="http://twitter.com/gr2t">gr2t</a>?')
                   else:
                       self.response.out.write("You sync is established. Wish you can share this tool in greader:) <a href=\"javascript:var%20b=document.body;var%20GR________bookmarklet_domain='http://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}\">click to share</a>")
               else:
                   logging.info("向hub订阅Publisher失败")
                   self.response.out.write('Please <a href="/buzz">retry</a>')
           except:
               logging.info("和hub连接失败")
               self.response.out.write('Please <a href="/buzz">retry</a>')
       else:
           logging.info("google reader id格式错误")
           self.response.out.write('Please use Google Profile <b>number</b> ID,<a href="/buzz">retry</a>')
   else:
       logging.info("没有oauth认证")
       self.response.out.write('Please <a href="/buzz">sign in</a>')