wrap csv filenames in os.path.expanduser()
authorgregor herrmann <gregor@toastfreeware.priv.at>
Wed, 13 Jun 2018 14:40:20 +0000 (16:40 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Wed, 13 Jun 2018 14:40:20 +0000 (16:40 +0200)
to allow ~ in filenames in ini file

owm.py
seewasser.py

diff --git a/owm.py b/owm.py
index d42ebed..878e3eb 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -94,6 +94,7 @@ def main(configfile):
     config.read(configfile)
     apikey = config.get('openweathermap', 'apikey')
     cityid = config.get('openweathermap', 'cityid')
+    csvfile = config.get("openweathermap", 'csvfilename')
 
     weather_raw = getweather(apikey, cityid)
     if debug:
@@ -106,7 +107,7 @@ def main(configfile):
     # write to db
 
     # write to csv
-    write_csv(config.get("openweathermap", 'csvfilename'), weather)
+    write_csv(os.path.expanduser(csvfile), weather)
 
 
 if __name__ == '__main__':
index dfed1cf..724beb6 100755 (executable)
@@ -54,7 +54,7 @@ def readsensor(sensor_id):
 
 def writesensordatacsv(config, sensor_id, sensor_name, timestamp, value_type, value_raw, value):
     # Schreiben des csv-files
-    file = open(config.get("csv", "filename"), "a", newline = "")
+    file = open(os.path.expanduser(config.get("csv", "filename")), "a", newline = "")
     writer = csv.writer(file, dialect = "excel")
     writer.writerow([timestamp.strftime("%Y-%m-%d %H:%M"), sensor_id, sensor_name, "{:.1f}".format(value)])