Skip to content

Commit e35a7c8

Browse files
committed
Move fetch_planet into fetch_blog and import my blog posts into the planet section
Closes: #196
1 parent 5dd0030 commit e35a7c8

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ Cron jobs:
141141
142142
# Update translation stats
143143
./manage.py fetch_translations
144-
# Update planet posts
145-
./manage.py fetch_planet
144+
# Update blog posts
145+
./manage.py fetch_blog
146146
147147
File releases scan:
148148

news/management/commands/__init__.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,28 @@
2121
#
2222
from django.core.management.base import BaseCommand, CommandError
2323
import feedparser
24-
from urllib.request import urlopen
24+
import urllib.request
2525

26+
def fetch_url(url: str) -> feedparser.FeedParserDict:
27+
"""Helper for fetch blog posts"""
28+
try:
29+
request = urllib.request.Request(url)
30+
request.add_header('User-Agent', 'phpMyAdmin/website blog post fetcher')
31+
handle = urllib.request.urlopen(request)
32+
content = handle.read()
33+
except IOError as err:
34+
content = str(err)
35+
if hasattr(err, 'fp'):
36+
content = err.fp.read()
37+
raise CommandError(f'[{url}] {err.code}: {content}')
38+
return feedparser.parse(content)
2639

2740
class FeedCommand(BaseCommand):
28-
url = None
41+
url: str = ''
2942

3043
def process_feed(self, feed):
3144
raise NotImplementedError()
3245

3346
def handle(self, *args, **options):
34-
handle = urlopen(self.url)
35-
data = handle.read()
36-
parsed = feedparser.parse(data)
37-
if parsed.bozo == 1:
38-
raise CommandError(parsed.bozo_exception)
39-
else:
40-
self.process_feed(parsed)
47+
parsed = fetch_url(self.url)
48+
self.process_feed(parsed)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from news.management.commands import FeedCommand
2525
from news.models import Planet
2626

27-
URL = 'https://planet.phpmyadmin.net/rss20.xml'
27+
URL = 'https://blog.williamdes.eu/tags/phpmyadmin/atom.xml'
2828

2929

3030
class Command(FeedCommand):
@@ -33,6 +33,7 @@ class Command(FeedCommand):
3333

3434
def process_feed(self, feed):
3535
for entry in feed.entries:
36+
3637
params = {
3738
'title': entry.title,
3839
'date': parser.parse(entry.published),

0 commit comments

Comments
 (0)