Exemple #1
0
    def init(self):
        if xmltodict is None:
            raise MissingDependencyError("xmltodict")

        self.set_request_parameters()
        self.session = create_request_session_from_bot(self)
        self.dns_name = getattr(self.parameters, "dns_name", None)
        if self.dns_name is None:
            raise ValueError('No dns name provided.')
        self.request_duration = getattr(self.parameters, "request_duration",
                                        None)
        if self.request_duration is None:
            raise ValueError('No request_duration provided.')
        user = getattr(self.parameters, "http_username", None)
        if user is None:
            raise ValueError('No http_username provided.')
        pw = getattr(self.parameters, "http_password", None)
        if pw is None:
            raise ValueError('No http_password provided.')

        # create auth token
        token = user + ":" + pw
        message_bytes = token.encode('ascii')
        base64_bytes = base64.b64encode(message_bytes)
        base64_message = base64_bytes.decode('ascii')
        self.http_header = {'Authorization': 'Basic ' + base64_message}
        self.custom_auth_url = "https://" + self.dns_name + "/wsapis/v2.0.0/auth/login"
Exemple #2
0
    def init(self):
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')

        self.set_request_parameters()

        self.session = create_request_session_from_bot(self)
Exemple #3
0
    def init(self):
        if requests is None:
            raise MissingDependencyError("requests")

        self.set_request_parameters()

        self.session = create_request_session_from_bot(self)
Exemple #4
0
    def init(self):
        if requests is None:
            raise ValueError("Could not import 'requests'. Please install it.")
        if twitter is None:
            raise ValueError("Could not import 'twitter'. Please install it.")
        self.current_time_in_seconds = int(time.time())
        self.target_timelines = []
        if getattr(self.parameters, "target_timelines", '') is not '':
            self.target_timelines.extend(
                self.parameters.target_timelines.split(','))
        self.tweet_count = int(getattr(self.parameters, "tweet_count", 20))
        self.follow_urls = []
        if getattr(self.parameters, "follow_urls", '') is not '':
            self.follow_urls.extend(self.parameters.follow_urls.split(','))
        self.include_rts = getattr(self.parameters, "include_rts", False)
        self.exclude_replies = getattr(self.parameters, "exclude_replies",
                                       False)
        self.timelimit = int(
            getattr(self.parameters, "timelimit", 24 * 60 * 60))
        self.api = twitter.Api(
            consumer_key=self.parameters.consumer_key,
            consumer_secret=self.parameters.consumer_secret,
            access_token_key=self.parameters.access_token_key,
            access_token_secret=self.parameters.access_token_secret,
            tweet_mode="extended")

        self.set_request_parameters()
        self.session = create_request_session_from_bot(self)
Exemple #5
0
    def init(self):
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')
        if rt is None:
            raise ValueError('Could not import rt. Please install it.')

        if getattr(self.parameters, 'search_not_older_than', None):
            try:
                self.not_older_than = parser.parse(
                    self.parameters.search_not_older_than)
                self.not_older_than_type = 'absolute'
            except ValueError:
                try:
                    self.not_older_than_relative = timedelta(
                        minutes=parse_relative(
                            self.parameters.search_not_older_than))
                except ValueError:
                    self.logger.error(
                        "Parameter 'search_not_older_than' could not be parsed. "
                        "Check your configuration.")
                    raise
                self.not_older_than_type = 'relative'
        else:
            self.not_older_than_type = False

        self.set_request_parameters()
        self.session = create_request_session_from_bot(self)
Exemple #6
0
    def init(self):
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')

        self.set_request_parameters()
        self.extract_files = getattr(self.parameters, "extract_files", None)

        self.session = create_request_session_from_bot(self)
Exemple #7
0
    def init(self):
        super().init()
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')

        # Build request
        self.set_request_parameters()
        self.session = create_request_session_from_bot(self)

        self.chunk_size = getattr(self.parameters, 'chunk_size', None)
        self.chunk_replicate_header = getattr(self.parameters,
                                              'chunk_replicate_header', None)
    def init(self):
        super().init()
        if requests is None:
            raise MissingDependencyError("requests")

        # Build request
        self.set_request_parameters()
        self.session = create_request_session_from_bot(self)

        self.chunk_size = getattr(self.parameters, 'chunk_size', None)
        self.chunk_replicate_header = getattr(self.parameters,
                                              'chunk_replicate_header', None)
    def init(self):
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')

        self.set_request_parameters()

        self.http_header['Ocp-Apim-Subscription-Key'] = self.parameters.api_key
        if self.parameters.file_match:
            self.file_match = re.compile(self.parameters.file_match)
        else:
            self.file_match = None

        if self.parameters.not_older_than:
            try:
                self.time_match = timedelta(
                    minutes=parse_relative(self.parameters.not_older_than))
            except ValueError:
                if sys.version_info >= (3, 6):
                    self.time_match = parser.parse(
                        self.parameters.not_older_than).astimezone(pytz.utc)
                else:  # "astimezone() cannot be applied to a naive datetime" otherwise
                    if '+' not in self.parameters.not_older_than:
                        self.parameters.not_older_than += '+00:00'
                    self.time_match = parser.parse(
                        self.parameters.not_older_than)
                self.logger.info("Filtering files absolute %r.",
                                 self.time_match)
                self.check_ttl_time()
            else:
                self.logger.info("Filtering files relative %r.",
                                 self.time_match)
                if timedelta(seconds=self.parameters.redis_cache_ttl
                             ) < self.time_match:
                    raise ValueError(
                        "The cache's TTL must be higher than 'not_older_than', "
                        "otherwise the bot is processing the same data over and over again."
                    )
        else:
            self.time_match = None
        self.session = create_request_session_from_bot(self)

        self.cache = Cache(
            self.parameters.redis_cache_host, self.parameters.redis_cache_port,
            self.parameters.redis_cache_db, self.parameters.redis_cache_ttl,
            getattr(self.parameters, "redis_cache_password", None))
