def get_attachments(xml):
 items = get_items(xml)
 names = {}
 attachments = []
 for item in items:
  kind = item.find(u'post_type').string
  filename = item.find(u'post_name').string
  post_id = item.find(u'post_id').string
  if (kind == u'attachment'):
   attachments.append((item.find(u'post_parent').string, item.find(u'attachment_url').string))
  else:
   filename = get_filename(filename, post_id)
   names[post_id] = filename
 attachedposts = {}
 for (parent, url) in attachments:
  try:
   parent_name = names[parent]
  except KeyError:
   parent_name = None
  try:
   attachedposts[parent_name].append(url)
  except KeyError:
   attachedposts[parent_name] = []
   attachedposts[parent_name].append(url)
 return attachedposts

def get_attachments ( xml ) : items = get_items ( xml ) names = { } attachments = [ ] for item in items : kind = item . find ( u'post_type' ) . string filename = item . find ( u'post_name' ) . string post_id = item . find ( u'post_id' ) . string if ( kind == u'attachment' ) : attachments . append ( ( item . find ( u'post_parent' ) . string , item . find ( u'attachment_url' ) . string ) ) else : filename = get_filename ( filename , post_id ) names [ post_id ] = filename attachedposts = { } for ( parent , url ) in attachments : try : parent_name = names [ parent ] except KeyError : parent_name = None try : attachedposts [ parent_name ] . append ( url ) except KeyError : attachedposts [ parent_name ] = [ ] attachedposts [ parent_name ] . append ( url ) return attachedposts
returns a dictionary of posts that have attachments with a list of the attachment_urls .