Fixing yaml loading warnings, checking if bill is already in nextcloud

This commit is contained in:
Kirby 2020-03-13 10:51:05 +01:00
parent f3c3fd231c
commit 4450c6e07d

View File

@ -10,8 +10,8 @@ try:
except NameError: except NameError:
pass pass
conf = yaml.load(open('creds.yml')) conf = yaml.load(open('creds.yml'), Loader=yaml.SafeLoader)
user = conf['nextcloud']['username'] username = conf['nextcloud']['username']
password = conf['nextcloud']['password'] password = conf['nextcloud']['password']
client = ovh.Client() client = ovh.Client()
bills = client.get('/me/bill') bills = client.get('/me/bill')
@ -24,12 +24,23 @@ for bill in bills:
f.write(r.content) f.write(r.content)
f.close() f.close()
url += bill + ".pdf" url += bill + ".pdf"
file = open(file_path) with open('/dev/null','wb') as output:
c = pycurl.Curl() c = pycurl.Curl()
c.setopt(c.URL, url) c.setopt(c.URL, url)
c.setopt(c.USERPWD, '%s:%s' %(username, password)) c.setopt(c.USERPWD, '%s:%s' %(username, password))
c.setopt(c.UPLOAD, 1) c.setopt(c.CUSTOMREQUEST, 'PROPFIND')
c.setopt(c.READDATA, file) c.setopt(c.WRITEDATA, output)
c.perform() c.perform()
c.close() status = c.getinfo(c.RESPONSE_CODE)
file.close() 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()