Skip to content

Commit

Permalink
Merge pull request #15 from miztch/perf/sort-by-date
Browse files Browse the repository at this point in the history
Add startDate to the item attribute and use as sort key
  • Loading branch information
miztch committed Jun 13, 2024
2 parents d77aca8 + addb1a2 commit fd010d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions functions/sasha/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def scrape_match(match_url_path):
with_timezone = " ".join([start_time, "EST"])

tzinfo = {"EST": tz.gettz("America/New_York"), "CST": tz.gettz("America/Chicago")}
start_time_est = parse(with_timezone, tzinfos=tzinfo)
start_time_utc = start_time_est.astimezone(tz.gettz("Etc/GMT"))
start_time_utc = datetime.strftime(start_time_utc, "%Y-%m-%dT%H:%M:%S%z")
dt_start_time_est = parse(with_timezone, tzinfos=tzinfo)
dt_start_time_utc = dt_start_time_est.astimezone(tz.gettz("Etc/GMT"))
start_time_utc = datetime.strftime(dt_start_time_utc, "%Y-%m-%dT%H:%M:%S%z")
start_date_utc = datetime.strftime(dt_start_time_utc, "%Y-%m-%d")

teams = html.css(".wf-title-med")
teams = [t.text().replace("\t", "").replace("\n", "") for t in teams]
Expand All @@ -128,6 +129,7 @@ def scrape_match(match_url_path):

data = {
"match_id": match_id,
"start_date": start_date_utc,
"event_name": event_info["event_name"],
"event_country_flag": event_info["country_flag"],
"start_time": start_time_utc,
Expand Down Expand Up @@ -159,6 +161,7 @@ def scrape_matches(page: str = 1):

item = {
"id": match_detail["match_id"],
"startDate": match_detail["start_date"],
"eventName": match_detail["event_name"],
"eventCountryFlag": match_detail["event_country_flag"],
"startTime": match_detail["start_time"],
Expand Down
4 changes: 4 additions & 0 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ Resources:
AttributeDefinitions:
- AttributeName: id
AttributeType: N
- AttributeName: startDate
AttributeType: S
BillingMode: PROVISIONED
DeletionProtectionEnabled: True
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: startDate
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Expand Down

0 comments on commit fd010d6

Please sign in to comment.