Skip to content

Commit

Permalink
Merge pull request #33 from route1io/feature-s3-to-onedrive
Browse files Browse the repository at this point in the history
Feature s3 to OneDrive
  • Loading branch information
chris-greening authored Jun 29, 2022
2 parents 36d72a4 + 4db1dc4 commit 3e3ebf2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions route1io_connectors/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
AWS SDK for Python (Boto3)
https://aws.amazon.com/sdk-for-python/
"""
import tempfile
from typing import Union, Sequence, Dict, Tuple, List
from pathlib import Path

import boto3

from . import onedrive

FilenameVar = Union[str, Sequence[Union[str, None]]]

def get_most_recent_filename(s3, bucket: str, prefix: str = "") -> str:
Expand Down Expand Up @@ -114,6 +117,26 @@ def download_from_s3(s3, bucket: str, key: str, filename: str = None) -> List[st
)
return list(filename_to_key_map.values())

def copy_object_to_onedrive(s3, bucket: str, key: str, access_token: str, url: str) -> None:
"""Copy object from S3 bucket to OneDrive at given URL
Parameters
----------
s3
Valid S3 connection created using aws.connect_to_s3
bucket : str
Existing bucket on AWS
key : str
Key name of the file as it will appear in S3
access_token : str
Valid access token for accessing OneDrive
url : str
URL of the file on OneDrive or SharePoint
"""
with tempfile.NamedTemporaryFile("wb+") as outfile:
download_from_s3(s3=s3, bucket=bucket, key=key, filename=outfile.name)
onedrive.upload_file(access_token, url, fpath=outfile.name)

def _create_filename_key_map(filename: FilenameVar,
key: FilenameVar,
filename_required: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="route1io-connectors",
version="0.12.2",
version="0.13.0",
description="Connectors for interacting with popular API's used in marketing analytics using clean and concise Python code.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 3e3ebf2

Please sign in to comment.