Skip to content

Instantly share code, notes, and snippets.

@fieldingtron
Last active May 5, 2018 11:22
Show Gist options
  • Save fieldingtron/b7d9d02e11293b3d1be6745c49c35745 to your computer and use it in GitHub Desktop.
Save fieldingtron/b7d9d02e11293b3d1be6745c49c35745 to your computer and use it in GitHub Desktop.
replace wierd wordpress characters in utf-8 in markdown files using python 3
#!/usr/bin/env python
filename = "filemarkdown.md"
## OPEN FILE READ TO FILEDATA
f = open(filename,'r', encoding="utf-8")
newdata = f.read()
f.close()
#REPLACE wierd characters
newdata = newdata.replace( '‘', '‘')
newdata = newdata.replace( '’', '’')
newdata = newdata.replace( '‘', '‘')
newdata = newdata.replace( '—', '–')
newdata = newdata.replace( '–', '—')
newdata = newdata.replace( '•', '-')
newdata = newdata.replace( '…', '…')
newdata = newdata.replace('â€', '”')
newdata = newdata.replace( '�', '')
newdata = newdata.replace( '', '')
#rewrite the files
f = open(filename,'w', encoding="utf-8")
f.write(newdata)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment