Skip to content

Instantly share code, notes, and snippets.

@purplepinapples
Created January 21, 2019 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplepinapples/5dc60f15f2837bf1cea71b089cfeaa0a to your computer and use it in GitHub Desktop.
Save purplepinapples/5dc60f15f2837bf1cea71b089cfeaa0a to your computer and use it in GitHub Desktop.
Use Anilist API to get an AniList entry from a MAL id
#!/usr/bin/env python3
import requests
query = '''query($id: Int, $type: MediaType){Media(idMal: $id, type: $type){siteUrl}}'''
variables = {
'id': 30831,
'type': "ANIME"
}
url = 'https://graphql.anilist.co'
response = requests.post(url, json={'query': query, 'variables': variables})
print(response.json())
@janvernieuwe
Copy link

<?php
$query = 'query($id: Int, $type: MediaType){Media(idMal: $id, type: $type){siteUrl}}';
$data_string = json_encode(['query' => $query, 'variables' => ['id' => 38397, 'type' => 'ANIME']]);
$ch = curl_init('https://graphql.anilist.co');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
    $ch,
    CURLOPT_HTTPHEADER,
    array(
        'Content-Type: application/json',
        'Content-Length: '.strlen($data_string),
    )
);
$result = curl_exec($ch);
curl_close($ch);

var_dump($result);

The plain php version (I'll make this into a package soon)

@purplepinapples
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment