mirror of
https://github.com/SocksPls/hltv-api
synced 2025-06-28 00:19:49 +00:00
chore(main): datetime impl for get_matches
This commit is contained in:
parent
1c7cebf512
commit
d06f379a32
1 changed files with 11 additions and 8 deletions
19
main.py
19
main.py
|
@ -178,18 +178,19 @@ def get_matches():
|
||||||
for getMatch in matchDetails:
|
for getMatch in matchDetails:
|
||||||
matchObj = {}
|
matchObj = {}
|
||||||
|
|
||||||
matchObj['date'] = date
|
|
||||||
matchObj['url'] = "https://hltv.org" + getMatch.find("a", {"class": "match a-reset"}).get("href")
|
matchObj['url'] = "https://hltv.org" + getMatch.find("a", {"class": "match a-reset"}).get("href")
|
||||||
matchObj['time'] = getMatch.find("div", {"class": "matchTime"}).text
|
|
||||||
|
|
||||||
if (matchObj['date'] and matchObj['time']):
|
if (date and getMatch.find("div", {"class": "matchTime"})):
|
||||||
|
timeFromHLTV = datetime.datetime.strptime(date + " " + getMatch.find("div", {"class": "matchTime"}).text,'%Y-%m-%d %H:%M')
|
||||||
|
matchObj['date'] = timeFromHLTV.strftime('%Y-%m-%d')
|
||||||
|
matchObj['time'] = timeFromHLTV.strftime('%H:%M')
|
||||||
timenow = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
|
timenow = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||||
deadline = matchObj["date"] + " " + matchObj["time"]
|
deadline = date + " " + getMatch.find("div", {"class": "matchTime"}).text
|
||||||
start = datetime.datetime.strptime(timenow,'%Y-%m-%d %H:%M')
|
currentTime = datetime.datetime.strptime(timenow,'%Y-%m-%d %H:%M')
|
||||||
ends = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M')
|
ends = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M')
|
||||||
|
|
||||||
if start < ends:
|
if currentTime < ends:
|
||||||
matchObj['countdown'] = str(ends - start)
|
matchObj['countdown'] = str(ends - currentTime)
|
||||||
|
|
||||||
if getMatch.find("div", {"class": "matchEvent"}):
|
if getMatch.find("div", {"class": "matchEvent"}):
|
||||||
matchObj['event'] = getMatch.find("div", {"class": "matchEvent"}).text.encode('utf8').strip()
|
matchObj['event'] = getMatch.find("div", {"class": "matchEvent"}).text.encode('utf8').strip()
|
||||||
|
@ -224,10 +225,12 @@ def get_results():
|
||||||
|
|
||||||
if (res.parent.find("span", {"class": "standard-headline"})):
|
if (res.parent.find("span", {"class": "standard-headline"})):
|
||||||
dateText = res.parent.find("span", {"class": "standard-headline"}).text.replace("Results for ", "").replace("th", "")
|
dateText = res.parent.find("span", {"class": "standard-headline"}).text.replace("Results for ", "").replace("th", "")
|
||||||
|
|
||||||
dateArr = dateText.split()
|
dateArr = dateText.split()
|
||||||
|
|
||||||
dateTextFromArrPadded = padIfNeeded(dateArr[2]) + "-" + padIfNeeded(monthNameToNumber(dateArr[0])) + "-" + padIfNeeded(dateArr[1])
|
dateTextFromArrPadded = padIfNeeded(dateArr[2]) + "-" + padIfNeeded(monthNameToNumber(dateArr[0])) + "-" + padIfNeeded(dateArr[1])
|
||||||
resultObj['date'] = dateTextFromArrPadded.encode('utf8')
|
timeFromHLTV = datetime.datetime.strptime(dateTextFromArrPadded,'%Y-%m-%d')
|
||||||
|
resultObj['date'] = timeFromHLTV.strftime('%Y-%m-%d')
|
||||||
else:
|
else:
|
||||||
dt = datetime.date.today()
|
dt = datetime.date.today()
|
||||||
resultObj['date'] = str(dt.day) + '/' + str(dt.month) + '/' + str(dt.year)
|
resultObj['date'] = str(dt.day) + '/' + str(dt.month) + '/' + str(dt.year)
|
||||||
|
|
Loading…
Add table
Reference in a new issue