当前位置: 首页>>代码示例>>Python>>正文


Python PageEditor.get_body方法代码示例

本文整理汇总了Python中MoinMoin.PageEditor.PageEditor.get_body方法的典型用法代码示例。如果您正苦于以下问题:Python PageEditor.get_body方法的具体用法?Python PageEditor.get_body怎么用?Python PageEditor.get_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoinMoin.PageEditor.PageEditor的用法示例。


在下文中一共展示了PageEditor.get_body方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: processWeapon

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_body [as 别名]
def processWeapon(j, context, is_sub, dry_run):
    status_map = j.get(u'subStatusMap' if is_sub else  u'statusMap', {}) or {}
    weapon_name = j.get(u'subWeaponName' if is_sub else u'weaponName', u'').strip()
    level = j.get(u'subWeaponLevel' if is_sub else u'weaponLevel', 0)
    if not status_map or not weapon_name or not level:
        print u'Weapon %s is missing critical params.' % weapon_name
        return

    page = PageEditor(context, weapon_name)
    body_pre = u''
    body_json = {}
    body_post = u''
    if page.isStandardPage():
        match = RE_WEAPON_PAGE.match(page.get_body())
        if match:
            body_pre = match.group(u'pre')
            body_post = match.group(u'post')
            try:
                body_json = json.loads(match.group(u'body'))
            except Error:
                pass

    diff_dst_json = statusMapToAttrs(status_map)
    if not is_sub and j.get(u'subStatusMap', {}):
        diff_dst_json[u'サブウェポン'] = {
            u'名称': j[u'subWeaponName'].strip(),
            u'レベル': int(j[u'subWeaponLevel']),
        }

    if not body_json:
        body_pre = WEAPON_PAGE_DEFAULT_BODY_PRE
        body_post = WEAPON_PAGE_DEFAULT_BODY_POST
        body_json = {
            u'名称': weapon_name,
            u'レベル': {},
            u'弾種': j.get(u'subBulletTypeName' if is_sub else u'bulletTypeName', u''),
        }

    levels_json = body_json.get(u'レベル', {})
    if not levels_json:
        levels_json = {}
        body_json[u'レベル'] = levels_json

    dst_json = levels_json.get(u'%d' % level, {})
    if not dst_json:
        dst_json = {}
        levels_json[u'%d' % level] = dst_json

    dst_json.update(diff_dst_json)
    # clenup legacy attrs
    if u'爆発半径' in dst_json:
        del dst_json[u'爆発半径']
    if u'発射準備時間' in dst_json:
        del dst_json[u'発射準備時間']

    output = (body_pre + u'\n'
              + json_printer.print_json(body_json, indent=2) + u'\n'
              + body_post)

    try:
        if not dry_run:
            page.saveText(output, page.current_rev())
            print u'Processed weapon %s correctly.' % weapon_name
        else:
            differ = difflib.Differ(charjunk=lambda c:c.isspace())
            l = map(lambda s: s.strip(), page.get_body().splitlines())
            r = map(lambda s: s.strip(), output.splitlines())   
            if l != r:
                d = u'\n'.join(filter(lambda s: s and s[0] in u'+-?', differ.compare(l, r)))
                print((u'#### Diff in %s ####' % weapon_name).encode('utf-8'))
                print(d.encode('utf-8'))
    except PageEditor.Unchanged:
        pass

    if not is_sub and j.get(u'subStatusMap', {}):
        processWeapon(j, context, True, dry_run)
开发者ID:wada314,项目名称:gswiki,代码行数:78,代码来源:import_website_jsons.py

示例2: processWeaponPack

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_body [as 别名]
def processWeaponPack(j, context, dry_run):
    wp_name = j.get(u'weaponPackName', None)
    if not wp_name:
        return
    page = PageEditor(context, wp_name)
    body_pre = u''
    body_json = {}
    body_post = u''
    if page.isStandardPage():
        match = RE_WP_PAGE.match(page.get_body())
        if match:
            body_pre = match.group(u'pre')
            body_post = match.group(u'post')
            try:
                body_json = json.loads(match.group(u'body'))
            except Error:
                pass

    def getBriefWeaponJson(weapon):
        return {
            u'名称': weapon.get(u'weaponName').strip(),
            u'レベル': weapon.get(u'weaponLevel'),
        }

    w_map = j.get(u'weaponMap', {})
    json_diff = {
        u'コスト': j.get(u'cost', 0),
        u'耐久力': j.get(u'hitPoint', 0),
        u'格闘補正': j.get(u'grappleUp', 1.0),
        u'右手武器': getBriefWeaponJson(w_map.get(u'right', {})),
        u'左手武器': getBriefWeaponJson(w_map.get(u'left', {})),
        u'サイド武器': getBriefWeaponJson(w_map.get(u'side', {})),
        u'タンデム武器': getBriefWeaponJson(w_map.get(u'tandem', {})),
    }

    if not body_json:
        body_pre = WP_PAGE_DEFAULT_BODY_PRE
        body_json = {
            u'名称': wp_name,
            u'入手条件': u'',
            u'タイプ': u''
        }
        body_post = WP_PAGE_DEFAULT_BODY_POST

    body_json.update(json_diff)

    output = (body_pre + u'\n'
              + json_printer.print_json(body_json, indent=2) + u'\n'
              + body_post)

    try:
        if not dry_run:
            page.saveText(output, page.current_rev())
            print u'Processed %s correctly.' % wp_name
        else:
            differ = difflib.Differ()
            l = map(lambda s: s.strip(), page.get_body().splitlines())
            r = map(lambda s: s.strip(), output.splitlines())
            if l != r:
                d = u'\n'.join(filter(lambda s: s and s[0] in u'+-?', differ.compare(l, r)))
                print((u'#### Diff in %s ####' % wp_name).encode('utf-8'))
                print(d.encode('utf-8'))
    except PageEditor.Unchanged:
        pass
开发者ID:wada314,项目名称:gswiki,代码行数:66,代码来源:import_website_jsons.py


注:本文中的MoinMoin.PageEditor.PageEditor.get_body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。