def func(templateArguments):
            oauth_token = request.GET.oauth_token
            oauth_secret = request.GET.oauth_token_secret
            oauth_verifier = request.GET.oauth_verifier

            oauth = OAuth1(self.consumer_token,
                           client_secret=self.consumer_secret,
                           resource_owner_key=oauth_token,
                           resource_owner_secret=oauth_secret,
                           verifier=oauth_verifier)
            response = requests.post(
                'https://api.twitter.com/oauth/access_token', auth=oauth)
            if not response.ok:
                return redirect_problem(
                    'Failed to retrieve oauth_secret from twitter')

            response = parse_qs(response.content)
            final_token = response['oauth_token'][0]
            final_token_secret = response['oauth_token_secret'][0]

            logger.info('oauth_token: %s, oauth_secret: %s received' %
                        (final_token, final_token_secret))

            return redirect(
                Display.addArgumentsToLink(self.callback_link,
                                           oauth_token=final_token,
                                           oauth_secret=final_token_secret))
Example #2
0
        def func(templateArguments):
            oauth_token = request.forms.get('oauth_token')
            oauth_secret = request.forms.get('oauth_secret')

            oauth = TwitterInstance.makeAuthTuple(oauth_token, oauth_secret)
            removedInstance = self.application.twitter_instances.removeTwitterInstanceByAuth(
                oauth)

            if removedInstance is not None:
                assert isinstance(removedInstance, TwitterInstance)

                logger.info('Cleaned up twitter instance with oauth: %s' %
                            unicode(oauth))

                try:
                    keywords = ','.join(
                        removedInstance.twitter_thread.twitter_feed.keywords)
                except TypeError:
                    keywords = ''

                regions = removedInstance.geographic_setup_string
                instanceSetupCode = removedInstance.instance_setup_code
            else:
                keywords = None
                regions = None
                instanceSetupCode = None

            return redirect(
                Display.addArgumentsToLink(
                    GateInstance.link_info.getPageLink(),
                    oauth_token=oauth_token,
                    oauth_secret=oauth_secret,
                    keywords=keywords,
                    regions=regions,
                    instance_setup_code=instanceSetupCode))
        def func(templateArguments):
            form = request.forms.decode("UTF-8")

            oauth_token = form.get("oauth_token")
            oauth_secret = form.get("oauth_secret")
            keywords = form.get("keywords")
            geographical_setup_string = unicode(
                form.get("regions")
            )  # includes all geographical information including influence and twitter feed areas.
            instance_setup_code = form.get("instance_setup_code")

            keywordsList = None
            if keywords is not None:
                if len(keywords) > 0:
                    assert isinstance(keywords, basestring)
                    keywordsList = keywords.split(",")

            def redirectError(errorMessage):
                return redirect(
                    Display.addArgumentsToLink(
                        GateInstance.link_info.getPageLink(),
                        oauth_token=oauth_token,
                        oauth_secret=oauth_secret,
                        keywords=keywords,
                        regions=geographical_setup_string,
                        instance_setup_code=instance_setup_code,
                        error=errorMessage,
                    )
                )

            if not oauth_token or not oauth_secret:
                return redirectError("Twitter login credentials are missing")

            oauth = TwitterInstance.makeAuthTuple(oauth_token, oauth_secret)
            if self.application.twitter_instances.isAuthInUse(oauth):
                # Do nothing, we will be redirected to the gate instance which will hopefully
                # correct this mistake.
                pass
            else:
                try:
                    twitterInstance = self.application.twitter_instances.createInstance(
                        TwitterAuthentication(
                            Configuration.CONSUMER_TOKEN, Configuration.CONSUMER_SECRET, oauth_token, oauth_secret
                        ),
                        geographical_setup_string,
                        keywordsList,
                        instance_setup_code,
                    )
                except ValueError as e:
                    return redirectError("Failed to setup instance, reason: %s" % e.message)

                error = twitterInstance.setup_error
                if error is not None:
                    return redirectError(error)

            return redirect(
                Display.addArgumentsToLink(
                    GateInstance.link_info.getPageLink(), oauth_token=oauth_token, oauth_secret=oauth_secret
                )
            )
        def func(templateArguments):
            oauth_token = request.forms.get("oauth_token")
            oauth_secret = request.forms.get("oauth_secret")

            oauth = TwitterInstance.makeAuthTuple(oauth_token, oauth_secret)
            removedInstance = self.application.twitter_instances.removeTwitterInstanceByAuth(oauth)

            if removedInstance is not None:
                assert isinstance(removedInstance, TwitterInstance)

                logger.info("Cleaned up twitter instance with oauth: %s" % unicode(oauth))

                try:
                    keywords = ",".join(removedInstance.twitter_thread.twitter_feed.keywords)
                except TypeError:
                    keywords = ""

                regions = removedInstance.geographic_setup_string
                instanceSetupCode = removedInstance.instance_setup_code
            else:
                keywords = None
                regions = None
                instanceSetupCode = None

            return redirect(
                Display.addArgumentsToLink(
                    GateInstance.link_info.getPageLink(),
                    oauth_token=oauth_token,
                    oauth_secret=oauth_secret,
                    keywords=keywords,
                    regions=regions,
                    instance_setup_code=instanceSetupCode,
                )
            )
