コード例 #1
0
ファイル: knock27.py プロジェクト: greatestgoat/100knock2019
def main():
    with gzip.open('jawiki-country.json.gz', 'rt', encoding='utf-8') as fs:

        data = jsons2dict(fs, 'イギリス')
        t = exttemplate(data['text'])

    return t
コード例 #2
0
def main():
    with gzip.open('jawiki-country.json.gz', 'rt', encoding='utf-8') as fs:

        data = jsons2dict(fs, 'イギリス')
        template = exttemplate(data['text'])
        url = geturl_flagimg(template)
        print(url)
    return None
コード例 #3
0
    def test20_jsons2dict(self):
        print('test_jsons2dict')
        in_file = 'test1.json'

        refdict = {"text": "#転送 [[アイルランド共和国]]", "title": "アイルランド"}

        with open(in_file) as fin:
            mydict = jsons2dict(fin, 'アイルランド')

        self.assertEqual(mydict, refdict)
コード例 #4
0
    def test23_extcatnames(self):
        print('test23_extsections')
        in_file = 'test2.json'

        reflist = [[1, '概要'], [2, 'テスト']]

        with open(in_file) as fin:
            mydict = jsons2dict(fin, '南オセチア')
            sectionlist = extsections(mydict['text'])
            print(sectionlist)
            self.assertEqual(reflist, sectionlist)
コード例 #5
0
    def test22_extcatnames(self):
        print('test22_extcatnames')
        in_file = 'test1.json'

        with open(in_file) as fin:
            mydict = jsons2dict(fin, '南オセチア')
            refcatnames = []
            refcatnames.append('南オセチア')
            refcatnames.append('グルジアの地理')
            refcatnames.append('カフカス')
            refcatnames.append('オセット')

            mycatnames = extcatnames(mydict['text'])
            self.assertEqual(refcatnames, mycatnames)
コード例 #6
0
    def test26_exttemplate(self):
        in_file = 'test3.json'

        refdict = defaultdict(lambda: 0)
        refdict['略名'] = 'チュニジア'
        refdict['日本語国名'] = 'チュニジア共和国'
        refdict['公式国名'] = "{{lang|ar|الجمهورية التونسية}}"
        refdict[
            'GDP値元'] = "496億<ref name=\"economy\">IMF Data and Statistics 2009年4月27日閲覧</ref>"
        refdict['注記'] = ''

        with open(in_file) as fin:
            mydict = jsons2dict(fin, 'チュニジア')
            tempdict = exttemplate(mydict['text'])
        self.assertEqual(refdict, tempdict)
コード例 #7
0
    def test21_extcategories(self):
        print('test21_extcategories')
        in_file = 'test1.json'

        with open(in_file) as fin:
            mydict = jsons2dict(fin, '南オセチア')
            refcategories = []
            refcategories.append('[[Category:南オセチア|*]]')
            refcategories.append('[[Category:グルジアの地理]]')
            refcategories.append('[[Category:カフカス]]')
            refcategories.append('[[Category:オセット]]')

            mycategories = extcategories(mydict['text'])

            self.assertEqual(refcategories, mycategories)
コード例 #8
0
ファイル: knock21.py プロジェクト: greatestgoat/100knock2019
def main():
    with gzip.open('jawiki-country.json.gz', 'rt',
                   encoding='utf-8') as infiles:
        data = jsons2dict(infiles, 'イギリス')
        categories = extcategories(data['text'])
    return