| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
|
| 4 |
import datetime |
| 5 |
|
| 6 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 7 |
|
| 8 |
|
| 9 |
class IEEESpectrumMagazine(BasicNewsRecipe): |
| 10 |
title = 'IEEE Spectrum Magazine' |
| 11 |
language = 'en' |
| 12 |
__author__ = 'yodha8' |
| 13 |
description = 'Published on day 1 of every month.' |
| 14 |
oldest_article = 120 # Mag gathers articles published older than a month online. So we scan for 4 months in the feed. |
| 15 |
max_articles_per_feed = 100 |
| 16 |
auto_cleanup = True |
| 17 |
|
| 18 |
# RSS feed for the current month |
| 19 |
now = datetime.datetime.now() |
| 20 |
year_month = now.strftime('%Y/%B').lower() |
| 21 |
month_feed_url = 'https://spectrum.ieee.org/feeds/magazine/{}.rss'.format(year_month) |
| 22 |
|
| 23 |
feeds = [ |
| 24 |
('IEEE Spectrum Magazine', month_feed_url), |
| 25 |
] |
| 26 |
|
| 27 |
def get_cover_url(self): |
| 28 |
"""Go to this month's URL and pull cover image from there.""" |
| 29 |
month_url = 'https://spectrum.ieee.org/magazine/{}'.format(self.year_month) |
| 30 |
soup = self.index_to_soup(month_url) |
| 31 |
img_meta = soup.find('meta', property='og:image') |
| 32 |
img_url = img_meta['content'] |
| 33 |
return img_url |