-
-
Save tanupoo/d9b8d177b3e7f4597c2e35a09a59c10c to your computer and use it in GitHub Desktop.
mozilla hubsのソースコードからQuery Stringを抜き出す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
""" | |
find ./src -name '*.js' |\ | |
xargs grep -nE '(qs.get|qsTruthy|qsGet)' |\ | |
python findopts.py | |
""" | |
opts = {} | |
for line in sys.stdin: | |
line = line.strip() | |
r = re.match('([^:]+):(\d+):(.+qs[^"]+"([^"]+))".*', line) | |
if r: | |
if " from " not in line: | |
file_name = r.group(1).replace("./src/","") | |
line_no = r.group(2) | |
code = r.group(3) | |
k = r.group(4) | |
if re.search("(qs.get|qsGet)", line): | |
if "parseInt" in line: | |
t = "int" | |
else: | |
t = "str" | |
elif "qsTruthy" in line: | |
t = "bool" | |
opts[k] = f"{t} | {file_name} | {line_no} | {code}" | |
print("| name | type | file | line# | code |") | |
print("|------|------|------|-------|------|") | |
for k,v in sorted(opts.items()): | |
print(f"| {k} | {v} |") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment