Example #1
0
    def get_entity_rank(self, entity_type=None, rank_size=20, date_year=2020):
        """
        Get the Entity Rank from RedisDB.
        Args:
            entity_type: (str) "Superior" or "Subordinado"
            date_year: (str) Year for the Rank selected.
        """
        if not entity_type:
            logging.warning(
                "Superior ou Subordinado not select! Return empty list.")
            return []

        self.redis_connector = redis_connector.RedisConnector()
        self.redis_connector.connect()

        if entity_type == "Subordinado":
            redis_key = "spenders_rank_" + str(date_year)
        elif entity_type == "Superior":
            redis_key = "superiors_spenders_rank_" + date_year
        else:
            return []

        logging.debug(redis_key)

        return json.loads(self.redis_connector.get(redis_key))
Example #2
0
 def __remove_reports_downloads(self):
     """
     Remove from Redis information about downloaded reports.
     """
     rc = redis_connector.RedisConnector()
     rc.connect()
     rc.set("downloaded_reports", json.dumps({"downloaded_reports": []}))
Example #3
0
    def get_companies_list_from_redis(self):
        """
        Get all Companies list from Redis DB, instead of Mongo DB.
        """
        key_name = "all_companies_list"
        self.redis_connector = redis_connector.RedisConnector()
        self.redis_connector.connect()

        companies_list = self.redis_connector.get(key_name)
        return json.loads(companies_list)
Example #4
0
    def get_all_entities_from_redis(self, entity_type=None, date=None):
        """
        Get all Entities list from Redis DB, instead of Mongo DB.
        Args:
            entity_type: (str) "Superior" or "Subordinado"
        """
        if not entity_type:
            logging.warning("Entity type is None. Returning empty list...")
            return []

        key_name = "all_" + entity_type + "_list_alltime"
        self.redis_connector = redis_connector.RedisConnector()
        self.redis_connector.connect()

        entities_list = self.redis_connector.get(key_name)
        return json.loads(entities_list)
Example #5
0
    def __register_report_downloaded(self, report_url, report_url_arg):
        """
        Based on the Downloaded Report, save at the RedisDB the information about the Report.
        The format saved on Redis is:
            {
                "downloaded_reports": [
                    {
                        "url": "url_to_report",
                        "info": "some info about the report"
                    },
                ]
            }
        Args:
            report_url: (str) Report URL
            report_url_arg: (str) Report URL arg
        """
        logging.debug("Registering downloaded report...")
        report_url = report_url + report_url_arg

        rc = redis_connector.RedisConnector()
        rc.connect()

        downloaded_report_info = {}
        already_in_redis = rc.get("downloaded_reports")

        if already_in_redis:
            downloaded_report_info = json.loads(already_in_redis)
        else:
            downloaded_report_info["downloaded_reports"] = []

        downloaded_report_info["downloaded_reports"].append(
            {
                "url": report_url,
                "info": ""
            }
        )

        return rc.set("downloaded_reports", json.dumps(downloaded_report_info))
Example #6
0
 def __connect_redis(self, db=1):
     logging.debug("Connecting Redis DB")
     self.redis_connector = redis_connector.RedisConnector()
     self.redis_connector.connect(db=db)
     logging.debug("DONE")
Example #7
0
    def __connect_redis_db(self):
        if self.redis_connection:
            return

        self.redis_connection = redis_connector.RedisConnector()
        self.redis_connection.connect()
Example #8
0
 def get_downloaded_reports(self):
     rc = redis_connector.RedisConnector()
     rc.connect()
     return (json.loads(rc.get("downloaded_reports")))
Example #9
0
 def __init__(self):
     self.redis_connection = redis_connector.RedisConnector()
     self.redis_connection.connect(db=2)