Mercurial > repos > davidvanzessen > argalaxy_tools
annotate convert_windows_to_utf-8.py @ 58:4c6df851e262 draft default tip
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
author | rhpvorderman |
---|---|
date | Fri, 21 Apr 2023 10:04:39 +0000 |
parents | |
children |
rev | line source |
---|---|
58
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
1 import argparse |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
2 |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
3 if __name__ == "__main__": |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
4 parser = argparse.ArgumentParser() |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
5 parser.add_argument("files", nargs="+") |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
6 args = parser.parse_args() |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
7 for file in args.files: |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
8 with open(file, "rb") as in_r: |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
9 data = in_r.read() |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
10 text = data.decode("windows-1252") |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
11 text = text.replace("charset=windows-1252", "charset=\"UTF-8\"", 1) |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
12 with open(file, "wt", encoding="UTF-8") as out: |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
13 out.write(text) |
4c6df851e262
"planemo upload commit 1a7731bb4fe2e80fb1fdc88121783068af3edb08"
rhpvorderman
parents:
diff
changeset
|
14 |