2016-10-02 15 views
0

考虑到OmniFocus中没有一个API,我已经创建了一个拉的OmniFocus数据是XML格式的经常性的基础如何解析Omnifocus XML数据以获取有关特定任务的详细信息?

See linked here for the full omnifocus data set

我想我最好的解析这个数据集上的脚本这样我就可以得到这些属性对于一个名为任务“这是一个测试任务”

我想从XML数据

  • 任务名称提取此任务以下属性:“这是一个 测试任务 “
  • 完成日期: ”2016年10月2日“
  • 上架日期: ”2016年10月2日“
  • 项目: ”测试项目“
  • 截止日期:” 2016年10月11日“
  • 时间:10分钟

见下面我的Python脚本:

from bs4 import BeautifulSoup 

text_data = BeautifulSoup(xml_data_set) 
list_of_tags = s.find_all(tag.has_attr('id')) 
#This creates an array of strings. The string that I'm interested looks like the following: 
#>> e.g. <task id="lyZY7EINc02" op="update"><added>2016-10-02T19:53:09.672Z</added><modified>2016-10-02T19:53:13.912Z</modified><name>This is a test task</name></task> 
list_of_dicts = [loads(dumps(xmltodict.parse(str(i)))) for i in l] 
#I then use xmltodict to change each tag into an a dictionary. The tag that I'm interested looks like the following: 
#>> e.g. {'[email protected]': 'lyZY7EINc02', 'task_modified': '2016-10-02T19:53:13.912Z', 'task_added': '2016-10-02T19:53:09.672Z', 'task_name': 'This is a test task', '[email protected]': 'update'} 

虽然,我可以得到TA sk_added日期和task_name,我无法获得我希望获得的其他属性。

+0

这是一个测试任务吗? –

+0

几乎没有任何内容显示在您链接到的文件中 –

+0

对于混淆,我很抱歉,但是文件被截断,但现在已经修复了新链接。你应该能够找到线58395 – Chris

回答

0

你只需要使用文本找到节点,然后就叫.parent得到任务节点。

In [55]: task 
Out[55]: <task id="lyZY7EINc02" op="update"><added>2016-10-02T19:53:09.672Z</added><modified>2016-10-02T19:53:13.912Z</modified><name>This is a test task</name></task> 
相关问题