Use raw strings for regular expressions
Python 3.12 requires raw strings for many character sequences used in regular expressions. Originally submitted by Piraty, thanks!
This commit is contained in:
12
weather.py
12
weather.py
@@ -130,7 +130,7 @@ def filter_units(line, units="imperial"):
|
|||||||
# filter lines with both pressures in the form of "X inches (Y hPa)" or
|
# filter lines with both pressures in the form of "X inches (Y hPa)" or
|
||||||
# "X in. Hg (Y hPa)"
|
# "X in. Hg (Y hPa)"
|
||||||
dual_p = re.match(
|
dual_p = re.match(
|
||||||
"(.* )(\d*(\.\d+)? (inches|in\. Hg)) \((\d*(\.\d+)? hPa)\)(.*)",
|
r"(.* )(\d*(\.\d+)? (inches|in\. Hg)) \((\d*(\.\d+)? hPa)\)(.*)",
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
if dual_p:
|
if dual_p:
|
||||||
@@ -139,7 +139,7 @@ def filter_units(line, units="imperial"):
|
|||||||
elif units == "metric": line = preamble + hpa + trailer
|
elif units == "metric": line = preamble + hpa + trailer
|
||||||
# filter lines with both temperatures in the form of "X F (Y C)"
|
# filter lines with both temperatures in the form of "X F (Y C)"
|
||||||
dual_t = re.match(
|
dual_t = re.match(
|
||||||
"(.* )(-?\d*(\.\d+)? F) \((-?\d*(\.\d+)? C)\)(.*)",
|
r"(.* )(-?\d*(\.\d+)? F) \((-?\d*(\.\d+)? C)\)(.*)",
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
if dual_t:
|
if dual_t:
|
||||||
@@ -150,7 +150,7 @@ def filter_units(line, units="imperial"):
|
|||||||
# "Y kilometer(s)"
|
# "Y kilometer(s)"
|
||||||
if units == "metric":
|
if units == "metric":
|
||||||
imperial_d = re.match(
|
imperial_d = re.match(
|
||||||
"(.* )(\d+)( mile\(s\))(.*)",
|
r"(.* )(\d+)( mile\(s\))(.*)",
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
if imperial_d:
|
if imperial_d:
|
||||||
@@ -160,7 +160,7 @@ def filter_units(line, units="imperial"):
|
|||||||
# filter speeds in the form of "X MPH (Y KT)" to just "X MPH"; if metric is
|
# filter speeds in the form of "X MPH (Y KT)" to just "X MPH"; if metric is
|
||||||
# desired, convert to "Z KPH"
|
# desired, convert to "Z KPH"
|
||||||
imperial_s = re.match(
|
imperial_s = re.match(
|
||||||
"(.* )(\d+)( MPH)( \(\d+ KT\))(.*)",
|
r"(.* )(\d+)( MPH)( \(\d+ KT\))(.*)",
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
if imperial_s:
|
if imperial_s:
|
||||||
@@ -170,7 +170,7 @@ def filter_units(line, units="imperial"):
|
|||||||
line = preamble + str(int(round(int(mph)*1.609344))) + " KPH" + \
|
line = preamble + str(int(round(int(mph)*1.609344))) + " KPH" + \
|
||||||
trailer
|
trailer
|
||||||
imperial_s = re.match(
|
imperial_s = re.match(
|
||||||
"(.* )(\d+)( MPH)( \(\d+ KT\))(.*)",
|
r"(.* )(\d+)( MPH)( \(\d+ KT\))(.*)",
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
if imperial_s:
|
if imperial_s:
|
||||||
@@ -182,7 +182,7 @@ def filter_units(line, units="imperial"):
|
|||||||
# if imperial is desired, qualify given forcast temperatures like "X F"; if
|
# if imperial is desired, qualify given forcast temperatures like "X F"; if
|
||||||
# metric is desired, convert to "Y C"
|
# metric is desired, convert to "Y C"
|
||||||
imperial_t = re.match(
|
imperial_t = re.match(
|
||||||
"(.* )(High |high |Low |low )(\d+)(\.|,)(.*)",
|
r"(.* )(High |high |Low |low )(\d+)(\.|,)(.*)",
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
if imperial_t:
|
if imperial_t:
|
||||||
|
|||||||
Reference in New Issue
Block a user