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:
@@ -1,8 +1,8 @@
|
||||
import re
|
||||
import urllib.parse
|
||||
from bs4 import BeautifulSoup
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
from datetime import datetime
|
||||
|
||||
"""Fetch Firefox versions with their dates from https://www.mozilla.org/"""
|
||||
|
||||
@@ -12,13 +12,7 @@ PRODUCT = "firefox"
|
||||
|
||||
def format_date(text: str) -> str:
|
||||
text = text.replace(')', '')
|
||||
formats = ["%b %d, %Y", "%B %d, %Y"]
|
||||
for f in formats:
|
||||
try:
|
||||
return datetime.strptime(text, f).strftime("%Y-%m-%d")
|
||||
except ValueError:
|
||||
pass
|
||||
return ""
|
||||
return dates.parse_date(text).strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
print(f"::group::{PRODUCT}")
|
||||
|
||||
Reference in New Issue
Block a user