Compare commits
5 Commits
moneymanag
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ce052e04d | |||
| ed85763ff5 | |||
| 1205dddc9e | |||
| 56d4354b53 | |||
| f16b3ae078 |
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.8
|
FROM python:3.8-slim
|
||||||
|
|
||||||
RUN pip install ofxparse
|
RUN pip install ofxparse
|
||||||
RUN pip install watchdog
|
RUN pip install watchdog
|
||||||
|
|||||||
46
converter.py
46
converter.py
@@ -134,9 +134,10 @@ class Handler(watchdog.events.PatternMatchingEventHandler):
|
|||||||
|
|
||||||
fileExists = False
|
fileExists = False
|
||||||
timeout = 0
|
timeout = 0
|
||||||
|
|
||||||
while not fileExists:
|
while not fileExists:
|
||||||
fileExists = os.path.isfile(event.src_path)
|
fileExists = os.path.isfile(event.src_path)
|
||||||
time.sleep(1)
|
time.sleep(5)
|
||||||
timeout += 1
|
timeout += 1
|
||||||
|
|
||||||
if timeout > 60:
|
if timeout > 60:
|
||||||
@@ -152,32 +153,41 @@ class Handler(watchdog.events.PatternMatchingEventHandler):
|
|||||||
logging.info("file copy has now finished")
|
logging.info("file copy has now finished")
|
||||||
|
|
||||||
with open(event.src_path, 'r') as file:
|
with open(event.src_path, 'r') as file:
|
||||||
qfx = OfxParser.parse(file, fail_fast=False)
|
try:
|
||||||
statement, acct_name = Handler.get_statement_from_qfx(qfx)
|
qfx = OfxParser.parse(file, fail_fast=False)
|
||||||
|
statement, acct_name = Handler.get_statement_from_qfx(qfx)
|
||||||
|
|
||||||
path = Path(event.src_path)
|
path = Path(event.src_path)
|
||||||
path.resolve()
|
path.resolve()
|
||||||
|
|
||||||
converted_dir = path.parent / CONVERTED_DIR
|
converted_dir = path.parent / CONVERTED_DIR
|
||||||
if not converted_dir.exists():
|
if not converted_dir.exists():
|
||||||
converted_dir.mkdir()
|
converted_dir.mkdir()
|
||||||
|
|
||||||
out_file = str(path.parent / CONVERTED_DIR / (acct_name + '-' + qfx.signon.dtserver + '.csv'))
|
out_file = str(path.parent / CONVERTED_DIR / (acct_name + '-' + qfx.signon.dtserver + '.csv'))
|
||||||
Handler.write_csv(statement, out_file)
|
Handler.write_csv(statement, out_file)
|
||||||
|
|
||||||
#Now move the input file to backup
|
#Now move the input file to backup
|
||||||
archive_file_dir = path.parent / BACKUP_DIR
|
archive_file_dir = path.parent / BACKUP_DIR
|
||||||
archive_file = (path.stem + '{:04d}' + path.suffix)
|
archive_file = (path.stem + '{:04d}' + path.suffix)
|
||||||
destination = Handler.unique_path(archive_file_dir, archive_file)
|
destination = Handler.unique_path(archive_file_dir, archive_file)
|
||||||
|
|
||||||
if not archive_file_dir.exists():
|
if not archive_file_dir.exists():
|
||||||
archive_file_dir.mkdir()
|
archive_file_dir.mkdir()
|
||||||
|
|
||||||
if not destination.exists():
|
if not destination.exists():
|
||||||
path.replace(destination)
|
path.replace(destination)
|
||||||
|
except:
|
||||||
|
logging.info("Failed to process {}".format(event.src_path))
|
||||||
|
|
||||||
logging.info("Processing successfully finished for {}".format(event.src_path))
|
logging.info("Processing successfully finished for {}".format(event.src_path))
|
||||||
|
|
||||||
|
def on_modified(self, event):
|
||||||
|
logging.info('Found modified file: {}'.format(event.src_path))
|
||||||
|
self.on_created(event)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
event_handler = Handler()
|
event_handler = Handler()
|
||||||
observer = watchdog.observers.Observer()
|
observer = watchdog.observers.Observer()
|
||||||
|
|||||||
Reference in New Issue
Block a user