2007-07-24 Don Allingham <don@gramps-project.org>
* src/plugins/ExtractCity.py: fix regular expression matching svn: r8772
This commit is contained in:
parent
0e5034050a
commit
fe13b9775b
@ -1,3 +1,6 @@
|
|||||||
|
2007-07-24 Don Allingham <don@gramps-project.org>
|
||||||
|
* src/plugins/ExtractCity.py: fix regular expression matching
|
||||||
|
|
||||||
2007-07-24 Doug Blank <dblank@cs.brynmawr.edu>
|
2007-07-24 Doug Blank <dblank@cs.brynmawr.edu>
|
||||||
* src/Mime/_PythonMime.py: Add CSV mime type
|
* src/Mime/_PythonMime.py: Add CSV mime type
|
||||||
* src/plugins/ImportCSV.py: Added
|
* src/plugins/ImportCSV.py: Added
|
||||||
|
@ -51,7 +51,9 @@ import GrampsDisplay
|
|||||||
from PluginUtils import Tool, register_tool
|
from PluginUtils import Tool, register_tool
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
CITY_STATE = re.compile("^(.+),\s*([\w\s\.]+),?\s*([\d-])?")
|
CITY_STATE_ZIP = re.compile("((\w|\s)+)\s*,\s*((\w|\s)+)\s*(,\s*((\d|-)+))")
|
||||||
|
CITY_STATE = re.compile("((\w|\s)+)\s*,\s*((\w|\s)+)")
|
||||||
|
STATE_ZIP = re.compile("(.+)\s+([\d-]+)")
|
||||||
|
|
||||||
COUNTRY = ( _(u"United States of America"), _(u"Canada"), _(u"France"))
|
COUNTRY = ( _(u"United States of America"), _(u"Canada"), _(u"France"))
|
||||||
|
|
||||||
@ -333,7 +335,7 @@ STATE_MAP = {
|
|||||||
u"RHONE-ALPES" : (u"Rhône-Alpes", 2),
|
u"RHONE-ALPES" : (u"Rhône-Alpes", 2),
|
||||||
u"RAL" : (u"RAL-Rhône-Alpes", 2),
|
u"RAL" : (u"RAL-Rhône-Alpes", 2),
|
||||||
u"AOM" : (u"AOM-Autres Territoires d'Outre-Mer", 2),
|
u"AOM" : (u"AOM-Autres Territoires d'Outre-Mer", 2),
|
||||||
u"COM" : (u"DOM-Collectivité Territoriale d'Outre-Mer", 2),
|
u"COM" : (u"COM-Collectivité Territoriale d'Outre-Mer", 2),
|
||||||
u"DOM" : (u"DOM-Départements d'Outre-Mer", 2),
|
u"DOM" : (u"DOM-Départements d'Outre-Mer", 2),
|
||||||
u"TOM" : (u"TOM-Territoires d'Outre-Mer", 2),
|
u"TOM" : (u"TOM-Territoires d'Outre-Mer", 2),
|
||||||
}
|
}
|
||||||
@ -396,9 +398,14 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
|||||||
if loc.get_street() == "" and loc.get_city() == "" \
|
if loc.get_street() == "" and loc.get_city() == "" \
|
||||||
and loc.get_state() == "" and \
|
and loc.get_state() == "" and \
|
||||||
loc.get_postal_code() == "":
|
loc.get_postal_code() == "":
|
||||||
match = CITY_STATE.match(descr.strip())
|
|
||||||
|
match = CITY_STATE_ZIP.match(descr.strip())
|
||||||
if match:
|
if match:
|
||||||
(city, state, postal) = match.groups()
|
data = match.groups()
|
||||||
|
city = data[0]
|
||||||
|
state = data[2]
|
||||||
|
postal = data[5]
|
||||||
|
|
||||||
val = " ".join(state.strip().split()).upper()
|
val = " ".join(state.strip().split()).upper()
|
||||||
if state:
|
if state:
|
||||||
new_state = STATE_MAP.get(val.upper())
|
new_state = STATE_MAP.get(val.upper())
|
||||||
@ -406,7 +413,29 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
|||||||
self.name_list.append(
|
self.name_list.append(
|
||||||
(handle, (city, new_state[0], postal,
|
(handle, (city, new_state[0], postal,
|
||||||
COUNTRY[new_state[1]])))
|
COUNTRY[new_state[1]])))
|
||||||
else:
|
continue
|
||||||
|
|
||||||
|
match = CITY_STATE.match(descr.strip())
|
||||||
|
if match:
|
||||||
|
data = match.groups()
|
||||||
|
city = data[0]
|
||||||
|
state = data[2]
|
||||||
|
postal = None
|
||||||
|
|
||||||
|
if state:
|
||||||
|
m0 = STATE_ZIP.match(state)
|
||||||
|
if m0:
|
||||||
|
(state, postal) = m0.groups()
|
||||||
|
|
||||||
|
val = " ".join(state.strip().split()).upper()
|
||||||
|
if state:
|
||||||
|
new_state = STATE_MAP.get(val.upper())
|
||||||
|
if new_state:
|
||||||
|
self.name_list.append(
|
||||||
|
(handle, (city, new_state[0], postal,
|
||||||
|
COUNTRY[new_state[1]])))
|
||||||
|
continue
|
||||||
|
|
||||||
val = " ".join(descr.strip().split()).upper()
|
val = " ".join(descr.strip().split()).upper()
|
||||||
new_state = STATE_MAP.get(val)
|
new_state = STATE_MAP.get(val)
|
||||||
if new_state:
|
if new_state:
|
||||||
@ -519,7 +548,7 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
|||||||
if state:
|
if state:
|
||||||
place.get_main_location().set_state(state)
|
place.get_main_location().set_state(state)
|
||||||
if postal:
|
if postal:
|
||||||
place.get_main_location().set_postal(postal)
|
place.get_main_location().set_postal_code(postal)
|
||||||
if country:
|
if country:
|
||||||
place.get_main_location().set_country(country)
|
place.get_main_location().set_country(country)
|
||||||
self.db.commit_place(place, self.trans)
|
self.db.commit_place(place, self.trans)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user