add script to update card script's image url if set matches

master
melvinzhang 2015-03-22 13:23:35 +08:00
parent faa141e9a0
commit 5c8e188cd4
1 changed files with 36 additions and 0 deletions

36
scripts/update_image.awk Normal file
View File

@ -0,0 +1,36 @@
# input:
# mapping file with one <card name><tab><image url> per line
# card script file to be updated, with image=<set>
# output:
# updated card script content
# condition:
# only update if computed image url has the same set
BEGIN {
FS = "\t"
}
NF == 2 {
map[$1] = $2
}
/^name=/ {
name = gensub("name=","","g", $0)
image = map[name]
}
/^image=/ {
old_set = gensub("image=","","g", $0)
new_set = gensub("http://magiccards.info/scans/en/", "", "g", image)
new_set = gensub("/[^/]*.jpg", "", "g", new_set)
if (old_set == new_set) {
print "image=" image
} else {
print $0
}
next
}
NF == 1 {
print $0
}