コード例 #1
0
def dump_label_data():

    modules = ["", "regional", "topical", "subvarieties"]
    variables = ["labels", "aliases"]

    print("data = {}")
    for module in modules:

        target = "Module:labels/data"
        suffix = ""
        if module:
            target += "/" + module

        res = get_wikipage(target)

        for varname in variables:
            print(
                f"# Data from: {res['url']} (revision: {res['revision']}, scraped {datetime.datetime.now()})"
            )
            print(f'data["{module}_{varname}"] = {{}}')
            pydata = luadata_to_python.convert(res["wikitext"],
                                               varname,
                                               f'data["{module}_{varname}"]',
                                               trim_newlines=True)
            print(pydata)

    for varname in variables:
        targets = [f'**data["{module}_{varname}"]' for module in modules]
        print(f'data["{varname}"] = {{', ", ".join(targets) + "}")
コード例 #2
0
def dump_label_data():

    print("data = {}")
    target = "Module:etymology_languages/data"
    res = get_wikipage(target)

    print(f"# Data from: {res['url']} (revision: {res['revision']}, scraped {datetime.datetime.now()})")
    pydata = luadata_to_python.convert(res["wikitext"], "m", f'data', trim_newlines=True)
    print(pydata)
コード例 #3
0
ファイル: test_lua.py プロジェクト: doozan/luadata_to_python
def test_multi():
    luadata = """\
labels['_'] = {
	display = '',
	omit_preComma = true,
	omit_postComma = true,
}

labels['also'] = {
	omit_postComma = true,
}

labels['and'] = {
	omit_preComma = true,
	omit_postComma = true,
}
aliases['&'] = 'and'
"""
    label_data = """\
label = {
'_': {
    "display" : '',
    "omit_preComma" : True,
    "omit_postComma" : True,
},
'also': {
    "omit_postComma" : True,
},
'and': {
    "omit_preComma" : True,
    "omit_postComma" : True,
},
}"""

    alias_data = """\
alias = {
'&': 'and',
}"""

    assert luadata_to_python.convert(luadata, "labels", "label", trim_newlines=True, no_warning=True) == label_data
    assert luadata_to_python.convert(luadata, "aliases", "alias", trim_newlines=True, no_warning=True) == alias_data
コード例 #4
0
ファイル: test_lua.py プロジェクト: doozan/luadata_to_python
def test_skipunquoted():
    luadata="""\
data['test'] = {}
data[test2] = {}
"""

    pydata = """\
data = {
'test': {},
}"""

    assert luadata_to_python.convert(luadata, "data", "data", trim_newlines=True, no_warning=True, numeric_keys=True) == pydata
コード例 #5
0
ファイル: test_lua.py プロジェクト: doozan/luadata_to_python
def test_comments():
    luadata="""\
data['_'] = {
    display = '', -- comment
    omit_preComma = true,
    omit_postComma = true,
} -- comment"""

    pydata = """\
data = {
'_': {
    "display" : '', # comment
    "omit_preComma" : True,
    "omit_postComma" : True,
}, # comment
}"""

    assert luadata_to_python.convert(luadata, "data", "data", trim_newlines=True, no_warning=True) == pydata
コード例 #6
0
ファイル: test_lua.py プロジェクト: doozan/luadata_to_python
def test_numeric():
    luadata="""\
data['_'] = {
    1 = '', -- comment
    omit_preComma = true,
    omit_postComma = true,
} -- comment"""

    pydata = """\
data = {
'_': {
    1 : '', # comment
    "omit_preComma" : True,
    "omit_postComma" : True,
}, # comment
}"""

    assert luadata_to_python.convert(luadata, "data", "data", trim_newlines=True, no_warning=True, numeric_keys=True) == pydata
コード例 #7
0
ファイル: test_lua.py プロジェクト: doozan/luadata_to_python
def test_luabrackets():
    luadata="""\
data["-ír"] = {
    ["embaír"] = "embaír",
    ["oír"] = "oír",
    ["reír"] = "-eír",
    ["-eír"] = "-eír",
    ["freír"] = "-eír",
    ["refreír"] = "-eír",
} """

    pydata = """\
data = {
"-ír": {
      "embaír": "embaír",
      "oír": "oír",
      "reír": "-eír",
      "-eír": "-eír",
      "freír": "-eír",
      "refreír": "-eír",
},
}"""
    assert luadata_to_python.convert(luadata, "data", "data", trim_newlines=True, no_warning=True, numeric_keys=True) == pydata