Simplify date parsing (#195)
Create common functions parse_date, parse_month_year_date and parse_datetime. Those functions support trying multiple formats, and come with default formats lists that support most of the date format encountered so far. Notable change: year-month dates are now set to the end of month (impacted couchbase-server and ibm-aix).
This commit is contained in:
13
src/cgit.py
13
src/cgit.py
@@ -1,8 +1,8 @@
|
||||
import re
|
||||
import sys
|
||||
from bs4 import BeautifulSoup
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
from datetime import datetime, timezone
|
||||
from liquid import Template
|
||||
|
||||
"""Fetch versions with their dates from a cgit repository, such as
|
||||
@@ -22,15 +22,6 @@ DEFAULT_VERSION_REGEX = (
|
||||
)
|
||||
|
||||
|
||||
# Parse date with format 2023-05-01 08:32:34 +0900 and convert to UTC
|
||||
def parse_date(d):
|
||||
return (
|
||||
datetime.strptime(d, "%Y-%m-%d %H:%M:%S %z")
|
||||
.astimezone(timezone.utc)
|
||||
.strftime("%Y-%m-%d")
|
||||
)
|
||||
|
||||
|
||||
def make_bs_request(url):
|
||||
response = endoflife.fetch_url(url + '/refs/tags')
|
||||
return BeautifulSoup(response, features="html5lib")
|
||||
@@ -54,7 +45,7 @@ def fetch_releases(url, regex, template):
|
||||
if matches:
|
||||
match_data = matches.groupdict()
|
||||
version_string = l_template.render(**match_data)
|
||||
date = parse_date(datetime_text)
|
||||
date = dates.parse_datetime(datetime_text).strftime("%Y-%m-%d")
|
||||
print(f"{version_string} : {date}")
|
||||
releases[version_string] = date
|
||||
|
||||
|
||||
Reference in New Issue
Block a user