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