Created
May 8, 2020 11:54
-
-
Save JoeThunyathep/663a580d09988303b385a224b523c177 to your computer and use it in GitHub Desktop.
Lambda function for scraping COVID-19 data and save to S3 bucket
This file contains hidden or 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
import json | |
import boto3 | |
from covid19scraper import scrapeGlobalCase | |
def lambda_handler(event, context): | |
s3 = boto3.resource('s3') | |
print ("[INFO] Request COVID-19 data...") | |
update_covid_cases = scrapeGlobalCase() | |
BUCKET_NAME = "hourlycovid19" | |
DATE = f"{update_covid_cases['date']}" | |
OUTPUT_NAME = f"dataKeyTest{DATE}.json" | |
OUTPUT_BODY = json.dumps(update_covid_cases) | |
print (f"[INFO] Saving Data to S3 {BUCKET_NAME} Bucket...") | |
s3.Bucket(BUCKET_NAME).put_object(Key=OUTPUT_NAME, Body=OUTPUT_BODY) | |
print (f"[INFO] Job done at {DATE}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment