Created
September 27, 2015 21:21
-
-
Save bluebear94/95cdd917abe8399d7944 to your computer and use it in GitHub Desktop.
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
#!/bin/python3 | |
#TouhouDanmakufu[Package] | |
#ScriptVersion[3] | |
#Title["Nice Game!"] | |
#Text["Actually a Python script. (Yay! I'm free now!)"] | |
from pathlib import * | |
from io import * | |
from sys import * | |
def process_file(path): | |
output_path = path.with_suffix(".bin") | |
with path.open(encoding="utf=8") as input, output_path.open(mode="wb") as output: | |
output.write(bytes([0, 0])) | |
lines = 0 | |
for line in input: | |
if (line.endswith("\n")): line = line[0:-1] | |
b = line.encode() | |
l = len(b) | |
upper = l >> 8 | |
lower = l & 255 | |
output.write(bytes([lower, upper])) | |
output.write(b) | |
lines += 1 | |
output.seek(0) | |
upper = lines >> 8 | |
lower = lines & 255 | |
output.write(bytes([lower, upper])) | |
def iterate(f): | |
all_files = Path(".").glob("**/*.txt") | |
for file in all_files: | |
try: | |
f(file) | |
except Exception: | |
print(file + " could not be processed.") | |
raise | |
# main | |
path = argv[1] | |
process_file(Path(path)) | |
print("Packaged " + path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment