Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. #!/usr/bin/python
  2. # coding: utf-8
  3. import io, os, sys
  4. import xml.etree.ElementTree as ElementTree
  5.  
  6. for filename in sys.argv[1:]:
  7.   if os.path.exists(filename):
  8.     doc = ElementTree.parse(filename)
  9.  
  10.     title = doc.find('title').text or "Kein Titel"
  11.     year = doc.find('year').text or "Jahr ?"
  12.     plot = doc.find('plot').text or "Keine Inhaltsangabe"
  13.     votes = doc.find('ratings/rating/votes').text or "-"
  14.     director = doc.find('director').text or "?"
  15.  
  16.     runtime = doc.find('runtime').text or "X"
  17.     if runtime == "0": runtime = "X"
  18.  
  19.     rating = doc.find('ratings/rating/value').text
  20.     if rating is None: votes = "-"
  21.     if rating is None: rating = "-.-"
  22.  
  23.     country = doc.find('country').text or "Land ?"
  24.     if country == "United Kingdom": country = "GB"
  25.     if country == "France": country = "Frankreich"
  26.     if country == "Australia": country = "Australien"
  27.     if country == "Belgium": country = "Belgien"
  28.     if country == "Germany": country = "Deutschland"
  29.     if country == "United States of America": country = "USA"
  30.     if country == "Netherlands": country = "Niederlande"
  31.     if country == "Sweden": country = "Schweden"
  32.     if country == "Canada": country = "Kanada"
  33.     if country == "Colombia": country = "Kolumbien"
  34.     if country == "Spain": country = "Spanien"
  35.     if country == "Argentina": country = "Argentinien"
  36.     if country == "Italy": country = "Italien"
  37.     if country == "Cuba": country = "Kuba"
  38.     if country == "Denmark": country = "D  nemark"
  39.     if country == "Czech Republic": country = "Tscheschien"
  40.     if country == "New Zealand": country = "Neuseeland"
  41.     if country == "Russia": country = "Russland"
  42.     if country == "Iceland": country = "Island"
  43.  
  44.     names = [n.text or "?" for n in doc.findall('actor/name')]
  45.     genre = [g.text or "Genre ?" for g in doc.findall('genre')]
  46.  
  47.   items  = [ title, country + ' ' + year + ' (R/V: ' + rating[:3] + '/ ' + votes + ')', runtime + ' min, ' + ', '.join(genre), plot, 'Regie: ' + director, 'Darsteller: ' + ', '.join(names)]
  48.  
  49. basename = os.path.splitext(filename)[0]
  50.  
  51. with io.open(basename + '.txt', 'w', encoding='utf-8') as fh:
  52.   fh.write(u'\n\n'.join(items))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement