#!/usr/bin/env python
# vim:fileencoding=utf-8

from __future__ import absolute_import, division, print_function, unicode_literals

from calibre.web.feeds.news import BasicNewsRecipe

'''
ACM Queue Magazine
'''


class QueueAcmOrg(BasicNewsRecipe):
    title = 'ACM Queue Magazine'
    __author__ = 'yodha8'
    description = 'Queue is the ACM magazine for practicing software engineers. Published once every 2 months. Example: Jan-Feb.'
    oldest_article = 60
    max_articles_per_feed = 50
    auto_cleanup = True
    language = 'en'
    cover_url = 'https://queue.acm.org/img/acmqueue_logo.gif'

    feeds = [
        ('All Queue Content', 'https://queue.acm.org/rss/feeds/queuecontent.xml'),
    ]

    def get_cover_url(self):
        soup = self.index_to_soup('https://queue.acm.org/')
        imgs = soup.find_all(
            'img',
            attrs={'src': lambda x: x and x.startswith('/app/')},
        )
        if len(imgs) > 0:
            self.cover_url = 'https://queue.acm.org/' + imgs[0]['src']
        return getattr(self, 'cover_url', self.cover_url)
