Browse Source

Make API generation script Python 2/3 compatible

Thibaud Colas 7 years ago
parent
commit
58547989e4
1 changed files with 8 additions and 1 deletions
  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)