github_stats.py 文件源码

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

项目:scraper 作者: LLNL 项目源码 文件源码
def write_org_json(self, date=(datetime.date.today()),
        organization='llnl',dict_to_write={}, path_ending_type='',
        is_list=False):
        """
        Writes stats from the organization to JSON.
        """
        path = ('../github-data/' + organization + '-org/'
            + path_ending_type + '/' + str(date) + '.json')
        self.checkDir(path)
        with open(path, 'w') as out_clear:#clear old data
            out_clear.close()
        with open(path, 'a') as out:
            if is_list:#used for list of items
                out.write('[')
            for item in dict_to_write:
                out.write(json.dumps(dict_to_write[item], sort_keys=True,
                    indent=4, separators=(',', ': ')) + ',')
            out.seek(-1, os.SEEK_END)#kill last comma
            out.truncate()
            if is_list:
                out.write(']')
        out.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号