コード例 #1
0
    def test_crons(self):
        from payparrot_scripts.crons.cron1 import main as cron1
        cron1()
        
        from payparrot_scripts.crons.cron2 import main as cron2
        cron2()
        
        sleep(2)

        parrot = Parrots.findOne(self.db, {})
        
        twitter = Twitter()
        twitter.create_client(parrot.oauth_token, parrot.oauth_token_secret)
        headers, body = twitter.get("http://api.twitter.com/1/statuses/user_timeline.json?user_id=%s&include_rts=false&count=1" % parrot.twitter_info.get('screen_name'))
        json_twitter_status = json.loads(body)

        message_start = self.message.text
        received_message = json_twitter_status[0].get('text')
        self.assertEqual(self.message.text, received_message[0:len(message_start)])

        queue = Queue.get_queue('payments')
        self.assertEqual(0, queue.count())

        from payparrot_scripts.crons.cron3 import main as cron3
        cron3()

        raw_input("Check? ")

        
コード例 #2
0
ファイル: parrots.py プロジェクト: dperezrada/payparrot
def parrots_finish(db):
    if request.query.denied:
        redirect('/twitter_denied.html')
    session = Sessions.findOne(db, {'oauth_token': request.query.oauth_token})
    if session:
        account = Accounts.findOne(db, session.account_id)
        if not account:
            response.status = 404
            return {'error': 'Invalid token'}
        twitter = Twitter()
        try:
            access_tokens = twitter.get_access_tokens(request.query.oauth_verifier,{'oauth_token': session.oauth_token, 'oauth_token_secret': session.oauth_token_secret})
            twitter.create_client(access_tokens.get('oauth_token'),access_tokens.get('oauth_token_secret'))
            headers, body = twitter.get('https://api.twitter.com/1/account/verify_credentials.json')
        except:
            redirect('/twitter_auth_problem.html')
            return
        if headers.status == 200:
            body = json.loads(body)
            parrot = Parrots.findOne(db, {'twitter_id': body.get('id')})
            if not parrot:
                new_parrot = Parrots(db, {
                    'twitter_info': body,
                    'twitter_id': body.get('id'),
                    'oauth_token': access_tokens.get('oauth_token'),
                    'oauth_token_secret': access_tokens.get('oauth_token_secret')
                })
                new_parrot.insert()
                parrot = new_parrot
            else:
                parrot.update({
                    'oauth_token': access_tokens.get('oauth_token'),
                    'oauth_token_secret': access_tokens.get('oauth_token_secret')
                })
            subscription = Subscriptions.findOne(db, {'account_id': account.id, 'parrot_id': parrot.id})
            subscription_parameters = {
                'parrot_id': parrot.id,
                'account_id': account.id,
                'active': True,
                'external_id': session.external_id,
                'twitter_screen_name': body.get("screen_name")
            }
            if not subscription:
                subscription = Subscriptions(db, subscription_parameters)
                subscription.insert()
            else:
                subscription.update(subscription_parameters)
            notification_id = _create_notification(db, account, parrot, subscription)
            if notification_id:
                redirect_url = generate_redirect_url(account.callback_url, session.external_id, subscription.id, notification_id)
                redirect(redirect_url)
    else:
        response.status = 404
        return {'error': 'Expired token'}
コード例 #3
0
ファイル: parrots.py プロジェクト: dperezrada/payparrot
def parrots_start(db):
    account = Accounts.findOne(db,{'credentials.public_token': request.query.get("token")})
    if account:
        twitter = Twitter()
        client = twitter.create_session()
        try:
            tokens = twitter.get_request_token(client)
        except:
            redirect('/twitter_down.html')
            return
        session = Sessions(db, {'account_id': account.id, 'oauth_token': tokens['oauth_token'], 'oauth_token_secret': tokens['oauth_token_secret'], 'external_id': request.query.external_id})
        session.insert()
        redirect_url = twitter.redirect_url(tokens)
        redirect(redirect_url)
    else:
        print "Noooo ---"
        response.status = 404
        return {}
コード例 #4
0
ファイル: cron2.py プロジェクト: dperezrada/payparrot
def tweet_message(parrot, message, id_sqs):
    twitter = Twitter()
    twitter.create_client(parrot.oauth_token, parrot.oauth_token_secret)
    trackable_url = create_trackable_url(id_sqs)
    headers, body = twitter.post("https://api.twitter.com/1/statuses/update.json", {"status": message.get('text')+" "+trackable_url})
    return json.loads(body)