Skip to content

Commit

Permalink
okc_gov header fix incapsular + reformatting (#1306)
Browse files Browse the repository at this point in the history
Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
  • Loading branch information
5ila5 and 5ila5 authored Oct 6, 2023
1 parent 86e1327 commit 204eef0
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json
import requests

from datetime import datetime, timedelta

import requests
from waste_collection_schedule import Collection

TITLE = "City of Oklahoma City"
DESCRIPTION = (
"Source for okc.gov services for City of Oklahoma City"
)
DESCRIPTION = "Source for okc.gov services for City of Oklahoma City"
URL = "https://www.okc.gov"
COUNTRY = "us"
TEST_CASES = {
Expand All @@ -16,8 +14,10 @@
"Test_003": {"objectID": 1935340},
}
HEADERS = {
"content-type": "text/json",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0",
"user-agent": "Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:118.0) Gecko/20100101 Firefox/118.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en,en-GB;q=0.7,en-US;q=0.3",
"Upgrade-Insecure-Requests": "1",
}
ICON_MAP = {
"TRASH": "mdi:trash-can",
Expand All @@ -34,7 +34,7 @@ def fetch(self):

s = requests.Session()
r = s.get(
f"https://data.okc.gov/services/portal/api/data/records/Address%20Trash%20Services",
"https://data.okc.gov/services/portal/api/data/records/Address%20Trash%20Services",
params={"recordID": self._recordID},
headers=HEADERS,
)
Expand All @@ -46,12 +46,18 @@ def fetch(self):
else:
waste_types = []
# Build list of collection categories
for item in json_data["Fields"][3:-1]: # limit to those entries containing collection info
for item in json_data["Fields"][
3:-1
]: # limit to those entries containing collection info
waste_types.append(item["FieldName"].replace("Next_", "").split("_")[0])
# Build list of collection days/dates
waste_dates = []
action_day = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
for item in json_data["Records"][0][3:-1]:# limit to those entries containing collection info
action_day = datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0
)
for item in json_data["Records"][0][
3:-1
]: # limit to those entries containing collection info
if item != "Not Available": # ignore missing collections
if "day" in item: # convert day of week into next collection date
while action_day.strftime("%A") != item:
Expand Down

0 comments on commit 204eef0

Please sign in to comment.