Last active
May 19, 2019 11:50
-
-
Save iKalin/f75a6e2ca3f26caa1cbcdc5fa011a301 to your computer and use it in GitHub Desktop.
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 is library named utils.py | |
# in this article's example it will be imported | |
# import our dependencies | |
import boto3 # boto3 is an AWS SDK; the only library that needs installation | |
import urllib # urllib for http requests | |
import shutil # file and folder operations library | |
import re # regex library | |
def s3_upload(file_to_push, s3_path, bucket): | |
s3 = boto3.resource('s3') | |
s3.meta.client.upload_file(file_to_push, bucket, s3_path) | |
def s3_download(bucket, to_pull, where_to_put): | |
s3 = boto3.resource('s3') | |
s3.Bucket(bucket).download_file(to_pull, where_to_put) | |
def open_file(path): | |
with open(path, 'r') as f: | |
return f.readlines() | |
def url_content(url): | |
with urllib.request.urlopen(url) as f: | |
return f.read().decode() | |
def string_match(to_match, data): | |
for line in data.splitlines(): | |
match = re.search(to_match, line, re.IGNORECASE) | |
if match: | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment