Mercurial > repos > davidvanzessen > argalaxy_tools
annotate convert_windows_to_utf-8.py @ 61:f38a058e1a74 draft default tip
planemo upload commit 93519df849f317f4a8fc6167a48a4ee06e6aeff8
| author | rhpvorderman |
|---|---|
| date | Wed, 30 Apr 2025 12:44:38 +0000 |
| parents | 4c6df851e262 |
| 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 |
