Skip to content

Instantly share code, notes, and snippets.

@neko-neko-nyan
Created June 12, 2019 13:35
Show Gist options
  • Save neko-neko-nyan/f4197a067ac965a0538190165bd552ff to your computer and use it in GitHub Desktop.
Save neko-neko-nyan/f4197a067ac965a0538190165bd552ff to your computer and use it in GitHub Desktop.
Скрипт поиска не просмотренных аниме в просмотренных франшизах
import json
import os
from time import sleep
import pyshiki
from pprint import pprint
api = pyshiki.Api("<Логин>", "<Пароль>")
def get_in_list(list_name):
a = []
i = 1
while True:
n = api.animes(page=i, limit=50, order='id', censored='false',
mylist=list_name).get()
if not n:
break
i += 1
a += n
return {i['id']: i for i in a}
def gen_ids(*ls):
for ll in ls:
for lx in ll:
yield lx['id']
def cached(name, gen):
name = "%s.json" % name
if os.path.exists(name):
with open(name) as f:
return json.load(f)
data = gen()
with open(name, "wt") as f:
json.dump(data, f)
return data
def find_franchises(completed, ignored):
franchises = {}
for pn, (n, a) in enumerate(completed.items()):
print("\rGetting franchises: %s%%" % (pn * 100 / len(completed)), end='')
sleep(0.45)
try:
fa = api.animes("%s/franchise" % n).get()['nodes']
for i in fa:
if i['id'] not in completed and i['id'] not in ignored:
franchises[i['id']] = i
except BaseException as err:
print(err)
sleep(5)
return franchises
def main():
print("Getting lists...")
completed = cached("completed", lambda: get_in_list('completed'))
planned = cached("planned", lambda: get_in_list('planned'))
franchises = cached("franchises", lambda: find_franchises(completed, planned))
ona_spec = []
tv = []
film = []
for n, a in franchises.items():
if a['kind'] in ('ONA', 'Спешл'):
ona_spec.append(a)
elif a['kind'] == 'TV Сериал':
tv.append(a)
elif a['kind'] == 'Фильм':
film.append(a)
with open("output.txt", "wt") as f:
f.write("\n---- FILMS ----\n")
for a in film:
f.write("%s - https://shikimori.org%s\n" % (a['name'], a['url']))
f.write("\n---- SERIALS ----\n")
for a in tv:
f.write("%s - https://shikimori.org%s\n" % (a['name'], a['url']))
f.write("\n---- ONAS ----\n")
for a in ona_spec:
f.write("%s - https://shikimori.org%s\n" % (a['name'], a['url']))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment