コード例 #1
0
 def test_something(self):
     print(test_data)
     j = class_to_json(test_data)
     print(j)
     d = json_to_class(j, TestDataB)
     print(d)
     j2 = class_to_json(d)
     self.assertEqual(j, j2)
コード例 #2
0
 def test_something(self):
     info = character.RCharacter('测试')
     info.outlook.body.age_range = character.AgeRange(min=12, max=30)
     json1 = class_to_json(info)
     info2 = json_to_class(json1, character.RCharacter)
     self.assertEqual(info, info2)
     print(info)
コード例 #3
0
ファイル: cv_list.py プロジェクト: acgbase/crawler
def crawl(category):
    target_fp = indices_root / f'{category}.txt'
    site = wikipedia_ja()
    with open(target_fp, 'w') as f:
        for p in site.categories[category]:
            title = p.name
            if title.startswith("Category:"):
                continue
            print(category, title)
            item = PageIndex(title=title, source=site.host)
            json.dump(class_to_json(item), f)
            f.write("\n")
コード例 #4
0
def crawl(ftype):
    index_fp = indices_root / f'{ftype}_index.txt'
    target_fp = indices_root / f'{ftype}.txt'
    site = moegirl()
    categories = open(index_fp).read().split()
    with open(target_fp, 'w') as f:
        for cate in categories:
            for p in site.categories[cate]:
                title = p.name
                if title.startswith("Category:"):
                    continue
                print(ftype, cate, title)
                item = PageIndexWithTag(title=title,
                                        tag=cate,
                                        source=site.host)
                json.dump(class_to_json(item), f)
                f.write("\n")
コード例 #5
0
def save_character(page_name, data: RCharacter):
    fp = results_root / f"{page_name}.json"
    data = class_to_json(data)
    with open(fp, 'w') as f:
        json.dump(data, f)
コード例 #6
0
 def write(self, data: T):
     json.dump(class_to_json(data), self.io, ensure_ascii=False)
     self.io.write('\n')