In [ ]:
import requests
import numpy as np

In [ ]:
username = 'username'
query = 'https://myanimelist.net/malappinfo.php?u=%s&status=all&type=anime' % username
r = requests.get(query)
if r.status_code != requests.codes.ok:
    print ("Error processing request. Try again")
    import sys; sys.exit()

In [ ]:
from lxml import etree
doc = etree.fromstring(r.content)
titles = doc.xpath('.//series_title/text()')
ratings = doc.xpath('.//my_score/text()')

In [ ]:
from itertools import compress
mask = [rating != '0' for rating in ratings]
seen_titles = list(compress(titles, mask))
seen_ratings = list(map(int, compress(ratings, mask)))

In [ ]:
uid = doc.xpath('.//user_id/text()')

Use MAL credentials to get images.


In [ ]:
username = 'username'
password = 'password'

Try getting image information for each show


In [ ]:
import time

for title in seen_titles:
    title1 = "+".join( title.split() )
    query = 'https://%s:%s@myanimelist.net/api/anime/search.xml?q=%s' % (username, password, title1)
    r = requests.get(query)

    while r.status_code != requests.codes.ok:
        r = requests.get(query)
        time.sleep(1.0)    # don't overload their server...


    from PIL import Image
    import urllib.request
    import io

    %matplotlib inline

    with urllib.request.urlopen(URL) as url:
        f = io.BytesIO(url.read())

    img = Image.open(f, 'r')
    width, height = img.size   # Get dimensions

    print (title)

In [ ]:
title = 'Amagami SS%2B Plus'
title1 = "+".join( title.split() )
query = 'https://%s:%s@myanimelist.net/api/anime/search.xml?q=%s' % (username, password, title1)
r = requests.get(query)
if r.status_code != requests.codes.ok:
    r = requests.get(query)
    print ("Error processing request. Try again")

In [ ]:
from lxml import etree
doc = etree.fromstring(r.content)
image = doc.xpath('.//image/text()')
URL = image[0]

In [ ]:
from PIL import Image
import urllib.request
import io

In [ ]:
%matplotlib inline

with urllib.request.urlopen(URL) as url:
    f = io.BytesIO(url.read())

img = Image.open(f, 'r')
img

We'll need to crop the image if necessary.


In [ ]:
width, height = img.size   # Get dimensions
new_width = 224
new_height = 224

In [ ]:
left = int((width - new_width)/2)
top = int((height - new_height)/2)
right = (left+ new_width)
bottom = (top + new_height)

cropped = np.array(img.crop((left, top, right, bottom)))
img.crop((left, top, right, bottom))

In [ ]:
np.shape(cropped)

In [ ]:
img.crop((left, top, right, bottom)).size

In [ ]:
title