47 lines
1.4 KiB
Python
Executable File
47 lines
1.4 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import requests
|
|
import ovh
|
|
import yaml
|
|
import pycurl
|
|
|
|
try:
|
|
input = raw_input
|
|
except NameError:
|
|
pass
|
|
|
|
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')
|
|
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"
|
|
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()
|