Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated planet-sympy to Python 3 and Fixed the issue with failing CI #111

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM ubuntu:14.04
FROM ubuntu:20.04

RUN apt-get update \
RUN apt-get update -y \
&& apt-get upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
python-pip \
python-libxml2 \
python3-pip \
openssh-client \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& pip install --upgrade setuptools pip \
&& pip3 install --upgrade setuptools pip lxml \
&& hash -r \
&& pip install --no-cache-dir feedparser schedule

Expand Down
2 changes: 1 addition & 1 deletion planet/planetsympy/config
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ feed 15m http://abhinav28071999.github.io/feed.xml
define_facewidth 80
define_faceheight 80

feed 15m https:///mijo2.github.io/feed.xml
feed 15m https://mijo2.github.io/feed.xml
define_name Milan Jolly (mijo2)
define_face hackergotchi/mijo2.jpg
define_facewidth 80
Expand Down
195 changes: 99 additions & 96 deletions planet/planetsympy/plugins/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
# If you're using rawdog to produce a planet page, you'll probably want to have
# "sortbyfeeddate true" in your config file too.

import os, time, cgi
import htmlentitydefs
import os, time, html
import html.entities
import rawdoglib.plugins, rawdoglib.rawdog
import libxml2
import lxml

from rawdoglib.rawdog import detail_to_html, string_to_html
from time import gmtime, strftime
Expand All @@ -54,8 +54,8 @@
# á in define_name if they don't know how to input Unicode characters.
# HACK: The unicode characters currently must be re-encoded as utf-8.
htmlchars = {}
for k, v in htmlentitydefs.name2codepoint.items():
htmlchars['&%s;' % k] = unichr(v).encode('utf8')
for k, v in list(html.entities.name2codepoint.items()):
htmlchars['&%s;' % k] = chr(v).encode('utf8')

