def handle(self, *args, **options): category = 'anime' start = 0 if options.get('id'): anime_id = options.get('id')[0] anime = Work.objects.filter(category__slug='anime').get( id=anime_id) if anime.anidb_aid == 0: for reference in anime.reference_set.all(): if reference.url.startswith( 'http://anidb.net') or reference.url.startswith( 'https://anidb.net'): query = urlparse(reference.url).query anidb_aid = parse_qs(query).get('aid') if anidb_aid: anime.anidb_aid = anidb_aid[0] anime.save() todo = Work.objects.filter(category__slug='anime', id=anime_id, anidb_aid__gt=0) else: todo = Work.objects\ .only('pk', 'title', 'poster', 'nsfw')\ .annotate(rating_count=Count('rating'))\ .filter(category__slug=category, rating_count__gte=6)\ .exclude(anidb_aid=0)\ .order_by('-rating_count') a = AniDB('mangakihttp', 1) i = 0 for anime in todo: i += 1 if i < start: continue print(i, ':', anime.title, anime.id) creators = a.get(anime.anidb_aid).creators print(creators) staff_map = dict( Role.objects.filter( slug__in=['author', 'director', 'composer']).values_list( 'slug', 'pk')) for creator in creators.findAll('name'): artist = get_or_create_artist(creator.string) if creator['type'] == 'Direction': staff_id = 'director' elif creator['type'] == 'Music': staff_id = 'composer' elif creator['type'] == 'Original Work' or creator[ 'type'] == 'Story Composition': staff_id = 'author' else: staff_id = None if staff_id is not None: Staff.objects.get_or_create(work=anime, role_id=staff_map[staff_id], artist=artist) anime.save()
def handle(self, *args, **options): category = 'anime' start = 0 if len(sys.argv) > 2: if sys.argv[2] == 'id': anime_id = sys.argv[3] anime = Anime.objects.get(id=anime_id) if anime.anidb_aid == 0: for reference in anime.reference_set.all(): if reference.url.startswith('http://anidb.net'): query = urlparse(reference.url).query anidb_aid = parse_qs(query).get('aid') if anidb_aid: anime.anidb_aid = anidb_aid[0] anime.save() todo = Anime.objects.filter(id=anime_id, anidb_aid__gt=0) else: work_query = 'SELECT mangaki_{category}.work_ptr_id, mangaki_work.id, mangaki_work.title, mangaki_work.poster, mangaki_work.nsfw, COUNT(mangaki_work.id) rating_count FROM mangaki_{category}, mangaki_work, mangaki_rating WHERE mangaki_{category}.work_ptr_id = mangaki_work.id AND mangaki_rating.work_id = mangaki_work.id AND mangaki_{category}.anidb_aid > 0 GROUP BY mangaki_work.id, mangaki_{category}.work_ptr_id HAVING COUNT(mangaki_work.id) >= {min_ratings} ORDER BY {order_by}' todo = Anime.objects.raw( work_query.format(category=category, min_ratings=6, order_by='rating_count DESC')) if sys.argv[2] == 'from': start = int(sys.argv[3]) a = AniDB('mangakihttp', 1) i = 0 for anime in todo: i += 1 if i < start: continue print(i, ':', anime.title, anime.id) creators = a.get(anime.anidb_aid).creators print(creators) for creator in creators.findAll('name'): if creator['type'] == 'Direction': try_replace(anime, 'director', creator.string) elif creator['type'] == 'Music': try_replace(anime, 'composer', creator.string) elif creator['type'] == 'Original Work' or creator[ 'type'] == 'Story Composition': try_replace(anime, 'author', creator.string) anime.save()
def handle(self, *args, **options): category = 'anime' start = 0 if options.get('id'): anime_id = options.get('id')[0] anime = Anime.objects.get(id=anime_id) if anime.anidb_aid == 0: for reference in anime.reference_set.all(): if reference.url.startswith('http://anidb.net'): query = urlparse(reference.url).query anidb_aid = parse_qs(query).get('aid') if anidb_aid: anime.anidb_aid = anidb_aid[0] anime.save() todo = Anime.objects.filter(id=anime_id, anidb_aid__gt=0) else: work_query = 'SELECT mangaki_{category}.work_ptr_id, mangaki_work.id, mangaki_work.title, mangaki_work.poster, mangaki_work.nsfw, COUNT(mangaki_work.id) rating_count FROM mangaki_{category}, mangaki_work, mangaki_rating WHERE mangaki_{category}.work_ptr_id = mangaki_work.id AND mangaki_rating.work_id = mangaki_work.id AND mangaki_{category}.anidb_aid > 0 GROUP BY mangaki_work.id, mangaki_{category}.work_ptr_id HAVING COUNT(mangaki_work.id) >= {min_ratings} ORDER BY {order_by}' todo = Anime.objects.raw(work_query.format(category=category, min_ratings=6, order_by='rating_count DESC')) """if sys.argv[2] == 'from': start = int(sys.argv[3])""" a = AniDB('mangakihttp', 1) i = 0 for anime in todo: i += 1 if i < start: continue print(i, ':', anime.title, anime.id) creators = a.get(anime.anidb_aid).creators print(creators) for creator in creators.findAll('name'): if creator['type'] == 'Direction': try_replace(anime, 'director', creator.string) elif creator['type'] == 'Music': try_replace(anime, 'composer', creator.string) elif creator['type'] == 'Original Work' or creator['type'] == 'Story Composition': try_replace(anime, 'author', creator.string) anime.save()
def handle(self, *args, **options): category = 'anime' start = 0 if options.get('id'): anime_id = options.get('id')[0] anime = Work.objects.filter(category__slug='anime').get( id=anime_id) if anime.anidb_aid == 0: for reference in anime.reference_set.all(): if reference.url.startswith( 'http://anidb.net') or reference.url.startswith( 'https://anidb.net'): query = urlparse(reference.url).query anidb_aid = parse_qs(query).get('aid') if anidb_aid: anime.anidb_aid = anidb_aid[0] anime.save() todo = Work.objects.filter(category__slug='anime', id=anime_id, anidb_aid__gt=0) else: todo = Work.objects\ .only('pk', 'title', 'ext_poster', 'nsfw')\ .annotate(rating_count=Count('rating'))\ .filter(category__slug=category, rating_count__gte=6)\ .exclude(anidb_aid=0)\ .order_by('-rating_count') a = AniDB('mangakihttp', 1) i = 0 for anime in todo: i += 1 if i < start: continue print(i, ':', anime.title, anime.id) creators = a.get(anime.anidb_aid).creators worktitles = a.get(anime.anidb_aid).worktitles for worktitle in worktitles: language = Language.objects.get(iso639=worktitle[2]) WorkTitle.objects.get_or_create(work=anime, title=worktitle[0], language=language, type=worktitle[1]) retrieve_tags = anime.retrieve_tags(a) deleted_tags = retrieve_tags["deleted_tags"] added_tags = retrieve_tags["added_tags"] updated_tags = retrieve_tags["updated_tags"] kept_tags = retrieve_tags["kept_tags"] print(anime.title + ":") if deleted_tags: print("\n\tLes tags enlevés sont :") for tag, weight in deleted_tags.items(): print('\t\t{}: {} '.format(tag, weight)) if added_tags: print("\n\tLes tags totalement nouveaux sont :") for tag, weight in added_tags.items(): print('\t\t{}: {} '.format(tag, weight)) if updated_tags: print("\n\tLes tags modifiés sont :") for tag, weight in updated_tags.items(): print('\t\t{}: {} -> {}'.format(tag, weight[0], weight[1])) if kept_tags: print("\n\tLes tags non modifiés/restés identiques sont :") for tag, weight in kept_tags.items(): print('\t\t{}: {} '.format(tag, weight)) choice = input("Voulez-vous réaliser ces changements [y/n] : ") if choice == 'n': print("\nOk, aucun changement ne va être fait") elif choice == 'y': anime.update_tags(deleted_tags, added_tags, updated_tags) staff_map = dict( Role.objects.filter( slug__in=['author', 'director', 'composer']).values_list( 'slug', 'pk')) for creator in creators.findAll('name'): artist = get_or_create_artist(creator.string) if creator['type'] == 'Direction': staff_id = 'director' elif creator['type'] == 'Music': staff_id = 'composer' elif creator['type'] == 'Original Work' or creator[ 'type'] == 'Story Composition': staff_id = 'author' else: staff_id = None if staff_id is not None: Staff.objects.get_or_create(work=anime, role_id=staff_map[staff_id], artist=artist) anime.save()