Fixed some bugs with regex
This commit is contained in:
parent
36a541eef0
commit
d1a4543a4f
14
fetch.py
14
fetch.py
@ -29,7 +29,7 @@ def runfetch(url='https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD18245
|
|||||||
|
|
||||||
|
|
||||||
def dms2dd(dms):
|
def dms2dd(dms):
|
||||||
coordslst = re.search("(\d{1,3})° (\d{2})(?:'|′) (\d{2},?\d{0,2})(?:\"|”|\'\')", dms).groups()
|
coordslst = re.search("(\d{1,3})° (\d{2})(?:'|′) (\d{2},?\d{0,3})(?:\"|”|\'\')", dms).groups()
|
||||||
dd = float(coordslst[0].replace(",", ".")) + float(coordslst[1].replace(",", "."))/60 + float(coordslst[2].replace(",", "."))/3600
|
dd = float(coordslst[0].replace(",", ".")) + float(coordslst[1].replace(",", "."))/60 + float(coordslst[2].replace(",", "."))/3600
|
||||||
return dd
|
return dd
|
||||||
|
|
||||||
@ -49,8 +49,9 @@ def fetch(url='https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD1824595A
|
|||||||
lst = []
|
lst = []
|
||||||
tmp = re.compile(".*zone.*").split(area["zone"]) # List of polygons
|
tmp = re.compile(".*zone.*").split(area["zone"]) # List of polygons
|
||||||
del tmp[0]
|
del tmp[0]
|
||||||
|
print(tmp)
|
||||||
for polygon in tmp:
|
for polygon in tmp:
|
||||||
lst.append(re.findall(".{0,35} ?:? ?.? ?: ?(\d{1,3}° \d{2}(?:'|′) \d{2},?\d{0,2}(?:\"|”) .) ?\/ ?(\d{1,3}° \d{2}(?:'|′) \d{2},?\d{0,2}(?:\"|”) .)", polygon))
|
lst.append(re.findall(".{0,35} ?:? ?.? ?: ?(\d{1,3}° \d{2}(?:'|′) \d{2},?\d{0,3}(?:\"|”|\'\') .) ?\/ ?(\d{1,3}° \d{2}(?:'|′|\'\') \d{2},?\d{0,3}(?:\"|”) .)", polygon))
|
||||||
area["zone"] = []
|
area["zone"] = []
|
||||||
for index, polygon in enumerate(lst):
|
for index, polygon in enumerate(lst):
|
||||||
area["zone"].append([])
|
area["zone"].append([])
|
||||||
@ -64,7 +65,7 @@ def fetch(url='https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD1824595A
|
|||||||
# Polygons
|
# Polygons
|
||||||
elif "polygone" in area["zone"]:
|
elif "polygone" in area["zone"]:
|
||||||
lst = []
|
lst = []
|
||||||
lst.append(re.findall(".{0,35} ?:? ?.? ?: ?(\d{1,3}° \d{2}(?:'|′) \d{2},?\d{0,2}(?:\"|”|\'\') ?.) ?\/ ?(\d{1,3}° \d{2}(?:'|′) \d{2},?\d{0,2}(?:\"|”|\'\') ?.)", area["zone"]))
|
lst.append(re.findall(".{0,35} ?:? ?.? ?: ?(\d{1,3}° \d{2}(?:'|′) \d{2},?\d{0,3}(?:\"|”|\'\') ?.) ?\/ ?(\d{1,3}° \d{2}(?:'|′|\'\') \d{2},?\d{0,3}(?:\"|”|\'\') ?.)", area["zone"]))
|
||||||
area["zone"] = []
|
area["zone"] = []
|
||||||
for index, polygon in enumerate(lst):
|
for index, polygon in enumerate(lst):
|
||||||
area["zone"].append([])
|
area["zone"].append([])
|
||||||
@ -93,8 +94,7 @@ if __name__ == '__main__':
|
|||||||
# Print the dict (keep this code in the end of the file)
|
# Print the dict (keep this code in the end of the file)
|
||||||
print("===== Dict =====")
|
print("===== Dict =====")
|
||||||
for index, area in enumerate(diclist):
|
for index, area in enumerate(diclist):
|
||||||
if index == 30:
|
print(f"\n-------------{index}----------------\n")
|
||||||
print(f"\n-------------{index}----------------\n")
|
for element in area:
|
||||||
for element in area:
|
print(f" {element}: {diclist[index][element]}")
|
||||||
print(f" {element}: {diclist[index][element]}")
|
|
||||||
print("\n")
|
print("\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user