ovh-scripts/ovh-factures.py

36 lines
879 B
Python
Executable File

#!/usr/bin/python3
import requests
import ovh
import pycurl
import yaml
try:
input = raw_input
except NameError:
pass
conf = yaml.load(open('creds.yml'))
user = conf['nextcloud']['username']
password = conf['nextcloud']['password']
client = ovh.Client()
bills = client.get('/me/bill')
for bill in bills:
url = conf['nextcloud']['url_factures']
details = client.get('/me/bill/%s' % bill)
r = requests.get(details['pdfUrl'], stream=True)
file_path = "/tmp/" + bill + ".pdf"
with open(file_path, 'wb') as f:
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()