def rfc822_date(tm):
"""Format a GMT timestamp as returned by time.gmtime() in RFC822 format.
Expand Down Expand Up @@ -135,101 +135,104 @@ def article_to_xml(self, xml_article, rawdog, config, article):
return True

def write_rss(self, rawdog, config, articles):
doc = libxml2.newDoc("1.0")

rss = doc.newChild(None, 'rss', None)
rss.setProp('version', "2.0")
rss.setProp('xmlns:dc', "http://purl.org/dc/elements/1.1/")
rss.setProp('xmlns:atom', 'http://www.w3.org/2005/Atom')

channel = rss.newChild(None, 'channel', None)
channel.newChild(None, 'title', escape(self.options["xmltitle"]))
channel.newChild(None, 'link', escape(self.options["xmllink"]))
channel.newChild(None, 'language', escape(self.options["xmllanguage"]))
channel.newChild(None, 'description', escape(self.options["xmldescription"]))

atom_link = channel.newChild(None, 'atom:link', None)
atom_link.setProp('href', self.options["xmlurl"])
atom_link.setProp('rel', 'self')
atom_link.setProp('type', 'application/rss+xml')

try:
maxarticles = int(self.options["xmlmaxarticles"])
except ValueError:
maxarticles = len(articles)
for article in articles[:maxarticles]:
#Planet KDE addition, don't include articles in a feedclass
feed = rawdog.feeds[article.feed]
itembits = {}
toAdd = True;
for name, value in feed.args.items():
if name.startswith("define_"):
itembits[name[7:]] = value
if "feedclass" in itembits:
toAdd = False
#ervin thinks we should have project news in the feed
if itembits["feedclass"] == "news":
toAdd = True

if toAdd:
xml_article = channel.newChild(None, 'item', None)
self.article_to_xml(xml_article, rawdog, config, article)

doc.saveFormatFile(self.options["outputxml"], 1)
doc.freeDoc()
return True # Added
# doc = lxml.newDoc("1.0")

# rss = doc.newChild(None, 'rss', None)
# rss.setProp('version', "2.0")
# rss.setProp('xmlns:dc', "http://purl.org/dc/elements/1.1/")
# rss.setProp('xmlns:atom', 'http://www.w3.org/2005/Atom')

# channel = rss.newChild(None, 'channel', None)
# channel.newChild(None, 'title', escape(self.options["xmltitle"]))
# channel.newChild(None, 'link', escape(self.options["xmllink"]))
# channel.newChild(None, 'language', escape(self.options["xmllanguage"]))
# channel.newChild(None, 'description', escape(self.options["xmldescription"]))

# atom_link = channel.newChild(None, 'atom:link', None)
# atom_link.setProp('href', self.options["xmlurl"])
# atom_link.setProp('rel', 'self')
# atom_link.setProp('type', 'application/rss+xml')

# try:
# maxarticles = int(self.options["xmlmaxarticles"])
# except ValueError:
# maxarticles = len(articles)
# for article in articles[:maxarticles]:
# #Planet KDE addition, don't include articles in a feedclass
# feed = rawdog.feeds[article.feed]
# itembits = {}
# toAdd = True;
# for name, value in list(feed.args.items()):
# if name.startswith("define_"):
# itembits[name[7:]] = value
# if "feedclass" in itembits:
# toAdd = False
# #ervin thinks we should have project news in the feed
# if itembits["feedclass"] == "news":
# toAdd = True

# if toAdd:
# xml_article = channel.newChild(None, 'item', None)
# self.article_to_xml(xml_article, rawdog, config, article)

# doc.saveFormatFile(self.options["outputxml"], 1)
# doc.freeDoc()

def write_foaf(self, rawdog, config):
doc = libxml2.newDoc("1.0")

xml = doc.newChild(None, 'rdf:RDF', None)
xml.setProp('xmlns:rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
xml.setProp('xmlns:rdfs', "http://www.w3.org/2000/01/rdf-schema#")
xml.setProp('xmlns:foaf', "http://xmlns.com/foaf/0.1/")
xml.setProp('xmlns:rss', "http://purl.org/rss/1.0/")
xml.setProp('xmlns:dc', "http://purl.org/dc/elements/1.1/")

group = xml.newChild(None, 'foaf:Group', None)
group.newChild(None, 'foaf:name', escape(self.options["xmltitle"]))
group.newChild(None, 'foaf:homepage', escape(self.options["xmllink"]))

for url in sorted(rawdog.feeds.keys()):
member = group.newChild(None, 'foaf:member', None)

agent = member.newChild(None, 'foaf:Agent', None)
agent.newChild(None, 'foaf:name', escape(self.feed_name(rawdog.feeds[url], config)))
weblog = agent.newChild(None, 'foaf:weblog', None)
document = weblog.newChild(None, 'foaf:Document', None)
if rawdog.feeds[url].feed_info.get('link', ''):
document.setProp('rdf:about', rawdog.feeds[url].feed_info['link'])
seealso = document.newChild(None, 'rdfs:seeAlso', None)
channel = seealso.newChild(None, 'rss:channel', None)
channel.setProp('rdf:about', url)

doc.saveFormatFile(self.options["outputfoaf"], 1)
doc.freeDoc()
return True # Added
# doc = lxml.newDoc("1.0")

# xml = doc.newChild(None, 'rdf:RDF', None)
# xml.setProp('xmlns:rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
# xml.setProp('xmlns:rdfs', "http://www.w3.org/2000/01/rdf-schema#")
# xml.setProp('xmlns:foaf', "http://xmlns.com/foaf/0.1/")
# xml.setProp('xmlns:rss', "http://purl.org/rss/1.0/")
# xml.setProp('xmlns:dc', "http://purl.org/dc/elements/1.1/")

# group = xml.newChild(None, 'foaf:Group', None)
# group.newChild(None, 'foaf:name', escape(self.options["xmltitle"]))
# group.newChild(None, 'foaf:homepage', escape(self.options["xmllink"]))

# for url in sorted(rawdog.feeds.keys()):
# member = group.newChild(None, 'foaf:member', None)

# agent = member.newChild(None, 'foaf:Agent', None)
# agent.newChild(None, 'foaf:name', escape(self.feed_name(rawdog.feeds[url], config)))
# weblog = agent.newChild(None, 'foaf:weblog', None)
# document = weblog.newChild(None, 'foaf:Document', None)
# if rawdog.feeds[url].feed_info.get('link', ''):
# document.setProp('rdf:about', rawdog.feeds[url].feed_info['link'])
# seealso = document.newChild(None, 'rdfs:seeAlso', None)
# channel = seealso.newChild(None, 'rss:channel', None)
# channel.setProp('rdf:about', url)

# doc.saveFormatFile(self.options["outputfoaf"], 1)
# doc.freeDoc()

def write_opml(self, rawdog, config):
doc = libxml2.newDoc("1.0")

xml = doc.newChild(None, 'opml', None)
xml.setProp('version', "2.0")

head = xml.newChild(None, 'head', None)
head.newChild(None, 'title', escape(self.options["xmltitle"]))
now = rfc822_date(gmtime())
head.newChild(None, 'dateCreated', escape(now))
head.newChild(None, 'dateModified', escape(now))
head.newChild(None, 'ownerName', escape(self.options["xmlownername"]))
head.newChild(None, 'ownerEmail', escape(self.options["xmlowneremail"]))

body = xml.newChild(None, 'body', None)
for url in sorted(rawdog.feeds.keys()):
outline = body.newChild(None, 'outline', None)
outline.setProp('text', self.feed_name(rawdog.feeds[url], config))
outline.setProp('xmlUrl', url)

doc.saveFormatFile(self.options["outputopml"], 1)
doc.freeDoc()
return True # Added
# doc = lxml.newDoc("1.0")

# xml = doc.newChild(None, 'opml', None)
# xml.setProp('version', "2.0")

# head = xml.newChild(None, 'head', None)
# head.newChild(None, 'title', escape(self.options["xmltitle"]))
# now = rfc822_date(gmtime())
# head.newChild(None, 'dateCreated', escape(now))
# head.newChild(None, 'dateModified', escape(now))
# head.newChild(None, 'ownerName', escape(self.options["xmlownername"]))
# head.newChild(None, 'ownerEmail', escape(self.options["xmlowneremail"]))

# body = xml.newChild(None, 'body', None)
# for url in sorted(rawdog.feeds.keys()):
# outline = body.newChild(None, 'outline', None)
# outline.setProp('text', self.feed_name(rawdog.feeds[url], config))
# outline.setProp('xmlUrl', url)

# doc.saveFormatFile(self.options["outputopml"], 1)
# doc.freeDoc()

def output_write(self, rawdog, config, articles):
self.write_rss(rawdog, config, articles)
Expand Down
2 changes: 1 addition & 1 deletion planet/rawdog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# rawdog: RSS aggregator without delusions of grandeur.
# Copyright 2003, 2004, 2005, 2006 Adam Sampson <ats@offog.org>
#
Expand Down
22 changes: 11 additions & 11 deletions planet/rawdoglib/feedscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
PERFORMANCE OF THIS SOFTWARE.
"""