Exemple #10
0
    def init(self):
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')

        self.set_request_parameters()

        if self.parameters.auth_token_name and self.parameters.auth_token:
            if self.parameters.auth_type == 'http_header':
                self.http_header.update({
                    self.parameters.auth_token_name:
                    self.parameters.auth_token
                })
            elif self.parameters.auth_type == 'http_basic_auth':
                self.auth = self.parameters.auth_token_name, self.parameters.auth_token
        self.http_header.update(
            {"Content-Type": "application/json; charset=utf-8"})

        self.session = utils.create_request_session_from_bot(self)
        self.session.keep_alive = False
Exemple #11
0
    def init(self):
        if requests is None:
            raise MissingDependencyError("requests")

        self.set_request_parameters()

        if self.parameters.auth_token_name and self.parameters.auth_token:
            if self.parameters.auth_type == 'http_header':
                self.http_header.update({
                    self.parameters.auth_token_name:
                    self.parameters.auth_token
                })
            elif self.parameters.auth_type == 'http_basic_auth':
                self.auth = self.parameters.auth_token_name, self.parameters.auth_token
        self.http_header.update(
            {"Content-Type": "application/json; charset=utf-8"})

        self.session = utils.create_request_session_from_bot(self)
        self.session.keep_alive = False
Exemple #12
0
    def init(self):
        if requests is None:
            raise ValueError('Could not import requests. Please install it.')
        if rt is None:
            raise ValueError('Could not import rt. Please install it.')

        if getattr(self.parameters, 'search_not_older_than', None):
            try:
                self.not_older_than = parser.parse(
                    self.parameters.search_not_older_than)
                self.not_older_than_type = 'absolute'
            except ValueError:
                try:
                    self.not_older_than_relative = timedelta(
                        minutes=parse_relative(
                            self.parameters.search_not_older_than))
                except ValueError:
                    self.logger.error(
                        "Parameter 'search_not_older_than' could not be parsed. "
                        "Check your configuration.")
                    raise
                self.not_older_than_type = 'relative'
        else:
            self.not_older_than_type = False

        self.set_request_parameters()
        self.session = create_request_session_from_bot(self)
        self._parse_extract_file_parameter('extract_attachment')
        self._parse_extract_file_parameter('extract_download')

        if hasattr(self.parameters, 'unzip_attachment'):
            self.logger.warning(
                "The parameter 'unzip_attachment' is deprecated and "
                "will be removed in version 3.0 in favor of the "
                "more generic and powerful 'extract_attachment'. "
                "Look at the Bots documentation for more details.")
            if not self.extract_attachment:
                self.extract_attachment = self.parameters.unzip_attachment
            else:
                self.logger.warn(
                    "Both 'extract_attachment' and the deprecated "
                    "'unzip_attachment' parameter are in use. Ignoring "
                    "the latter one.")
Exemple #13
0
    def init(self):
        if requests is None:
            raise ValueError(
                "Library 'requests' could not be loaded. Please install it.")

        self.set_request_parameters()

        self.url = self.parameters.portal_url + '/api/1.0/ripe/contact?cidr=%s'
        self.http_header.update({
            "Content-Type":
            "application/json",
            "Accept":
            "application/json",
            "API-Authorization":
            self.parameters.portal_api_key
        })
        self.mode = self.parameters.mode

        self.session = utils.create_request_session_from_bot(self)
        retries = requests.urllib3.Retry.from_int(self.http_timeout_max_tries)
        retries.status_forcelist = [502]
        adapter = requests.adapters.HTTPAdapter(max_retries=retries)
        self.session.mount('http://', adapter)
        self.session.mount('https://', adapter)
Exemple #14
0
 def __initialize_http_session(self):
     self.set_request_parameters()
     self.http_session = utils.create_request_session_from_bot(self)