X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/blobdiff_plain/c76885ae93a85e0abe3ed4362e6cf2f628a239aa..6d184c0177af1000cac5ff6c4edf6a754f827577:/owm.py?ds=inline diff --git a/owm.py b/owm.py index c41c319..5d5a77c 100755 --- a/owm.py +++ b/owm.py @@ -14,7 +14,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,9 +88,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))) - print(sql) - 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()