summaryrefslogtreecommitdiff
path: root/archaeological_operations/import_from_csv.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-05-07 19:22:23 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-05-07 19:22:23 +0200
commitc5cff744df1ee138ddf77fc2b683e4f252b77ad5 (patch)
treea5449faaaf5e6b034152fcaea7fcb23165f76947 /archaeological_operations/import_from_csv.py
parent31c3a9a2e17db368a54e570eb1a2982b29849484 (diff)
downloadIshtar-c5cff744df1ee138ddf77fc2b683e4f252b77ad5.tar.bz2
Ishtar-c5cff744df1ee138ddf77fc2b683e4f252b77ad5.zip
First work on parcel imports
Diffstat (limited to 'archaeological_operations/import_from_csv.py')
-rw-r--r--archaeological_operations/import_from_csv.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/archaeological_operations/import_from_csv.py b/archaeological_operations/import_from_csv.py
index 9d3a58ffd..e61596b00 100644
--- a/archaeological_operations/import_from_csv.py
+++ b/archaeological_operations/import_from_csv.py
@@ -410,6 +410,43 @@ def parse_rapp_index(value):
if items:
return int(items[-1])
+PARCEL_YEAR_REGEXP = re.compile(r"^([0-9]{4})[ :]+")
+
+PARCEL_SECTION_REGEXP = re.compile(r"([A-Z0-9]{1,3})[ :]+ *(([0-9]+[a-z]?[ ,à]*[et]*)+)")
+PARCEL_NB_REGEXP = re.compile(r'([0-9]+[a-z]?)[ ,à]*[et]*')
+
+def parse_parcels(insee_code, parcel_str, owner):
+ parcels = []
+ town = parse_insee(insee_code)
+ # manage only one town at a time
+ assert len(town) < 2
+ if not town:
+ return parcels
+ town = town[0]
+ parcel_values = {}
+ m = PARCEL_YEAR_REGEXP.match(parcel_str)
+ year = None
+ if m:
+ year = m.groups()[0]
+ parcel_str = parcel_str[m.span()[1]:]
+ parcel_values[year] = []
+ parcels_str = [parcel_str]
+ if ';' in parcel_str:
+ parcels_str = parcel_str.split(';')
+ if '/' in parcel_str:
+ parcels_str = parcel_str.split('/')
+ for parcel_str in parcels_str:
+ m = PARCEL_SECTION_REGEXP.match(parcel_str)
+ while m:
+ gp = m.groups()
+ sector, nums = gp[0], gp[1]
+ for num in PARCEL_NB_REGEXP.findall(nums):
+ parcel_values[year].append((sector, num))
+ parcel_str = parcel_str[m.span()[1]:]
+ m = PARCEL_SECTION_REGEXP.match(parcel_str)
+ print parcel_values
+ return parcels
+
_CACHED_DOC_TYPES = {}
def parse_doc_types(value):
@@ -479,7 +516,8 @@ def ope_postimportfix(ope, dct):
return ope
class RelatedClass:
- def __init__(self, key, cls, default_data={}, reverse_key=False, unique_keys=[]):
+ def __init__(self, key, cls, default_data={}, reverse_key=False,
+ unique_keys=[]):
self.key, self.cls, self.default_data = key, cls, default_data
self.reverse_key, self.unique_keys = reverse_key, unique_keys