Compare commits

...

2 Commits

2 changed files with 46 additions and 35 deletions

46
ovh-bills.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/python3
import requests
import ovh
import pycurl
import yaml
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()

View File

@ -1,35 +0,0 @@
#!/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()