|
@@ -52,6 +52,10 @@ class Anafoauth(object):
|
|
|
def get_token(self) -> ujson:
|
|
|
# oauth = OAuth2Session(self.client_id, redirect_uri=self.redirect_uri)
|
|
|
authorization_url, _state = self.oauth.authorization_url(self.AUTH_URL)
|
|
|
+ #
|
|
|
+ # for JWT token
|
|
|
+ # authorization_url, state = self.oauth.authorization_url(self.AUTH_URL, params=AUTH_URL_PARAMS)
|
|
|
+ #
|
|
|
print(authorization_url)
|
|
|
# self._browser_redirect(self.authorization_url)
|
|
|
driver = webdriver.Chrome()
|
|
@@ -68,6 +72,10 @@ class Anafoauth(object):
|
|
|
auth=self.auth,
|
|
|
code=auth_code,
|
|
|
client_secret=self.client_secret)
|
|
|
+ #
|
|
|
+ # for JWT token we must add an additional body argument to fetch_token
|
|
|
+ # body=TOKEN_URL_BODY
|
|
|
+ #
|
|
|
print(self.token)
|
|
|
return self.token
|
|
|
|
|
@@ -161,13 +169,13 @@ class Efactoauth(Anafoauth):
|
|
|
# app_icon=app_icon,
|
|
|
timeout=86400)
|
|
|
|
|
|
- def get_all_messages(self, vat_id, days=60, env='test', extract=False) -> dict:
|
|
|
+ def get_all_messages(self, vat_id, days=60, env='test', root_path='efact', extract=False) -> dict:
|
|
|
url = self.MESSAGES.format(env, days, vat_id)
|
|
|
resp = self.oauth.get(url=url)
|
|
|
print(resp.text)
|
|
|
try:
|
|
|
self.invoices = resp.json()
|
|
|
- path = 'efact'
|
|
|
+ # path = 'efact'
|
|
|
for index_, inv in enumerate(self.invoices['mesaje'], start=1):
|
|
|
date_ = datetime.date(int(inv['data_creare'][:4]), int(inv['data_creare'][4:6]), int(inv['data_creare'][6:8]))
|
|
|
cif = re.search('(?<=cif_emitent=)[0-9]+', inv['detalii']).group()
|
|
@@ -177,7 +185,7 @@ class Efactoauth(Anafoauth):
|
|
|
dir_cifs = '{}'.format(cif)
|
|
|
dir_types = type_
|
|
|
dir_days = '{:02d}'.format(date_.day)
|
|
|
- dirs = os.path.join(path, dir_cifs, dir_types, dir_dates, dir_days)
|
|
|
+ dirs = os.path.join(root_path, dir_cifs, dir_types, dir_dates, dir_days)
|
|
|
# print(dirs)
|
|
|
os.makedirs(dirs, exist_ok=True)
|
|
|
new = self.download_invoice(download_id=inv['id'], path=dirs, env=env)
|