base.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:skills-ml 作者: workforce-data-initiative 项目源码 文件源码
def _load_lookup(self):
        """The method to download the lookup dictionary from S3 and load to the memory.

        Returns:
            dict: a lookup table for mapping gensim index to soc code.
        """
        try:
            filepath = os.path.join(LOCAL_CACHE_DIRECTORY, self.lookup_name)
            with open(filepath, 'r') as handle:
                lookup = json.load(handle)
            return lookup
        except:

            if not self.saved:
                with tempfile.TemporaryDirectory() as td:
                    filepath = os.path.join(td, self.lookup_name)
                    print(filepath)
                    logging.warning('calling download from %s to %s', self.s3_path + self.lookup_name, filepath)
                    download(self.s3_conn, filepath, os.path.join(self.s3_path, self.lookup_name))
                    with open(filepath, 'r') as handle:
                        lookup = json.load(handle)

            else:
                filepath = os.path.join(LOCAL_CACHE_DIRECTORY, self.lookup_name)
                if not os.path.exists(filepath):
                    logging.warning('calling download from %s to %s', self.s3_path + self.lookup_name, filepath)
                    download(self.s3_conn, filepath , os.join(self.s3_path, self.lookup_name))
                with open(filepath, 'r') as handle:
                    lookup = json.load(handle)

            return lookup
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号