]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - owm.py
Make constructing database URL more robust.
[chrisu/seepark.git] / owm.py
diff --git a/owm.py b/owm.py
index 1a55892a1cd0ba7bda3beb25b3dc7e186c107ca9..bd6ba6efb325be3c2cdedb983849a31422b8bf84 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -18,7 +18,7 @@ import os
 from pprint import pprint
 
 import sqlalchemy
-from sqlalchemy import create_engine, Table
+from sqlalchemy import create_engine, Table, URL
 
 from seeparklib.openweathermap import openweathermap_json
 
@@ -81,7 +81,8 @@ def write_db(config, url, weather_json, weather_data):
     host = config.get('database','hostname')
     db = config.get('database','database')
 
-    engine = create_engine('mysql+mysqldb://{}:{}@{}/{}'.format(user, pwd, host, db), echo=False)
+    db_url = URL.create(drivername='mysql+mysqldb', username=user, password=pwd, host=host, database=db)
+    engine = create_engine(db_url, echo=False)
     with engine.connect() as conn:
         row = dict(cityid=config.get('openweathermap', 'cityid'), url=url, result=json.dumps(weather_json))
         row.update(weather_data)