Skip to content

Commit

Permalink
Add pydantic settings for scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
keanrawr committed Aug 6, 2023
1 parent ca368c8 commit c09e6bf
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 7 deletions.
9 changes: 6 additions & 3 deletions get_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import logging
from lol_matches.s3 import S3Helper
from lol_matches.scraper import MatchScraper
from lol_matches.settings import ScraperSettings

settings = ScraperSettings()


def create_objects(region):
bucket_name = os.getenv('S3_BUCKET_NAME')
bucket_name = settings.s3_bucket_name
s3 = S3Helper(bucket_name, region)
scraper = MatchScraper(region)
logging.info('Instanciated scraper and s3 objects')
Expand All @@ -14,7 +17,7 @@ def create_objects(region):


def scrape_match(match_id, scraper, s3):
logging.info(f'Starting scraping match: {match_id}')
logging.info(f'Starting scraping match: {match_id}')
match = scraper.get_match(match_id)

logging.info(f'Parsing data for match: {match_id}')
Expand All @@ -33,7 +36,7 @@ def main():
logging.basicConfig(filename='log/get-matches.log', format='%(asctime)s %(levelname)s:%(message)s',
level=logging.INFO)
region = 'europe'
init_match_id = 5733866851
init_match_id = 6510066852
match_id = init_match_id

s3, scraper = create_objects(region)
Expand Down
6 changes: 4 additions & 2 deletions lol_matches/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import boto3
from pathlib import Path
from traceback import print_exc
from lol_matches.settings import ScraperSettings


class S3Helper:
def __init__(self, bucket, lol_region:str=None) -> None:
settings = ScraperSettings()
self.client = boto3.client(
's3',
aws_access_key_id=os.getenv('S3_ACCESS_KEY'),
aws_secret_access_key=os.getenv('S3_SECRET_ACCESS_KEY'),
aws_access_key_id=settings.s3_access_key,
aws_secret_access_key=settings.s3_secret_access_key,
)
self.bucket = bucket
if lol_region is None:
Expand Down
11 changes: 11 additions & 0 deletions lol_matches/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pydantic_settings import BaseSettings
from pydantic_settings import SettingsConfigDict

class ScraperSettings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")

riot_api_key: str

s3_bucket_name: str
s3_access_key: str
s3_secret_access_key: str
Loading

0 comments on commit c09e6bf

Please sign in to comment.