本文整理汇总了Python中Stream.Stream.stream方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.stream方法的具体用法?Python Stream.stream怎么用?Python Stream.stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream.Stream
的用法示例。
在下文中一共展示了Stream.stream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import stream [as 别名]
class Filter:
def __init__(self, inputFilePath, outputFilePath):
self.inclusionList = []
self.exclusionList = []
self.stream = Stream(inputFilePath, 'Letter')
self.new_shelve_file = outputFilePath
def inclusionListAdd(self, filterList):
self.inclusionList += filterList()
def exclusionListAdd(self, filterList):
self.exclusionList += filterList()
def filter(self):
with ShelveManager(self.new_shelve_file) as new_shelf:
for index, fields in self.stream.stream():
#print(str(index))
if str(index)+'.0' in self.inclusionList and str(index)+'.0' not in self.exclusionList:
new_shelf[index] = self._get_fields(fields)
@editLogger('Filtered from Completed List', 'PythonScript')
def _get_fields(self, fields):
return fields
示例2: run_templater
# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import stream [as 别名]
def run_templater(inputFile, outputDir, tmpF):
templateFile = open(tmpF).read()
env = jinja2.Environment()
env.globals.update(sorted=sorted, to_snake=to_snake_case)
template = env.from_string(templateFile)
s = Stream(inputFile, 'Letter')
# Dirty counter for well-formedness
wf = 0
bf = 0
for key, item in s.stream():
templatedText = template.render(item)
f = open(outputDir+key+".xml", 'w')
f.write(templatedText)
f.close()
# A dirty checker for wellformedness
try:
ET.fromstring(templatedText)
wf += 1
except Exception as e:
print(key, " is BAD:: ", e)
bf += 1
print('GOOD: ', wf)
print('BAD: ', bf)
示例3: getValuesFromFile
# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import stream [as 别名]
def getValuesFromFile(self):
stream = Stream(self.filePath, self.column, sheet="ID")
for k, v in stream.stream():
#print(k)
if k != 'None' and v["DATE"] < self.date:
yield str(k) + '.0'
示例4: getValuesFromFile
# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import stream [as 别名]
def getValuesFromFile(self):
stream = Stream(self.filePath, self.column, sheet="ID NUMBERS")
for k, v in stream.stream():
if k != 'None' and v['DATE'] < self.date:
yield str(k) + '.0'
示例5: run_templater
# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import stream [as 别名]
def run_templater(inputFile, outputDir, templateFilePath):#, templateFolder):
print(templateFilePath)
templateFile = open(templateFilePath).read()
editors = []
contributors = []
wf = 0
bf = 0
'''
letterPlainTemplateFile = open(templateFolder + 'letter_plain.xml').read()
letterEnvelopeTemplateFile = open(templateFolder + 'letter_envelope.xml').read()
postcardAMTemplateFile = open(templateFolder + 'postcard_am.xml').read()
postcardIMTemplateFile = open(templateFolder + 'postcard_im.xml').read()
'''
s = Stream(inputFile, 'Letter')
for key, item in s.stream():
print("Templating item: ", key, "-type ", item["Type"])
'''
if item["Type"] == 'Letter':
print(item["Pages"])
if [p for k, p in item["Pages"].items() if p["PageType"] == 'EnvelopeType']:
templateFile = letterEnvelopeTemplateFile
else:
templateFile = letterPlainTemplateFile
elif item["Type"] == 'PostcardAM':
templateFile = postcardAMTemplateFile
elif item["Type"] == 'PostcardIM':
templateFile = postcardIMTemplateFile
else:
templateFile = letterPlainTemplateFile
'''
item["ProcessingVersion"] = "2"
#print(len(item["Contributor_List"]), set(item["Contributor_List"]))
new_cont_list = []
item["Editors"] = []
with shelve.open('editorList.shelve') as editor_list:
for editor in item["Contributor_List"]:
if editor in editor_list and "Python" not in editor:
if editor_list[editor] != ("Susan Schreibman", "SS"):
item["Editors"].append(editor_list[editor])
elif editor != "NULL":
new_cont_list.append(editor)
item["Contributor_List"] = new_cont_list
#contributors += item["Contributor_List"]
template_log = {
'editType': 'TEI template built',
'editor': "PythonScript",
'datetime': str(datetime.datetime.now())[:-7].replace(" ", "T")}
item["Edits"].append(template_log)
item["Edits"] = sorted(item["Edits"], key=lambda f: datetime.datetime.strptime(f['datetime'], "%Y-%m-%dT%H:%M:%S"))
#print(templateFile)
env = jinja2.Environment()
env.globals.update(sorted=sorted, to_snake=to_snake_case,replace_contribs=replace_contrib_names,
abstract_split=abstract_split)
template = env.from_string(templateFile)
#print(item["DocCollection"])
#print(item["Document_Collection"],"~", item["Document_Number"])
#print(item["Letter"])
#for k, v in item.items():
# print(k, type(k), v)
if None in item:
del item[None]
templatedText = template.render(item)
f = open(outputDir+key+".xml", 'w')
#f = open("pagesList.xml", 'a')
f.write(templatedText)
f.close()
# A dirty checker for wellformedness
#.........这里部分代码省略.........