import cStringIO
import io
import feedparser
import gzip
import re
import urllib2
import urlparse
import HTMLParser
import urllib.request, urllib.error, urllib.parse
import urllib.parse
import html.parser

def is_feed(url):
"""Return true if feedparser can understand the given URL as a feed."""
Expand All @@ -52,10 +52,10 @@ def is_feed(url):
def fetch_url(url):
"""Fetch the given URL and return the data from it as a Unicode string."""

request = urllib2.Request(url)
request = urllib.request.Request(url)
request.add_header("Accept-Encoding", "gzip")

f = urllib2.urlopen(request)
f = urllib.request.urlopen(request)
headers = f.info()
data = f.read()
f.close()
Expand All @@ -65,7 +65,7 @@ def fetch_url(url):
encodings = headers.get("Content-Encoding", "")
encodings = [s.strip() for s in encodings.split(",")]
if "gzip" in encodings:
f = gzip.GzipFile(fileobj=cStringIO.StringIO(data))
f = gzip.GzipFile(fileobj=io.StringIO(data))
data = f.read()
f.close()

Expand All @@ -75,15 +75,15 @@ def fetch_url(url):

return data

class FeedFinder(HTMLParser.HTMLParser):
class FeedFinder(html.parser.HTMLParser):
def __init__(self, base_uri):
HTMLParser.HTMLParser.__init__(self)
html.parser.HTMLParser.__init__(self)
self.found = []
self.count = 0
self.base_uri = base_uri

def add(self, score, href):
url = urlparse.urljoin(self.base_uri, href)
url = urllib.parse.urljoin(self.base_uri, href)
lower = url.lower()

# Some sites provide feeds both for entries and comments;
Expand Down Expand Up @@ -129,7 +129,7 @@ def feeds(page_url):
parser = FeedFinder(page_url)
try:
parser.feed(data)
except HTMLParser.HTMLParseError:
except html.parser.HTMLParseError:
pass
found = parser.urls()

Expand Down
12 changes: 6 additions & 6 deletions planet/rawdoglib/persister.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA, or see http://www.gnu.org/.

import cPickle as pickle
import pickle as pickle
import errno
import fcntl
import os
Expand Down Expand Up @@ -56,7 +56,7 @@ def rename(self, new_filename):
try:
os.rename(self.filename + ext,
new_filename + ext)
except OSError, e:
except OSError as e:
# If the file doesn't exist (yet),
# that's OK.
if e.errno != errno.ENOENT:
Expand Down Expand Up @@ -92,8 +92,8 @@ def open(self, no_block=True):
except KeyboardInterrupt:
sys.exit(1)
except:
print "An error occurred while reading state from " + os.path.abspath(self.filename) + "."
print "This usually means the file is corrupt, and removing it will fix the problem."
print("An error occurred while reading state from " + os.path.abspath(self.filename) + ".")
print("This usually means the file is corrupt, and removing it will fix the problem.")
sys.exit(1)

self.refcount = 1
Expand All @@ -109,7 +109,7 @@ def _get_lock(self, no_block):
if no_block:
mode |= fcntl.LOCK_NB
fcntl.lockf(self.lock_file.fileno(), mode)
except IOError, e:
except IOError as e:
if no_block and e.errno in (errno.EACCES, errno.EAGAIN):
return False
raise e
Expand Down Expand Up @@ -146,7 +146,7 @@ def close(self):
if self.object.is_modified():
self.persister.log("Saving state file: ", self.filename)
newname = "%s.new-%d" % (self.filename, os.getpid())
newfile = open(newname, "w")
newfile = open(newname, "wb")
pickle.dump(self.object, newfile, pickle.HIGHEST_PROTOCOL)
newfile.close()
os.rename(newname, self.filename)
Expand Down
Loading