Created
July 5, 2022 11:10
-
-
Save dimitryzub/142ed4d380bf001da155267e6d9dc2d6 to your computer and use it in GitHub Desktop.
#AskSerpApi: "When using sport results API, what timezone do you guys use? The time and date responses are changing."
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AskSerpApi video: https://www.youtube.com/watch?v=c26LgucCqDo | |
from dateutil import parser | |
from serpapi import GoogleSearch | |
params = { | |
"api_key": "your serpapi api key", | |
"engine": "google", | |
"q": "liverpool", | |
"google_domain": "google.co.uk", | |
"gl": "uk", | |
"hl": "en", | |
"location": "United Kingdom" | |
} | |
search = GoogleSearch(params) | |
results = search.get_dict() | |
for game_result in results["sports_results"]["games"]: | |
parsed_time = parser.parse(game_result["date"]) | |
print(parsed_time.strftime("%Y-%m-%d %H:%M:%S")) | |
# time_formats = [ | |
# "12/31/1991", | |
# "December 10, 1980", | |
# "September 25, 1970", | |
# "2005-11-14", | |
# "December 1990", | |
# "October 12, 2005", | |
# "1993-06-26", | |
# "11/20/1967 6:08:15 PM", | |
# "28 May", | |
# "18 June, 13:35", | |
# "8 Jan, 8:35 AM", | |
# "8 Jan, 2019, 8:35 AM", | |
# "Tue, 12 Jul", | |
# "27/07/2022", # 27/7 would not work | |
# ] | |
# for time in time_formats: | |
# d = parser.parse(time) | |
# print(d.strftime("%Y-%m-%d %H:%M:%S")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment