Write it pylama friendly
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b368f62f7f
commit
2e0dbaa3ce
27
src/main.py
27
src/main.py
|
@ -1,14 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import ovh
|
||||
import pendulum
|
||||
import requests
|
||||
import typer
|
||||
import yaml
|
||||
|
||||
import pprint
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
@ -21,16 +18,17 @@ with open(f"{home}/.config/ovh-bills-pdf/secrets.yaml", "r") as stream:
|
|||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
|
||||
|
||||
@app.command()
|
||||
def download_all():
|
||||
typer.echo(f"Download all bills")
|
||||
typer.echo("Download all bills")
|
||||
params = {}
|
||||
download(params)
|
||||
#/me/bill
|
||||
|
||||
|
||||
@app.command()
|
||||
def download_week():
|
||||
typer.echo(f"Download week")
|
||||
typer.echo("Download week")
|
||||
now = pendulum.now(f"{secrets['timezone']}")
|
||||
week_start = now.start_of('week')
|
||||
week_end = now.end_of('week')
|
||||
|
@ -42,7 +40,10 @@ def download_week():
|
|||
|
||||
|
||||
def download(params):
|
||||
if Path(secrets['download_path']).is_dir():
|
||||
if not Path(secrets['download_path']).is_dir():
|
||||
typer.echo(f"{secrets['download_path']} don't exist. Please create it")
|
||||
raise SystemExit()
|
||||
|
||||
for account in secrets['accounts']:
|
||||
typer.echo(f"Processing of {account['name']}")
|
||||
client = ovh.Client(
|
||||
|
@ -53,6 +54,13 @@ def download(params):
|
|||
)
|
||||
billIds = client.get('/me/bill', **params)
|
||||
if billIds:
|
||||
_processBill(client, billIds)
|
||||
|
||||
else:
|
||||
typer.echo("No bill to download")
|
||||
|
||||
|
||||
def _processBill(client, billIds):
|
||||
for billId in billIds:
|
||||
bill = client.get(f"/me/bill/{billId}")
|
||||
try:
|
||||
|
@ -77,11 +85,6 @@ def download(params):
|
|||
except OSError:
|
||||
typer.echo(f"Can't open {secrets['download_path']}/{bill['billId']}.pdf).")
|
||||
typer.echo("Folder exist ?")
|
||||
else:
|
||||
typer.echo("No bill to download")
|
||||
else:
|
||||
typer.echo(f"{secrets['download_path']} don't exist. Please create it")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue