def make_recomend_set(title): collection = json_serializer.get_decoded_json('collection') if title in collection.keys(): film = collection[title] else: print('Фильм не найден') exit() genres = film['genre_ids'] recommendation_list = set() for film in collection: if film == title: continue for g in genres: if g in collection[film]['genre_ids']: recommendation_list |= set([film]) if len(recommendation_list) > 10: break return recommendation_list
import json_serializer if __name__ == '__main__': coll = json_serializer.get_decoded_json('collection') print(coll.keys())
def get_random_post(): posts = json_serializer.get_decoded_json('posts') rnd = random.randint(0, len(posts) - 1) return posts[rnd]
def write_to_json(post_list): """Complete posts.json with new posts""" pres_posts = json_serializer.get_decoded_json('posts') clear = check_simil(pres_posts, post_list) #check for similar posts new_posts = pres_posts + clear json_serializer.encode_json('posts', new_posts)