XML.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:birdnet 作者: cyysu 项目源码 文件源码
def filter(self, text):
    wanted_dm = ['created_at', 'id', 'text', 'source', 'sender_id', 'recipient_id', 'sender_screen_name', 'recipient_screen_name']
    root = ET.fromstring(text)
    builder = ET.TreeBuilder()
    builder.start('direct-messages', {'type': 'array'})
    for status in root.findall('direct_message'):
      builder.start('direct_message', {})
      for tag in wanted_status:
        copy_element(builder, status, tag)

      sender = status.find('sender')
      builder.start('sender', {})
      copy_element(builder, sender, 'profile_image_url')
      builder.end('sender')

      recipient = status.find('recipient')
      builder.start('recipient', {})
      copy_element(builder, recipient, 'profile_image_url')
      builder.end('recipient')

      builder.end('direct_message')
    builder.end('direct-messages')
    return ET.tostring(builder.close())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号