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:
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()