Skip to content

Commit

Permalink
added export to csv function
Browse files Browse the repository at this point in the history
  • Loading branch information
esalonico committed Jun 3, 2023
1 parent eb49c6d commit cf8f186
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/google_flight_analysis/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class _Scrape:

def __init__(self, export=False):
def __init__(self):
self._origin = None
self._dest = None
self._date_leave = None
Expand All @@ -31,12 +31,12 @@ def __init__(self, export=False):
self.results_dirty = None
self.results_clean = None
self.url = None
self.export = export


def __call__(self, *args):
def __call__(self, *args, export=False):
self._set_properties(*args)
self._data = self._scrape_data()
self.export = export
obj = self.clone(*args)

obj.data = self._data
Expand Down Expand Up @@ -95,12 +95,11 @@ def export_to_csv(self):
"""
folder = "outputs"

# TODO: check
# check if output folder exists
if not os.path.isdir("folder"):
if not os.path.isdir(folder):
raise FileNotFoundError(f"Check if folder {folder} esists")

access_date = datetime.strptime(self.data["Access Date"][0], "%Y-%m-%d").strftime("%y%m%d").strftime("%y%m%d_%H%M")
access_date = datetime.strptime(self.data["Access Date"][0], "%Y-%m-%d %H:%M:%S").strftime("%y%m%d_%H%M")
days_in_advance = self.data["Days in Advance"].min()
leave_date = datetime.strptime(self._date_leave, "%Y-%m-%d").strftime("%y%m%d")
return_date = (datetime.strptime(self._date_return, "%Y-%m-%d").strftime("%y%m%d") if self._date_return else None)
Expand All @@ -113,10 +112,11 @@ def export_to_csv(self):

full_filepath = os.path.join(folder, res)

# TODO: check
# if file already exists, raise ValueError
if os.path.isfile(full_filepath):
raise ValueError(f"File {full_filepath} already exists")

self.data.to_csv(full_filepath, index=False)


def _set_properties(self, *args):
Expand Down

0 comments on commit cf8f186

Please sign in to comment.