def set_last_update(self):
     self.last_update = proj_utils.get_date()
    def update_local_sic_dict_by_sic(self, sic):

        sic = str(sic)

        local_dict_copy = self.get_local_sics_dict()

        # Get companies by tickers from SEC
        sic_tickers = self.scrape_tickers_by_sic(sic)

        # Get (download) all the data of the companies via IB
        self.scrape_ticker_ib_data(sic_tickers)

        # Make sure all requests had responses
        self.tws_api.wait_for_api_task(
            "Waiting for responses from IB for SIC: {}".format(sic))

        if (sic not in local_dict_copy):
            # make a new industry Obj
            industry = Industry_c(industry_name=None, SIC=sic)

        else:
            industry = local_dict_copy[sic]

        last_update = industry.get_last_update()
        new_date = proj_utils.get_date()

        # in case the industry is up to date do nothing
        if not proj_utils.should_update_object(last_update, new_date, 3):
            return

        # update local sic dict
        for ticker in sic_tickers:
            fundumentals_obj = None
            snapshot_obj = None
            # first update ticker data for XML readers
            try:
                self.finStatementXmlReader.set_ticker(ticker)
            except:
                pass
            try:
                self.snapshotXmlReader.set_ticker(ticker)
            except:
                pass

            # get different data objects from xml to build the main sics dic
            try:
                fundumentals_obj = self.finStatementXmlReader.get_fundamentals_obj(
                )
            except:
                pass
            try:
                snapshot_obj = self.snapshotXmlReader.get_snapshot_obj()
            except:
                pass

            ticker_data = {
                cfg.FUNDAMENTALS: fundumentals_obj,
                cfg.SNAPSHOT: snapshot_obj
            }
            # update the local dict copy
            if (fundumentals_obj != None and snapshot_obj != None):
                industry.add_ticker_data(
                    ticker=ticker, ticker_data=ticker_data, source=cfg.IB
                )  # TODO - fix the "source" issue to include other sources
        industry.set_last_update()

        # analyze industry after all tickers are add
        # industry.analyze_industry_after_tickers_are_added()
        industry.calc_after_tickers_added()
        local_dict_copy[sic] = industry
        self.save_sic_dictionary(local_dict_copy)
 def set_last_updated(self, date=None):
     if (date is None):
         return proj_utils.get_date()
     else:
         return date