-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: contentlanguages need to be matched before piping output to target
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
FROM node:20-alpine | ||
|
||
RUN apk add --no-cache jq=1.7.1-r0 curl=8.8.0-r0 && \ | ||
RUN apk add --no-cache jq=1.7.1-r0 curl=8.8.0-r0 python3=3.12.3-r1 && \ | ||
npm install -g wikibase-cli@18.0.3 | ||
|
||
COPY --chmod=755 ./transferbot.sh /usr/bin/transferbot | ||
COPY --chmod=755 ./adjust_data.py /usr/bin/adjust_data | ||
|
||
ENTRYPOINT ["transferbot"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import fileinput | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Adjust a line from wb-cli so it can be fed into the target wiki" | ||
) | ||
|
||
parser.add_argument("-s", "--source", action="store", dest="source", required=True) | ||
parser.add_argument("-t", "--target", action="store", dest="target", required=True) | ||
parser.add_argument("-p", "--pick", action="append", dest="pick", required=True) | ||
|
||
|
||
def main(): | ||
args = parser.parse_args() | ||
source = json.load(open(args.source)) | ||
target = json.load(open(args.target)) | ||
|
||
source_languages = source["query"]["wbcontentlanguages"].keys() | ||
target_languages = target["query"]["wbcontentlanguages"].keys() | ||
|
||
selected_languages = set(source_languages) & set(target_languages) | ||
|
||
for line in fileinput.input("-"): | ||
data = json.loads(line) | ||
out = {} | ||
for key, value in data.items(): | ||
if key not in args.pick: | ||
continue | ||
|
||
if type(value) is not "dict": | ||
out[key] = value | ||
continue | ||
|
||
out[key] = {} | ||
for lang, value in data[key].items(): | ||
if lang in selected_languages: | ||
out[key][lang] = value | ||
|
||
print(json.dumps(out, ensure_ascii=False)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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