Adding scripts to work with bills, domain and retrieve consumer key
This commit is contained in:
parent
be6395f60d
commit
2904536840
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
data/*
|
||||||
|
*.yml
|
||||||
|
*.conf
|
||||||
26
ovh-domain.py
Executable file
26
ovh-domain.py
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import ovh
|
||||||
|
import pycurl
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Process arguments')
|
||||||
|
parser.add_argument('domain', metavar='method', type=str, help='Function to use')
|
||||||
|
parser.add_argument('--method', metavar='fr', type=str, help='domain to request from')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Instantiate. Visit https://api.ovh.com/createToken/?GET=/me
|
||||||
|
# to get your credentials
|
||||||
|
client = ovh.Client()
|
||||||
|
|
||||||
|
# Grab bill list
|
||||||
|
zone = client.get('/domain/zone/' + args.domain + '/record')
|
||||||
|
for id in zone:
|
||||||
|
entry = client.get('/domain/zone/' + args.domain + '/record/'+str(id))
|
||||||
|
print(entry)
|
||||||
35
ovh-factures.py
Executable file
35
ovh-factures.py
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/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="https://nextcloud.hyrule.ovh/nextcloud/remote.php/dav/files/seb/Documents/Factures/OVH/"
|
||||||
|
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()
|
||||||
18
ovh-getck.py
Executable file
18
ovh-getck.py
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import requests
|
||||||
|
import ovh
|
||||||
|
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
client = ovh.Client()
|
||||||
|
ck = client.new_consumer_key_request()
|
||||||
|
ck.add_recursive_rules(ovh.API_READ_WRITE, "/")
|
||||||
|
validation = ck.request()
|
||||||
|
print("Please visit %s to authenticate" % validation['validationUrl'])
|
||||||
|
input("and press Enter to continue...")
|
||||||
|
print("Welcome", client.get('/me')['firstname'])
|
||||||
|
print("Btw, your 'consumerKey' is '%s'" % validation['consumerKey'])
|
||||||
|
|
||||||
53
ovh-mail.py
Executable file
53
ovh-mail.py
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import ovh
|
||||||
|
import pycurl
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
def writeRedirectionsToFile(client):
|
||||||
|
# Grab bill list
|
||||||
|
mailbox = client.get('/email/domain/hyrule.ovh/redirection')
|
||||||
|
file = open(redir_file,'wt')
|
||||||
|
for id in mailbox:
|
||||||
|
redirection = client.get('/email/domain/hyrule.ovh/redirection/'+str(id))
|
||||||
|
file.write(redirection['from']+','+redirection['to']+','+redirection['id']+'\n')
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
def checkRedirExists(client,fr,to):
|
||||||
|
mailbox = client.get('/email/domain/hyrule.ovh/redirection')
|
||||||
|
for id in mailbox:
|
||||||
|
redirection = client.get('/email/domain/hyrule.ovh/redirection/'+str(id))
|
||||||
|
if (redirection['from'] == fr and redirection['to'] == to):
|
||||||
|
print("Redirection existante")
|
||||||
|
return id
|
||||||
|
elif (redirection['from'] == fr and redirection ['to'] != to):
|
||||||
|
print("Redirection existante vers l'adresse " + redirection['to'])
|
||||||
|
return id
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def addRedirection(client,fr,to):
|
||||||
|
result = client.post('/email/domain/hyrule.ovh/redirection',_from=fr,localCopy=False,to=to)
|
||||||
|
print(json.dumps(result,indent=4))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Process arguments')
|
||||||
|
parser.add_argument('method', metavar='method', type=str, help='Function to use')
|
||||||
|
parser.add_argument('--fr', metavar='fr', type=str, help='from mail address')
|
||||||
|
parser.add_argument('--to', metavar='to', type=str, help='to mail address')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
redir_file = '/var/scripts/ovh_api/data/redirections.txt'
|
||||||
|
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
client = ovh.Client()
|
||||||
|
if (args.method == "write"):
|
||||||
|
writeRedirectionsToFile(client)
|
||||||
|
elif (args.method == "add"):
|
||||||
|
if not (checkRedirExists(client,args.fr,args.to)):
|
||||||
|
addRedirection(client,args.fr,args.to)
|
||||||
Loading…
x
Reference in New Issue
Block a user