Last active
August 29, 2015 14:04
-
-
Save l34marr/5f700b977df4046c1a1c to your computer and use it in GitHub Desktop.
Check and Update Address from PostgreSQL to ZODB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Testing import makerequest | |
root = makerequest.makerequest(app) | |
site = root.mysite | |
admin = root.acl_users.getUserById('admin') | |
admin = admin.__of__(site.acl_users) | |
from AccessControl.SecurityManagement import newSecurityManager | |
newSecurityManager(None, admin) | |
from zope.site.hooks import setHooks | |
from zope.site.hooks import setSite | |
setHooks() | |
site.setupCurrentSkin(site.REQUEST) | |
setSite(site) | |
from Products.CMFCore.utils import getToolByName | |
catalog = getToolByName(site, 'portal_catalog') | |
path = '/mysite/myfolder' | |
import csv | |
with open('/home/marr/address-update/from-pgsql.csv', 'rb') as f: | |
f.seek(0) | |
reader = csv.reader(f) | |
for row in reader: | |
query = { | |
'id': row[0], | |
'path': path, | |
} | |
brain = catalog.unrestrictedSearchResults(query) | |
if len(brain) != 1: | |
print "not 1to1: %s" % row[0] | |
continue | |
try: | |
obj = brain[0]._unrestrictedGetObject() | |
if row[1] == '' and obj.getAddress() != '': | |
print "empty addr: %s" % row[0] | |
continue | |
obj.setAddress(row[1]) | |
print "ok: %s" % row[0] | |
except: | |
print "obj error: %s" % row[0] | |
import transaction | |
transaction.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment