-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from CityOfPhiladelphia/oracle-write-4-2024
2 new oracle functions, reload table from CSV in one transaction. Or append to existing table from CSV.
- Loading branch information
Showing
4 changed files
with
159 additions
and
4 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ame: Build and test docker image only for PRs | ||
name: Build and test docker image only for PRs | ||
|
||
on: | ||
pull_request: | ||
|
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,31 @@ | ||
import boto3 | ||
|
||
def _interact_with_s3(self, method: str, path: str, s3_key: str): | ||
''' | ||
- method should be one of "get", "load" | ||
''' | ||
self.logger.info(f"{method.upper()}-ing file: s3://{self.s3_bucket}/{s3_key}") | ||
|
||
s3 = boto3.resource('s3') | ||
if method == 'get': | ||
s3.Object(self.s3_bucket, s3_key).download_file(path) | ||
self.logger.info(f'File successfully downloaded from S3 to {path}\n') | ||
elif method == 'load': | ||
s3.Object(self.s3_bucket, s3_key).put(Body=open(path, 'rb')) | ||
self.logger.info(f'File successfully uploaded from {path} to S3\n') | ||
|
||
def get_json_schema_from_s3(self): | ||
_interact_with_s3(self, 'get', self.json_schema_path, self.json_schema_s3_key) | ||
|
||
def get_csv_from_s3(self): | ||
_interact_with_s3(self, 'get', self.csv_path, self.s3_key) | ||
|
||
def load_json_schema_to_s3(self): | ||
with open(self.json_schema_path, 'w') as f: | ||
f.write(self.export_json_schema) | ||
|
||
_interact_with_s3(self, 'load', self.json_schema_path, self.json_schema_s3_key) | ||
|
||
def load_csv_to_s3(self, path): | ||
'''Path of file to load - generally should be self.csv_path''' | ||
_interact_with_s3(self, 'load', path, self.s3_key) |
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