Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import xml.etree.ElementTree as ET
- def txt_to_xml():
- file_cont = list(open('movies.txt','r',encoding='cp1252').readlines())
- xmlfile = open('xmlfile.xml','w',encoding='cp1252')
- xmlfile.write('<films>\n')
- for film in file_cont:
- film.strip()
- words = film.split('/')
- #film_and_actors['Film']=words.pop(0)
- #film_and_actors['Actors']= words
- xmlfile.write('<film>\n')
- xmlfile.write('<caption>'+words.pop(0)+'</caption>\n')
- for name in words:
- xmlfile.write('<actor>'+words.pop(0)+'</actor>\n')
- xmlfile.write('</film>\n\n')
- xmlfile.write('</films>\n')
- xmlfile.close()
- def xml_to_json():
- file = list(open('xmlfile.xml', 'r').readlines())
- jsonfile = open('jsonfile.json', 'w')
- for string in file:
- new_string=json.dumps(string)
- jsonfile.write(new_string+"\n")
- jsonfile.close()
- def two_actors():
- print('Наберите имена 2х актёров,и мы отобразим фильмы,в которых они принимали участие')
- name1=input()
- name2=input()
- actors=[name1,name2]
- return actors
- def cinema_search():
- filemap = ET.parse('xmlfile.xml')
- actors=two_actors()
- result=[]
- for actor in actors:
- s=set()
- film_node=filemap.findall(".//film/[actor='" + actor + "']" )
- for film in film_node:
- film_name = film.findall(".//caption")[0].text
- s.add(film_name)
- result.append(s)
- print(result)
- txt_to_xml()
- xml_to_json()
- cinema_search()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement