-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: save new files to db after downoad
- Loading branch information
1 parent
c50b89d
commit 0243b41
Showing
8 changed files
with
315 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
work-folder: /data/.work | ||
|
||
destination: | ||
folder: /data/hk_l0/ | ||
filename: power.pkts | ||
|
||
packet-definition: | ||
hk: src/imap_mag/xtce/tlm_20240724.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
source: | ||
folder: /data/hk_l0/ | ||
|
||
work-folder: /data/.work | ||
|
||
destination: | ||
folder: /data/hk_l1/ | ||
filename: result.csv | ||
|
||
packet-definition: | ||
hk: src/imap_mag/xtce/tlm_20240724.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
work-folder: /data/science | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
|
||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from src.imap_db.model import File | ||
|
||
|
||
class DB: | ||
def __init__(self, db_url=None): | ||
env_url = os.getenv("SQLALCHEMY_URL") | ||
if db_url is None and env_url is not None: | ||
db_url = env_url | ||
|
||
self.engine = create_engine(db_url) | ||
self.Session = sessionmaker(bind=self.engine) | ||
|
||
def insert_files(self, files: list[File]): | ||
session = self.Session() | ||
try: | ||
for file in files: | ||
# check file does not already exist | ||
existing_file = ( | ||
session.query(File) | ||
.filter_by(name=file.name, path=file.path) | ||
.first() | ||
) | ||
if existing_file is not None: | ||
continue | ||
|
||
session.add(file) | ||
|
||
session.commit() | ||
except Exception as e: | ||
session.rollback() | ||
raise e | ||
finally: | ||
session.close() |
Oops, something went wrong.