Last active
December 20, 2015 23:18
-
-
Save l34marr/6210935 to your computer and use it in GitHub Desktop.
bin/plonectl run my-script.py
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 | |
folder = site.myfolder['some-folder'] | |
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() | |
setSite(site) | |
site.setupCurrentSkin(site.REQUEST) | |
import transaction | |
import DateTime | |
list = ['my-id', 'My Title', 'Some Keyword', 'http://tw.pycon.org/'] | |
_id = list[0] | |
_id = folder.invokeFactory(type_name="Document", id=_id) | |
obj = folder[_id] | |
obj.edit( | |
title = list[1], | |
subject = list[2], | |
text = '<p><a class="external-link" href="'+list[3]+'" target="_blank">PyCon Taiwan</a></p>', | |
) | |
obj._renameAfterCreation(check_auto_id=True) | |
transaction.commit() |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
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
"她將要生一個兒子,你要給他取名叫耶穌,因為他將拯救他的子民脫離他們的罪。";"馬太福音1:21";"new";"27" | |
"這一切事的發生是要應驗主藉著先知所說的話:「有童女將懷孕生子,他的名字要叫以馬內利。」(「以馬內利」的意思就是「上帝與我們同在」。)";"馬太福音1:22-23";"new";"28" | |
"猶大地區的伯利恆啊,你在猶大諸城邑中並不是最小的;因為有一位領袖要從你那裏出來,他要牧養我的子民以色列。";"馬太福音2:6";"new";"29" | |
"這事應驗了先知耶利米所說:在拉瑪聽見了號咷大哭的聲音。蕾潔為著孩子們哀哭,不肯接受安慰,因為他們都死了。";"馬太福音2:17-18";"new";"30" | |
"斧頭已經擱在樹根上了,凡不結好果子的樹都要砍掉,丟在火裏。";"馬太福音3:10";"";"31" | |
"我用水給你們施洗,表示你們已經悔改;但是,在我以後來的那一位要用聖靈和火給你們施洗。他比我偉大多了,我就是替他提鞋子也不配。";"馬太福音3:11";"";"32" | |
"耶穌一受了洗,從水裏出來,天為他開了;他看見上帝的靈好像鴿子降下來,落在他身上。接著,從天上有聲音說:「這是我親愛的兒子,我喜愛他。」";"馬太福音3:16-17";"";"33" | |
"那試探者上前對他說:「既然你是上帝的兒子,命令這些石頭變成麵包吧!」耶穌回答:「聖經說:『人的生存不僅是靠食物,而是靠上帝所說的每一句話。』";"馬太福音4:3-4";;"34" | |
"西布倫地和拿弗他利地,沿海的路,約旦河的那邊,外邦人的加利利!住在黑暗中的人要看見大光;住在死蔭之地的人有光要照亮他們。";"馬太福音4:15-16";"new";"35" | |
"耶穌對他們說:「來跟從我!我要使你們成為得人的漁夫。」 他們立刻丟下了魚網,跟從耶穌。";"馬太福音4:19-20";"new";"36" |
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() | |
setSite(site) | |
site.setupCurrentSkin(site.REQUEST) | |
folder = site['quotes'] | |
import csv | |
from plone.dexterity.utils import createContentInContainer | |
with open('quote.csv', 'rb') as f: | |
dialect = csv.Sniffer().sniff(f.read(1024), delimiters=";") | |
f.seek(0) | |
reader = csv.reader(f, dialect) | |
for row in reader: | |
item = createContentInContainer(folder, 'cnc.Quote', title=row[0], description=row[1], testament=row[2], checkConstraints=False) | |
folder.manage_renameObject(item.getId(), str(row[3])) | |
import transaction | |
transaction.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment