|
import sys |
|
import os |
|
import argparse |
|
|
|
placeholder = 'Paste mojibake here\nここで文字化けをペースト下さい' |
|
default_source_enc = 'sjis' |
|
|
|
# Open a file in binary mode and overwrite contents |
|
# with the text encoded in the given encoding |
|
def write_file(filename, encoding, text): |
|
with open(filename, 'wb') as f: |
|
f.write(text.encode(encoding)) |
|
f.write(b'\n') # newline at end of file |
|
|
|
# Open a file and return a string of the file contents decoded using the specified encoding |
|
def read_file(filename, encoding): |
|
with open(filename, 'r', encoding=encoding) as f: |
|
return f.read() |
|
|
|
if __name__ == '__main__': |
|
parser = argparse.ArgumentParser(description='Fix mojibake characters') |
|
parser.add_argument('filename', metavar='file', |
|
help='file to convert') |
|
parser.add_argument('--create', dest='create_file', action='store_true', |
|
help='create the file to paste mojibake text into, and open it in TextEdit') |
|
parser.add_argument('--overwrite', dest='overwrite_file', action='store_true', |
|
help='(only with --create) overwrite file') |
|
parser.add_argument('--from', dest='from_encoding', |
|
metavar='source_encoding', |
|
default=default_source_enc, |
|
help=f'source encoding (default: {default_source_enc})') |
|
|
|
args = parser.parse_args() |
|
|
|
from_encoding = args.from_encoding |
|
# target_encoding = 'utf-8' |
|
filename = args.filename |
|
create_file = args.create_file |
|
overwrite_file = args.overwrite_file |
|
|
|
if create_file: |
|
if os.path.exists(filename): |
|
if not overwrite_file: |
|
print('File already exists, skipping...') |
|
else: |
|
# 1. Write placeholder text to file, in original encoding |
|
print('Writing placeholder text to file') |
|
write_file(filename, from_encoding, placeholder) |
|
|
|
# 2. Paste manually into TextEdit |
|
print('Please paste the text manually into TextEdit') |
|
print('Press enter when ready to proceed') |
|
os.system('open -a TextEdit ' + filename) |
|
input() |
|
|
|
# 3. Output correctly-decoded file contents |
|
# New encoding should be in utf-8, which (I think) usually corresponds to what Python uses to output and is what most terminals use by default |
|
converted = read_file(filename, from_encoding) |
|
print(converted) |
qv4cdata) ��� ™ˆ¯Ñ“� ø� ¨�ï ¹ß|l“þ†gu/Ÿ8²wÊ�³rTÚl�ëa� è� I �� � ø$� $ � $� 6 $ � ü� � � (� (� (� (� (� (� (� ÿÿÿÿH H � (� � �� p� Ø� (� x� È� � h� Ð� ³� Ó� ã� ó� �� �� #� À� ³� 3� C� S� c� s� ƒ� À� s �� C � °� Ã� Ó� à� ó� �� �� ó� s �� s �� �� s � s 0� @� s 0� P� s �� s �� C �
� s �� s p� s �� ü¿ üÿ �À €¿ •¿H , 8 8 � ÿÿÿÿ� - P - + . . � .��.�|� .�| � .��.�|� .�| ��¦ � ��� H , � 8 8 � ÿÿÿÿ� / P / + 0 .�� . �. |� .�| � .�. |� .�| ��¦� � ��� @ � � 8 8 � ÿÿÿÿ� 3 P 3 .�:�� .�:�:�j ��� @ ! � 8 8 � ÿÿÿÿ 4 P 4 .�� .�:�\ L .���.�š�H�.�� .�š ��� @ � 8 8 � ÿÿÿÿ 7 � 7 .�:�L���H������ @ � � 8 8 � ÿÿÿÿ 8 � 8 .�:�L���H������ @ � � 8 8 � ÿÿÿÿ� : � : . � ��š ��� @ � � 8 8 � ÿÿÿÿ ; � ; .!:"L�.#:$:%H�.&:':(��� @ � 8 8 � ÿÿÿÿ H 0� H .):*��� @ # � 8 8 � ÿÿÿÿ @ Ð @ .+:,� .-:.:/h J�.0:1L .2:3����d���� @ � 8 8 � ÿÿÿÿ A ð� A .4:5��� @ˆ È �� 0� p� � È� X � è �8
€
°
� 0� X� � � � 8
ˆ ° Ø � P x À è �� @� €� ¸� è� � P� p� � Ð� �� 8� X� � Ð� � H� x� °� � 0�� ¨� Ø� �� 8� h� ˜� È� è� �� @� h� ˜� À� è� �� 0�� ˆ� ÿÿÿÿ � � ÿÿÿÿ � � Q t Q u i c k ÿÿÿÿ� � � Q t Q u i c k . C o n t r o l s ÿÿÿÿ� � � Q t Q u i c k . C o n t r o l s . i m p l ÿÿÿÿ� � � T ÿÿÿÿ� � � Q t Q u i c k . T e m p l a t e s ÿÿÿÿ� � � T . S c r o l l B a r ÿÿÿÿ � � c o n t r o l ÿÿÿÿ � � i m p l i c i t W i d t h ÿÿÿÿ� � � e x p r e s s i o n f o r i m p l i c i t W i d t h ÿÿÿÿ� � � i m p l i c i t H e i g h t ÿÿÿÿ� � � e x p r e s s i o n f o r i m p l i c i t H e i g h t ÿÿÿÿ � � p a d d i n g ÿÿÿÿ � � v i s i b l e ÿÿÿÿ� � � e x p r e s s i o n f o r v i s i b l e ÿÿÿÿ� � � m i n i m u m S i z e ÿÿÿÿ� � � e x p r e s s i o n f o r m i n i m u m S i z e ÿÿÿÿ � � R e c t a n g l e ÿÿÿÿ� � � r a d i u s ÿÿÿÿ� � � e x p r e s s i o n f o r r a d i u s ÿÿÿÿ� � � c o l o r ÿÿÿÿ� � � e x p r e s s i o n f o r c o l o r ÿÿÿÿ � � o p a c i t y ÿÿÿÿ� � � S t a t e ÿÿÿÿ� � � n a m e ÿÿÿÿ� � � a c t i v e ÿÿÿÿ� � � w h e n ÿÿÿÿ� � � e x p r e s s i o n f o r w h e n ÿÿÿÿ� � � P r o p e r t y C h a n g e s ÿÿÿÿ� � � t a r g e t ÿÿÿÿ� � � e x p r e s s i o n f o r t a r g e t ÿÿÿÿ� � � s t a t e s ÿÿÿÿ � � T r a n s i t i o n ÿÿÿÿ� � � f r o m ÿÿÿÿ� � � S e q u e n t i a l A n i m a t i o n ÿÿÿÿ� � � P a u s e A n i m a t i o n ÿÿÿÿ� � � d u r a t i o n ÿÿÿÿ� � � N u m b e r A n i m a t i o n ÿÿÿÿ� � � p r o p e r t y ÿÿÿÿ� � � t o ÿÿÿÿ� � � t r a n s i t i o n s ÿÿÿÿ� � � c o n t e n t I t e m ÿÿÿÿ� � � c o n t r o l . c o n t e n t I t e m ÿÿÿÿ� � � M a t h ÿÿÿÿ� � � m a x ÿÿÿÿ� � � i m p l i c i t B a c k g r o u n d W i d t h ÿÿÿÿ � � l e f t I n s e t ÿÿÿÿ � � r i g h t I n s e t ÿÿÿÿ� � � i m p l i c i t C o n t e n t W i d t h ÿÿÿÿ� � � l e f t P a d d i n g ÿÿÿÿ � � r i g h t P a d d i n g ÿÿÿÿ� � � i m p l i c i t B a c k g r o u n d H e i g h t ÿÿÿÿ� � � t o p I n s e t ÿÿÿÿ� � � b o t t o m I n s e t ÿÿÿÿ� � � i m p l i c i t C o n t e n t H e i g h t ÿÿÿÿ � � t o p P a d d i n g ÿÿÿÿ � � b o t t o m P a d d i n g ÿÿÿÿ� � � p o l i c y ÿÿÿÿ � � S c r o l l B a r ÿÿÿÿ � � A l w a y s O f f ÿÿÿÿ� � � o r i e n t a t i o n ÿÿÿÿ� � � Q t ÿÿÿÿ � � H o r i z o n t a l ÿÿÿÿ� � � h e i g h t ÿÿÿÿ� � � w i d t h ÿÿÿÿ� � � i n t e r a c t i v e ÿÿÿÿ � � p r e s s e d ÿÿÿÿ � � p a l e t t e ÿÿÿÿ� � � d a r k ÿÿÿÿ� � � m i d ÿÿÿÿ� � � A l w a y s O n ÿÿÿÿ� � � s i z e ÿÿÿÿ< � � q r c : / q t - p r o j e c t . o r g / i m p o r t s / Q t Q u i c k / C o n t r o l s . 2 / S c r o l l B a r . q m l � � � p � � � % � � � � & � � � � ' � � � � � ( � � x� x� �� � (� °� � � � ÿÿÿÿ T T T T T � T � ä * � + P è è ) € � � 6 P 6 �� � 4 P 4 � � 3 P 3 à � 2 P 2 à � / P / P�� - P - @� � ÿÿÿÿÿÿ T T T T T T ü 6 � ü ü ( � � D � D�� � � > � > ��� � � < � < �� ; � ; �� � : � : ��� 8 � 8 ��� � 7 � 7 €� � � ÿÿÿÿÿÿ T T T T T � T œ > �� œ œ � @ Ð @ 0�� � � ? Ð ? 0� € � � A Ð A Ð � � ÿÿÿÿÿÿ T T T T T � T „ A Ð „ „ � �� � A À�A P��