]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - owm.py
Update autogenerated API docs.
[chrisu/seepark.git] / owm.py
diff --git a/owm.py b/owm.py
index c36064f56e7556fa9e4b9c1f89df7c903dec6241..74fe6c48e2e0fdb30eaa8e3c4aa3a478d0543281 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -6,6 +6,8 @@
 # cityid=..
 # 3319578 for Obsteig, AT
 
+# needed packaes: python3-mysqldb python3-sqlalchemy
+
 from pprint import pprint
 import argparse
 import configparser
@@ -14,7 +16,10 @@ import csv
 import datetime
 import math
 import json
+import warnings
+import sqlalchemy
 from sqlalchemy import create_engine
+import MySQLdb.cursors
 from seeparklib.openweathermap import openweathermap_json
 
 
@@ -85,8 +90,11 @@ def write_db(config, url, weather_json, weather_data):
             row[key] = None
     sql_columns = list(row.keys())
     sql_values = list(row.values())
-    sql = 'insert into openweathermap ({}) values ({})'.format(', '.join(sql_columns), ','.join(['%s'] * len(sql_columns)))
-    conn.execute(sql, *sql_values)
+    sql = 'insert ignore into openweathermap ({}) values ({})'.format(', '.join(sql_columns), ','.join(['%s'] * len(sql_columns)))
+    with warnings.catch_warnings():
+        # ignore _mysql_exceptions.Warning: Duplicate entry '3319578-2018-08-01 20:50:00' for key 'cityid_datetime'
+        warnings.simplefilter("ignore", category=MySQLdb.cursors.Warning)
+        conn.execute(sql, *sql_values)
     conn.close()