예제 #1
0
    def test_load(self):
        actor = Actor('Nicolas Zanforlini')
        actor.add_film('Lord of war')
        actor.add_film('Wow')
        actor.load(db)
        actor_document = db.actors.find_one({'name': 'Nicolas Zanforlini'})
        self.assertIsNotNone(actor_document)
        self.assertEqual(actor_document.get('name'), 'Nicolas Zanforlini')
        self.assertEqual(actor_document.get('films'), ['Lord of war', 'Wow'])

        db.actors.delete_many({'name': 'Nicolas Zanforlini'})
def clean_actor(actor):
    actor_nettoye = actor.replace('\n', '').replace('.', '').strip()
    return actor_nettoye


def clean_title(title):
    title_nettoye = title.replace('\xa0', '')
    return title_nettoye


dico_actor = {}
for film in db.films.find():
    for actor in film.get('actors'):
        act = clean_actor(actor)
        if act not in dico_actor:
            dico_actor[act] = []
        tit = film.get('title')
        titre = clean_title(tit)
        dico_actor[act].append(titre)

print(dico_actor)

for act, tit in dico_actor.items():
    o = Actor(act)
    for t in tit:
        o.add_film(t)
    o.load(db)

client.close()