Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2. import os
  3. from shutil import copyfile
  4.  
  5. # Bu dvd'de fscommand klasöründeki ZZZY0258.pdf dosyası aslında bu dvdnin haritası.
  6. # arsiv.xml olarak script ile aynı yere kopyaladım
  7.  
  8. root = ET.parse('arsiv.xml').getroot()
  9. base = os.path.abspath(os.path.dirname(__file__))
  10. unknown_files = []
  11. for type_tag in root.findall('Item'):
  12. year = type_tag.get('Year')
  13. print(year)
  14. os.makedirs(year)
  15. os.chdir(year)
  16. for year_tag in type_tag.findall('Item'):
  17. month = year_tag.get('Month')
  18. print(month)
  19. os.makedirs(month)
  20. os.chdir(month)
  21. used_articles = []
  22. for index,article_tag in enumerate(year_tag.findall('Item')):
  23. title = article_tag.get('Title')
  24. file_name = article_tag.get('File')
  25. btd_location = 'fscommand klasorune giden yol'
  26. print(str(index+1) + '-' + title)
  27. title = title.replace('/','').replace('(','').replace(')','')
  28. try:
  29. if file_name not in used_articles:
  30. copyfile(btd_location+file_name+'.pdf',str(index+1)+'-'+title+'.pdf')
  31. used_articles.append(file_name)
  32. except FileNotFoundError as err:
  33. print(err)
  34. unknown_files.append(file_name)
  35. os.chdir('../')
  36. os.chdir(base)
  37.  
  38. missing = open('missing.txt','w')
  39. for m_file in unknown_files:
  40. missing.write(m_file+'\n')
  41. missing.close()
  42. print(unknown_files)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement