#!/usr/bin/python3 import requests import json import os url = 'https://graphql.anilist.co' variables = {} home = os.path.expanduser("~") subdir = "notes/misc" # Here we define our query as a multi-line string query = ''' query ($name: String, $type: MediaType) { MediaListCollection (userName: $name, type: $type) { lists { status entries { media { title { romaji } } } } } } ''' variables['name'] = input('Enter username: ') for MediaType in ['ANIME', 'MANGA']: variables['type'] = MediaType response = requests.post(url, json={'query': query, 'variables': variables}) data = response.json() with open(os.path.join(home, subdir, "AniList_{}_{}.txt".format(variables['name'], variables['type'])), "w") as f: for sublist in data["data"]["MediaListCollection"]["lists"]: print('----- {} -----'.format(sublist["status"]), end="\n"*2, file=f) for entry in sublist["entries"]: print(entry["media"]["title"]["romaji"], file=f) print("\n", file=f)