From 4450c6e07d6d376c48522affcc5d56f088499b44 Mon Sep 17 00:00:00 2001 From: Kirby Date: Fri, 13 Mar 2020 10:51:05 +0100 Subject: [PATCH] Fixing yaml loading warnings, checking if bill is already in nextcloud --- ovh-factures.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/ovh-factures.py b/ovh-factures.py index 61ae9f5..172fdab 100755 --- a/ovh-factures.py +++ b/ovh-factures.py @@ -10,8 +10,8 @@ try: except NameError: pass -conf = yaml.load(open('creds.yml')) -user = conf['nextcloud']['username'] +conf = yaml.load(open('creds.yml'), Loader=yaml.SafeLoader) +username = conf['nextcloud']['username'] password = conf['nextcloud']['password'] client = ovh.Client() bills = client.get('/me/bill') @@ -24,12 +24,23 @@ for bill in bills: f.write(r.content) f.close() url += bill + ".pdf" - file = open(file_path) - c = pycurl.Curl() - c.setopt(c.URL, url) - c.setopt(c.USERPWD, '%s:%s' %(username, password)) - c.setopt(c.UPLOAD, 1) - c.setopt(c.READDATA, file) - c.perform() - c.close() - file.close() + with open('/dev/null','wb') as output: + c = pycurl.Curl() + c.setopt(c.URL, url) + c.setopt(c.USERPWD, '%s:%s' %(username, password)) + c.setopt(c.CUSTOMREQUEST, 'PROPFIND') + c.setopt(c.WRITEDATA, output) + c.perform() + status = c.getinfo(c.RESPONSE_CODE) + c.close() + output.close() + if (status == 404): + file = open(file_path) + c = pycurl.Curl() + c.setopt(c.URL, url) + c.setopt(c.USERPWD, '%s:%s' %(username, password)) + c.setopt(c.UPLOAD, 1) + c.setopt(c.READDATA, file) + c.perform() + c.close() + file.close()