机娘霜天酱是贯井羽优的草莓胖次[更多]讨论页贡献上传历史封禁及历史被删贡献移动日志巡查日志用户权限及日志用户查核操作的机器人,主要用于闪耀幻想曲专题维护。
Python N | 这个用户的母语是Python。 |
闪耀幻想曲专题维护——在《闪耀幻想曲》追加新卡后进行相关编辑:
展开查看 |
---|
import pandas as pd import pywikibot as pwb import os import math import sys import time import re def wait_exit(errinfo): print(errinfo) print("程序将在30秒后自动关闭") time.sleep(30) sys.exit() def inputnotice(): print("\n指令说明:") print("添加卡片-输入7位卡片代码,如:1000200") print("添加全部-输入all") print("清空列表-输入clean") print("删除卡片-输入x+7位卡片代码,如:x1000200") print("结束输入-输入end") print("*添加全部是指将krfcard.csv中的全部卡片添加至列表") a=input("请输入指令:") return a #导入角色数据和卡片数据 print("正在从krfchara.csv导入角色数据……") df_ch=pd.read_csv("C:/Users/万类霜天/Desktop/kirafan/krfedit/krfchara.csv",index_col="no") print("角色数据导入完毕") for i in df_ch.index: if "{{!}}" in df_ch.loc[i,"main"]: df_ch.loc[i,"main"]=re.sub("{{!}}.+","",df_ch.loc[i,"main"]) print("正在从krfcard.csv导入卡片数据……") df_cd=pd.read_csv("C:/Users/万类霜天/Desktop/kirafan/krfedit/krfcard.csv",index_col="no") print("卡片数据导入完毕") df_cd=df_cd.fillna("") #输入活动信息 info=input(r"请输入活动信息(如:2020年{{0}}7月29日的活动《暑假!作业大作战》):") id=[] a=inputnotice() #添加要操作的卡片列表 while(1==1): os.system('cls') if(a=="end"): print("添加完毕!") break elif(a=="all"): for idn in df_cd.index: num=int(idn) chnum=math.floor(num/1000) if not(idn in id): id.append(idn) print(f'添加成功:{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}') else: print(f'已在列表:{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}') elif(a=="clean"): id=[] print("清空列表") elif(re.match("\d{7}",a)): if(a in id): print(f'已在列表:{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}') else: num=int(a) chnum=math.floor(num/1000) if not (chnum in df_ch.index): print("未查询到相应角色,添加失败") else: if not (num in df_cd.index): print("未找到卡片数据,添加失败") else: id.append(int(a)) print(f'添加成功:{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}') elif(re.match("x\d{7}",a)): a=a.replace("x","") if(a in id): id.remove(a) num=int(a) chnum=math.floor(num/1000) print(f'删除成功:{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}') else: print("未找到该卡,删除失败") else: print("无效指令") print("\n列表中卡片:") for idn in id: num=int(idn) chnum=math.floor(num/1000) print(f'{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}') a=inputnotice() #定义状态列表 ids={} for idm in id: ids[idm]="" #编辑角色主条目 for idn in id: check="" os.system('cls') ids[idn]="(主条目编辑中)" print("列表中卡片:") for idm in id: num=int(idm) chnum=math.floor(num/1000) print(f'{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}{ids[idm]}') print("") num=int(idn) chnum=math.floor(num/1000) rare=math.floor(((num+1)/1000-math.floor(num/1000))*10)+3 cardname=f'{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}' page = pwb.Page(pwb.Site(), df_ch.loc[chnum,"main"]) origintext=page.text if not page.text: print("角色主条目未创建,跳过编辑") ids[idn]="(角色主条目未创建)" continue if("{{kiraraf卡表" not in page.text): print("未找到卡表,请手动添加卡片") check += "未找到卡表;" elif(f'|{cardname}|' in page.text): print("卡片已存在") elif(f'|{rare}{rare{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}=',f'|{rare}icon|{cardname}|evo=true}}}}<br>') else: print("卡片添加成功") page.text = page.text.replace(r"{{kiraraf卡表",f'{{{{kiraraf卡表\n|{rare{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}= {{{{kf-table|icon|{cardname}|evo=true}}}}') if not info: print("跳过更新剧情") elif(info in page.text): print("剧情信息已存在") elif("*作为主要角色:" in page.text): print("剧情信息添加成功") note=re.search("日的活动《(.+》)\n\*?[^\*]",page.text) page.text=re.sub(note.group(1),note.group(1)+"\n**"+info,page.text,count=1) elif("'''活动剧情'''(具体的活动剧情请在游戏中查看,或者观看[[闪耀幻想曲/年表#活动列表|活动列表]]处的B站汉化剧情)" in page.text): print("剧情信息添加成功") page.text=re.sub("的B站汉化剧情)","的B站汉化剧情)\n\n*作为主要角色:\n**"+info,page.text,count=1) elif("=== 卡片索引 ===" in page.text): print("剧情信息添加成功") page.text=re.sub("=== 卡片索引 ===","'''活动剧情'''(具体的活动剧情请在游戏中查看,或者观看[[闪耀幻想曲/年表#活动列表|活动列表]]处的B站汉化剧情)\n\n*作为主要角色:\n**"+info+"\n\n=== 卡片索引 ===",page.text,count=1) else: print("剧情信息添加失败") check += "剧情信息添加失败" if not origintext==page.text: page.save(summary="krf角色主条目维护:"+check+" //Edit via Pywikibot",tags="Automation tool") ids[idn]="(已完成)" if(check!=""): ids[idn]="(未找到卡表)" os.system('cls') print("列表中卡片:") for idm in id: num=int(idm) chnum=math.floor(num/1000) print(f'{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}{ids[idm]}') #编辑Template:Kiraraf角色卡片列表 check="" print("\n开始编辑Template:Kiraraf角色卡片列表") page = pwb.Page(pwb.Site(), "Template:Kiraraf角色卡片列表") origintext=page.text for idn in id: num=int(idn) chnum=math.floor(num/1000) rare=math.floor(((num+1)/1000-math.floor(num/1000))*10)+3 order=num%10 cardinfo=f'{df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}{df_cd.loc[num,"sup"]}' cardname=f'{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}' if ("|%s={{array|id=%s"%(df_ch.loc[chnum,"chara"],df_ch.loc[chnum,"chara"])) not in page.text: print("添加失败:"+cardname) check += df_ch.loc[chnum,"chara"]+"添加失败;" continue if(rare==5): note=re.compile("(\|%s={{array\|id=%s(\n\|5,[^}\n]+){%s})"%(df_ch.loc[chnum,"chara"],df_ch.loc[chnum,"chara"],order)) else: note=re.compile("(\|%s={{array\|id=%s(\n\|5,[^}\n]+)*(\n\|4,.+){%s})"%(df_ch.loc[chnum,"chara"],df_ch.loc[chnum,"chara"],order)) result=note.findall(page.text) pattern=re.sub("\|","\|",result[0][0]) newtext=result[0][0]+"\n|"+str(rare)+","+cardinfo if newtext in page.text: print("已在列表:"+cardname) else: page.text=re.sub(pattern,newtext,page.text,count=1) print("添加成功:"+cardname) if not origintext==page.text: page.save(summary="添加新卡:"+check+" //Edit via Pywikibot",tags="Automation tool") #编辑Template:筛选功能/闪耀幻想曲卡片 print("\n开始编辑Template:筛选功能/闪耀幻想曲卡片") page = pwb.Page(pwb.Site(), "Template:筛选功能/闪耀幻想曲卡片") origintext=page.text for idn in id: num=int(idn) chnum=math.floor(num/1000) rare=math.floor(((num+1)/1000-math.floor(num/1000))*10)+3 cardname=f'{df_ch.loc[chnum,"chara"]}({df_cd.loc[num,"pre"]}{df_cd.loc[num,"ele"]}之{df_cd.loc[num,"job"]}){df_cd.loc[num,"sup"]}' mark="" if df_ch.loc[chnum,"chara"] in page.text: note=re.compile("\| {{#invoke:kiraraf筛选\|main\|\d\|%s\|.+}}"%df_ch.loc[chnum,"chara"]) mark="\n|-" elif df_ch.loc[chnum,"title"] in page.text: for i in range(1,chnum%10+1,1): if df_ch.loc[chnum-i,"chara"] in page.text: note=re.compile("\| {{#invoke:kiraraf筛选\|main\|\d\|%s\|.+}}"%df_ch.loc[chnum-i,"chara"]) mark="\n|-" break note=re.compile("<!--%s-->"%df_ch.loc[chnum,"title"]) else: page.text=re.sub("\|}","\n|-<!--%s-->\n|}"%df_ch.loc[chnum,"title"],page.text) note=re.compile("<!--%s-->"%df_ch.loc[chnum,"title"]) result=note.findall(page.text) pattern=re.sub("\|","\|",result[-1]) newtext="\n| {{#invoke:kiraraf筛选|main|"+str(rare)+"|"+df_ch.loc[chnum,"chara"]+"|"+df_cd.loc[num,"ele"]+"|"+df_cd.loc[num,"job"] if df_cd.loc[num,"pre"]: newtext += "|pre="+df_cd.loc[num,"pre"] if df_cd.loc[num,"sup"]: newtext += "|suf="+df_cd.loc[num,"sup"] if df_cd.loc[num,"type"]=="活动兑换卡" or (df_cd.loc[num,"type"]=="期间限定卡" and not df_cd.loc[num,"pre"]): newtext += "|type="+df_cd.loc[num,"type"] newtext += "}}" if newtext in page.text: print("已在列表:"+cardname) else: page.text=re.sub(pattern,result[-1]+mark+newtext,page.text,count=1) print("添加成功:"+cardname) if not origintext==page.text: page.save(summary="添加新卡 //Edit via Pywikibot",tags="Automation tool") #检查[[模块:Kiraraf角色信息]]并补漏 print("\n开始检查[[模块:Kiraraf角色信息]]并补漏") page = pwb.Page(pwb.Site(), "模块:Kiraraf角色信息") origintext=page.text newchara="" for idn in id: chnum=math.floor(idn/1000) if df_ch.loc[chnum,"chara"] in page.text: print("已在列表:"+df_ch.loc[chnum,"chara"]) else: titleset='titleset["%s"]={"%s","%s","%s"}'%(df_ch.loc[chnum,"chara"],df_ch.loc[chnum,"main"],df_ch.loc[chnum,"title"],df_ch.loc[chnum,"cv"]) if df_ch.loc[chnum,"title"] in page.text: note=re.compile('titleset\[".+"\]={".+","%s",".+"}'%df_ch.loc[chnum,"title"]) result=note.findall(page.text) pattern=re.sub("\[","\[",result[-1]) pattern=re.sub("\]","\]",pattern) page.text=re.sub(pattern,result[-1]+"\n"+titleset,page.text,count=1) else: page.text=re.sub("--如广播需用未实卡化的角色,请置于本注释下方",titleset+"\n--如广播需用未实卡化的角色,请置于本注释下方",page.text,count=1) print("添加成功:"+df_ch.loc[chnum,"chara"]) if newchara: newchara += "、"+df_ch.loc[chnum,"chara"] else: newchara += ":"+df_ch.loc[chnum,"chara"] if not origintext==page.text: page.save(summary="新角色参战"+newchara+" //Edit via Pywikibot",tags="Automation tool") #检查[[模块:Kiraraf角色简介/Title]]并发送补漏提醒 print("\n检查[[模块:Kiraraf角色简介/Title]]并发送补漏提醒") page = pwb.Page(pwb.Site(), "模块:Kiraraf角色简介/Title") page2 = pwb.Page(pwb.Site(), "Template_talk:Kiraraf角色简介") newchara="" for idn in id: chnum=math.floor(idn/1000) if '["%s"]'%df_ch.loc[chnum,"chara"] in page.text: print("已在列表:"+df_ch.loc[chnum,"chara"]) elif df_ch.loc[chnum,"chara"] in page2.text: print("已经提醒:"+df_ch.loc[chnum,"chara"]) else: print("新增参战:"+df_ch.loc[chnum,"chara"]) if newchara: newchara += "、"+df_ch.loc[chnum,"chara"] else: newchara += ":"+df_ch.loc[chnum,"chara"] if newchara: page.text += "\n\n== 提醒:新角色参战 ==\n新角色参战"+newchara+"\n\n请及时补充角色简介哦~ ——~~~~" page2.save(summary="新参战提醒 //Edit via Pywikibot",tags="Automation tool") print("\n本次维护已完成") |