Skip to content

Commit

Permalink
Use default session, add some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
cal4 committed Aug 23, 2024
1 parent fe24e58 commit 92dcfb5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def getGoogleTrends(self, wordsCount: int) -> list[str]:
f"https://trends.google.com/trends/api/dailytrends?hl={self.browser.localeLang}"
f'&ed={(date.today() - timedelta(days=i)).strftime("%Y%m%d")}&geo={self.browser.localeGeo}&ns=15'
)
assert r.status_code == requests.codes.ok
assert r.status_code == requests.codes.ok # todo Add guidance if assertion fails
trends = json.loads(r.text[6:])
for topic in trends["default"]["trendingSearchesDays"][0][
"trendingSearches"
Expand All @@ -113,10 +113,10 @@ def getGoogleTrends(self, wordsCount: int) -> list[str]:

def getRelatedTerms(self, term: str) -> list[str]:
# Function to retrieve related terms from Bing API
relatedTerms: list[str] = requests.get(
relatedTerms: list[str] = Utils.makeRequestsSession().get(
f"https://api.bing.com/osjson.aspx?query={term}",
headers={"User-agent": self.browser.userAgent},
).json()[1]
).json()[1] # todo Wrap if failed, or assert response?
if not relatedTerms:
return [term]
return relatedTerms
Expand Down

0 comments on commit 92dcfb5

Please sign in to comment.