Example #5
0
        def func(templateArguments):
            form = request.forms.decode('UTF-8')

            oauth_token = form.get('oauth_token')
            oauth_secret = form.get('oauth_secret')
            keywords = form.get('keywords')
            geographical_setup_string = unicode(
                form.get('regions')
            )  # includes all geographical information including influence and twitter feed areas.
            instance_setup_code = form.get('instance_setup_code')

            keywordsList = None
            if keywords is not None:
                if len(keywords) > 0:
                    assert isinstance(keywords, basestring)
                    keywordsList = keywords.split(',')

            def redirectError(errorMessage):
                return redirect(
                    Display.addArgumentsToLink(
                        GateInstance.link_info.getPageLink(),
                        oauth_token=oauth_token,
                        oauth_secret=oauth_secret,
                        keywords=keywords,
                        regions=geographical_setup_string,
                        instance_setup_code=instance_setup_code,
                        error=errorMessage))

            if not oauth_token or not oauth_secret:
                return redirectError('Twitter login credentials are missing')

            oauth = TwitterInstance.makeAuthTuple(oauth_token, oauth_secret)
            if self.application.twitter_instances.isAuthInUse(oauth):
                # Do nothing, we will be redirected to the gate instance which will hopefully
                # correct this mistake.
                pass
            else:
                try:
                    twitterInstance = self.application.twitter_instances.createInstance(
                        TwitterAuthentication(Configuration.CONSUMER_TOKEN,
                                              Configuration.CONSUMER_SECRET,
                                              oauth_token, oauth_secret),
                        geographical_setup_string, keywordsList,
                        instance_setup_code)
                except ValueError as e:
                    return redirectError(
                        'Failed to setup instance, reason: %s' % e.message)

                error = twitterInstance.setup_error
                if error is not None:
                    return redirectError(error)

            return redirect(
                Display.addArgumentsToLink(
                    GateInstance.link_info.getPageLink(),
                    oauth_token=oauth_token,
                    oauth_secret=oauth_secret))
Example #6
0
 def redirectError(errorMessage):
     return redirect(
         Display.addArgumentsToLink(
             GateInstance.link_info.getPageLink(),
             oauth_token=oauth_token,
             oauth_secret=oauth_secret,
             keywords=keywords,
             regions=geographical_setup_string,
             instance_setup_code=instance_setup_code,
             error=errorMessage))
 def redirectError(errorMessage):
     return redirect(
         Display.addArgumentsToLink(
             GateInstance.link_info.getPageLink(),
             oauth_token=oauth_token,
             oauth_secret=oauth_secret,
             keywords=keywords,
             regions=geographical_setup_string,
             instance_setup_code=instance_setup_code,
             error=errorMessage,
         )
     )
        def func(templateArguments):
            oauth_token = request.GET.oauth_token
            oauth_secret = request.GET.oauth_token_secret
            oauth_verifier = request.GET.oauth_verifier

            oauth = OAuth1(self.consumer_token, client_secret=self.consumer_secret, resource_owner_key=oauth_token, resource_owner_secret=oauth_secret, verifier=oauth_verifier)
            response = requests.post('https://api.twitter.com/oauth/access_token', auth=oauth)
            if not response.ok:
                return redirect_problem('Failed to retrieve oauth_secret from twitter')

            response = parse_qs(response.content)
            final_token = response['oauth_token'][0]
            final_token_secret = response['oauth_token_secret'][0]

            logger.info('oauth_token: %s, oauth_secret: %s received' % (final_token, final_token_secret))

            return redirect(Display.addArgumentsToLink(self.callback_link, oauth_token=final_token, oauth_secret=final_token_secret))
Example #9
0
 def getLandingPageLink(pageNum):
     return Display.addArgumentsToLink(LandingPage.link_info.getPageLink(),
                                       page=pageNum)
Example #10
0
 def getLandingPageLink(pageNum):
     return Display.addArgumentsToLink(LandingPage.link_info.getPageLink(),page=pageNum)