-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththpatch_images.py
72 lines (65 loc) · 2.08 KB
/
thpatch_images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# Touhou Patch Center
# Scripts
#
# ----
#
"""Builds an image page from thanm dumps."""
import argparse
import os
import pdb
import shutil
parser = argparse.ArgumentParser(
description=__doc__
)
parser.add_argument(
'f',
help='Root path of the extracted data.'
)
parser.add_argument(
'-t', '--to',
help='Path that receives all files to be uploaded to Touhou Patch Center.',
dest='t',
default=None
)
parser.add_argument(
'-g', '--game',
help='Game ID.',
required=True
)
if __name__ == '__main__':
arg = parser.parse_args()
# Header
print("""<languages /><div style="float:right;">__TOC__</div>
{{#vardefine:game|%s}}
<translate><!--T:0-->
<!-- Optional message you want to include at the top of the page --></translate>"""
% arg.game)
for root, dirs, files in os.walk(arg.f):
for fn in files:
if (fn.endswith('.png') or fn.endswith('.jpg') or fn.endswith('.gif')) and not fn.startswith('bounds-'):
f_fn = os.path.join(root, fn)
game_fn = f_fn[len(arg.f) + 1:].replace('\\', '/')
tlunit = game_fn.replace('/', ' ')
wiki_fn = arg.game + "-" + game_fn.replace('/', '-')
if arg.t:
t_fn = os.path.join(arg.t, wiki_fn)
bounds_fn = 'bounds-' + wiki_fn
f_bounds_fn = os.path.join(arg.f, bounds_fn)
t_bounds_fn = os.path.join(arg.t, bounds_fn)
shutil.copy2(f_fn, t_fn)
try:
shutil.copy2(f_bounds_fn, t_bounds_fn)
except FileNotFoundError:
pass
else:
t_fn = None
print("""{{thcrap Image
|target=%s
|transcription=<translate><!--T:%s-->
Please add a transcription by editing the corresponding section on the root page ([[%s]])!
</translate>
}}""" % (game_fn, tlunit, arg.game + "/Images")
)
# Footer
print("{{SubpageCategory}}\n(Don't forget to set the .anm data format in the main .js file!)")