コード例 #1
0
ファイル: main.py プロジェクト: userid/TwitterSinaSync
    def get(self):
        invitationCode = self.request.get('invitation_code')
        if not self.isValidInvitationCode(invitationCode):
            error_output(self, "<html><body>邀请码无效</body></html>", "text/html", 400)
            return
        auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        
        verifier = self.request.get("oauth_verifier").strip()
        twitterId = self.request.get("twitter_id").strip()
        if verifier == "" or twitterId == "":
            authUrl = auth.get_authorization_url()
            success_output(self, page_goto_sina_oauth % \
                {'url':authUrl, 
                 'invitation':invitationCode.encode('UTF-8'),
                 'token':auth.request_token.key, 
                 'secret':auth.request_token.secret})
        else:
            request_token = self.request.get("request_token")
            request_secret = self.request.get("request_secret")
            auth.set_request_token(request_token, request_secret)
            accessToken = auth.get_access_token(verifier)
            binding = SyncBinding.getOrInsertByInvitationCode(invitationCode)
            binding.lastTweetId = None
            binding.twitterId = twitterId
            binding.sinaAccessToken = accessToken.key
            binding.sinaAccessSecret = accessToken.secret
            binding.put()
            success_output(self, '''
<html><body>
<p>Twitter与新浪微博同步绑定成功</p>
<p>如需要修改绑定,请重新访问邀请链接</p>
</body></html>
            ''')
コード例 #2
0
def syncAll(CONSUMER_KEY, CONSUMER_SECRET):
    bindings = SyncBinding.all()
    bindings.order("nextSyncTime")
    for binding in bindings:
        if binding.nextSyncTime > time.time():
            return
        synchronousMsg(CONSUMER_KEY, CONSUMER_SECRET, binding);
コード例 #3
0
def syncAll(CONSUMER_KEY, CONSUMER_SECRET):
    bindings = SyncBinding.all()
    bindings.order("nextSyncTime")
    for binding in bindings:
        if binding.nextSyncTime > time.time():
            return
        synchronousMsg(CONSUMER_KEY, CONSUMER_SECRET, binding)
コード例 #4
0
    def get(self):
        invitationCode = self.request.get('invitation_code')
        if not self.isValidInvitationCode(invitationCode):
            error_output(self, "<html><body>邀请码无效</body></html>", "text/html",
                         400)
            return
        auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)

        verifier = self.request.get("oauth_verifier").strip()
        twitterId = self.request.get("twitter_id").strip()
        if verifier == "" or twitterId == "":
            authUrl = auth.get_authorization_url()
            success_output(self, page_goto_sina_oauth % \
                {'url':authUrl,
                 'invitation':invitationCode.encode('UTF-8'),
                 'token':auth.request_token.key,
                 'secret':auth.request_token.secret})
        else:
            request_token = self.request.get("request_token")
            request_secret = self.request.get("request_secret")
            auth.set_request_token(request_token, request_secret)
            accessToken = auth.get_access_token(verifier)
            binding = SyncBinding.getOrInsertByInvitationCode(invitationCode)
            binding.lastTweetId = None
            binding.twitterId = twitterId
            binding.sinaAccessToken = accessToken.key
            binding.sinaAccessSecret = accessToken.secret
            binding.put()
            success_output(
                self, '''
<html><body>
<p>Twitter与新浪微博同步绑定成功</p>
<p>如需要修改绑定,请重新访问邀请链接</p>
</body></html>
            ''')
コード例 #5
0
ファイル: main.py プロジェクト: userid/TwitterSinaSync
    def get(self):
        content = """
<html><body><table border="1">
<tr><th>Invatation Code</th><th>Twitter ID</th><th>Last synced tweet</th><th>Next sync(GMT)</th>
<th>Sina token</th><th>Sina secret</th></tr>
            """
        bindings = SyncBinding.all()
        for binding in bindings:
            content += "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % \
                (binding.invitationCode, binding.twitterId, binding.lastTweetId, 
                 time.ctime(binding.nextSyncTime),
                 binding.sinaAccessToken, binding.sinaAccessSecret)
        content += "</table></body></html>"
        success_output(self, content)
コード例 #6
0
    def get(self):
        content = """
<html><body><table border="1">
<tr><th>Invatation Code</th><th>Twitter ID</th><th>Last synced tweet</th><th>Next sync(GMT)</th>
<th>Sina token</th><th>Sina secret</th></tr>
            """
        bindings = SyncBinding.all()
        for binding in bindings:
            content += "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % \
                (binding.invitationCode, binding.twitterId, binding.lastTweetId,
                 time.ctime(binding.nextSyncTime),
                 binding.sinaAccessToken, binding.sinaAccessSecret)
        content += "</table></body></html>"
        success_output(self, content)