Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

okc_gov header fix incapsular + reformatting #1306

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading