Explorar el Código

Make API generation script Python 2/3 compatible

Thibaud Colas hace 7 años
padre
commit
58547989e4
Se han modificado 1 ficheros con 8 adiciones y 1 borrados
  1. 8 1
      api.py

+ 8 - 1
api.py

@@ -15,6 +15,7 @@
 from __future__ import absolute_import, unicode_literals
 from __future__ import absolute_import, unicode_literals
 
 
 import json
 import json
+import codecs
 import datetime
 import datetime
 
 
 API_PATH = '/api/v1/readme.json'
 API_PATH = '/api/v1/readme.json'
@@ -72,9 +73,15 @@ if __name__ == '__main__':
     readme = open('README.md', 'r').read()
     readme = open('README.md', 'r').read()
 
 
     try:
     try:
+        readme = readme.decode('utf-8')
+    except:
+        pass
+
+    try:
         parsed_readme = parse_readme(readme)
         parsed_readme = parse_readme(readme)
+        json_path = './dist%s' % API_PATH
 
 
-        with open('./dist%s' % API_PATH, mode='w+', encoding='utf-8') as f:
+        with codecs.open(json_path, mode='w+', encoding='utf8') as f:
             readme_payload = json.dumps(parsed_readme, indent=True)
             readme_payload = json.dumps(parsed_readme, indent=True)
             print(readme_payload)
             print(readme_payload)
             f.write(readme_payload)
             f.write(readme_payload)