Example #1
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 #4
0
        def onInstanceLoadFunc(instanceKey,
                               oauthToken,
                               oauthSecret,
                               geographicSetupString,
                               keywords,
                               instanceSetupCode,
                               startTime,
                               temporalLastTimeId,
                               count=count):
            temporal = dict()
            for providerId, value in temporalLastTimeId.iteritems():
                providerId = int(providerId)
                for placeId, timeId in value.iteritems():
                    placeId = int(placeId)
                    timeId = int(timeId)
                    temporal[GeocodeResultAbstract.buildCacheIdTuple(
                        providerId, placeId)] = timeId
                    logger.debug(
                        'Loaded instance %s last temporal change source %d/%d -> %d'
                        % (instanceKey, providerId, placeId, timeId))

            TwitterInstance(
                instanceKey, webApplication.twitter_instances,
                TwitterAuthentication(Configuration.CONSUMER_TOKEN,
                                      Configuration.CONSUMER_SECRET,
                                      oauthToken, oauthSecret),
                unicode(geographicSetupString), keywords, instanceSetupCode,
                startTime, temporal)

            # can delete, was debugging indexes.
            if args.rebuild_instance_indexes:
                logger.info('Dropping indexes of instance %s' % instanceKey)
                getUserCollection(instanceKey).drop_indexes()
                getTweetCollection(instanceKey).drop_indexes()
            count[0] += 1
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))
        def func(templateArguments):
            oauth_token = request.GET.oauth_token
            oauth_secret = request.GET.oauth_secret
            templateArguments.update({"oauth_token": oauth_token, "oauth_secret": oauth_secret})

            oauth = TwitterInstance.makeAuthTuple(oauth_token, oauth_secret)
            if not self.application.twitter_instances.isAuthInUse(oauth):
                return self.start_instance_get(templateArguments)
            else:
                return self.manage_instance_get(templateArguments, oauth)
Example #7
0
        def func(templateArguments):
            oauth_token = request.GET.oauth_token
            oauth_secret = request.GET.oauth_secret
            templateArguments.update({
                'oauth_token': oauth_token,
                'oauth_secret': oauth_secret
            })

            oauth = TwitterInstance.makeAuthTuple(oauth_token, oauth_secret)
            if not self.application.twitter_instances.isAuthInUse(oauth):
                return self.start_instance_get(templateArguments)
            else:
                return self.manage_instance_get(templateArguments, oauth)