Compare commits
2 Commits
f3c3fd231c
...
c17318aea4
| Author | SHA1 | Date | |
|---|---|---|---|
| c17318aea4 | |||
| 4450c6e07d |
46
ovh-bills.py
Executable file
46
ovh-bills.py
Executable 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()
|
||||||
@ -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()
|
|
||||||
Loading…
x
Reference in New Issue
Block a user