Skip to content

Instantly share code, notes, and snippets.

@inajob
Last active May 21, 2022 14:05
Show Gist options
  • Save inajob/21cd18960c4a07d6d9d59c65404b521e to your computer and use it in GitHub Desktop.
Save inajob/21cd18960c4a07d6d9d59c65404b521e to your computer and use it in GitHub Desktop.
# https://github.com/takker99/scrapbox-backups の /villagepump で実行する前提です
import json
import sys
import os
import re
iconPattern = r"\[[^\[\]]*\.icon\]"
if len(sys.argv) != 2:
print("usage: " + sys.argv[0] + " userid")
sys.exit()
target=sys.argv[1]
iconsCount = {}
for fname in os.listdir('pages'):
fname = "pages/" + fname
if not(os.path.exists(fname)):
print(fname + " not found")
notFoundCount = notFoundCount + 1
continue
icons = [] # その文書に含まれるicon記法
with open(fname) as f:
o = json.load(f)
for l in o["lines"]:
if l['userId'] == target:
# detect icon
m = re.findall(iconPattern, l["text"])
icons.extend(m)
for icon in icons:
if iconsCount.get(icon) == None:
iconsCount[icon] = 0
else:
iconsCount[icon] = iconsCount[icon] + 1
if(len(iconsCount) > 0):
print(sorted(iconsCount.items(), key=lambda x:x[1])[-1][0])
else:
print("not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment