Explorar o código

Make API generation script Python 2/3 compatible

Thibaud Colas %!s(int64=8) %!d(string=hai) anos
pai
achega
58547989e4
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      api.py

+ 8 - 1
api.py

@@ -15,6 +15,7 @@
 from __future__ import absolute_import, unicode_literals
 
 import json
+import codecs
 import datetime
 
 API_PATH = '/api/v1/readme.json'
@@ -72,9 +73,15 @@ if __name__ == '__main__':
     readme = open('README.md', 'r').read()
 
     try:
+        readme = readme.decode('utf-8')
+    except:
+        pass
+
+    try:
         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)
             print(readme_payload)
             f.write(readme_payload)