Skip to content

Commit

Permalink
chore: more file type
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 1, 2024
1 parent f019a45 commit 96fd0a5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/weby_pilot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .base import WebyAPI
from .bpi import BpiAPI
from .big import BigAPI
from .common import FileType
22 changes: 20 additions & 2 deletions src/weby_pilot/bpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from selenium.webdriver.common.keys import Keys

from .base import WebyAPI
from .common import FileType

BpiSections = Literal[
"Consultas",
Expand Down Expand Up @@ -107,6 +108,7 @@ def download_invoice(
BpiDocumentType.from_section(document_type),
basename(self._last_download_path),
self._last_download_buffer(),
file_type=FileType.PDF,
account=self.username,
date=datetime.strptime(
self._last_download_path[-14:-4], "%Y-%m-%d"
Expand All @@ -132,6 +134,7 @@ def download_report(
BpiDocumentType.from_section(section),
basename(self._last_download_path),
self._last_download_buffer(),
file_type=FileType.PDF,
account=self.username,
date=datetime.strptime(
self._last_download_path[-14:-4], "%Y-%m-%d"
Expand Down Expand Up @@ -242,23 +245,38 @@ class BpiDocument:

type: BpiDocumentType
name: str
buffer: IO
buffer: IO[bytes]
file_type: FileType
account: str | None
date: datetime | None

def __init__(
self,
type: BpiDocumentType,
name: str,
buffer: IO,
buffer: IO[bytes],
file_type: FileType,
account: str | None = None,
date: datetime | None = None,
):
self.type = type
self.name = name
self.buffer = buffer
self.file_type = file_type
self.account = account
self.date = date

def __repr__(self):
return f"BpiDocument(type={self.type}, name={self.name}, account={self.account} date={self.date})"

@property
def year(self) -> Tuple[int, int]:
if self.date is None:
raise Exception("Date is not set")
return self.date.year

@property
def month_filename(self) -> str:
if self.date is None:
raise Exception("Date is not set")
return f"{self.date.strftime('%m')}.{self.file_type.extension}"
14 changes: 14 additions & 0 deletions src/weby_pilot/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from enum import Enum


class FileType(Enum):
PDF = "application/pdf"
CSV = "text/csv"
TXT = "text/plain"

@property
def extension(self) -> str:
return self.name.lower()

0 comments on commit 96fd0a5

Please sign in to comment.