diff --git a/roles/developer/build/files/developer-rss-update.cron b/roles/developer/build/files/developer-rss-update.cron index 440de0f579..98232b22e0 100644 --- a/roles/developer/build/files/developer-rss-update.cron +++ b/roles/developer/build/files/developer-rss-update.cron @@ -1,2 +1,2 @@ MAILTO=web-members@fedoraproject.org -45 * * * * apache /srv/web/developer.fedoraproject.org/rss.py /srv/web/developer.fedoraproject.org/index.html +45 * * * * apache /usr/local/bin/rss.py /srv/web/developer.fedoraproject.org/index.html diff --git a/roles/developer/build/files/rss.py b/roles/developer/build/files/rss.py new file mode 100755 index 0000000000..7a8f91620a --- /dev/null +++ b/roles/developer/build/files/rss.py @@ -0,0 +1,105 @@ +#!/usr/bin/python -tt +# -*- coding: utf-8 -*- + +import codecs +import os +import sys +import feedparser +import re +import sys + +feedparser._HTMLSanitizer.unacceptable_elements_with_end_tag.add('
') + +defenc = "utf-8" if sys.getdefaultencoding() == "ascii" else sys.getdefaultencoding() + +FedMag = ['http://fedoraplanet.org/rss20.xml'] + +if len(sys.argv) > 2: + print ('Alone script or only one argument is allowed.') + sys.exit(1) + +HTML = u""" +""" + + +for feed in map(feedparser.parse, FedMag): + # We will parse last ten items + HTML += u""" +
+
+
+
+

Fedora Planet

+
+
+
+""" + cnt = 0 + for item in feed["items"][:4]: + if int(cnt) % 2 == 0: + HTML += u""" +
+ """ + item.title = item.title.replace("&", "&") + author, title = item.title.split(':', 1) + link = item.links[0]['href'] + # Remove image tag from beginning + article_desc = '\n'.join(item.description.split('\n')[1:]) + # remove html tags from description + article_desc = re.sub('<[^<]+?>', '', article_desc) + if len(article_desc) > 140: + article_desc = ' '.join(article_desc.split()[0:25]) + '...' + if not article_desc.startswith('

'): + article_desc = '

%s

' % article_desc + # we got + # Tue, 20 Oct 2015 03:28:42 +0000 + # But we expect + # Tue, 20 Oct 2015 + article_date = ' '.join(item.updated.split()[:4]) + HTML += u""" + +""".format(article_url=link, + article_title=title, + article_desc=article_desc, + article_date=article_date, + author=author) + cnt += 1 + if int(cnt) % 2 == 0: + HTML += u""" +
+""" + HTML += u""" +
+
+
+""" + +if len(sys.argv) == 1: + INDEX_FILE = os.path.join('.', '_site', 'index.html') +else: + INDEX_FILE = sys.argv[1] +with codecs.open(INDEX_FILE, 'r', 'utf8') as f: + contents = [line for line in f.readlines()] +if contents: + with codecs.open(INDEX_FILE, 'w', 'utf8') as f: + found_start = False + for line in contents: + if not found_start: + f.write(line) + if '' in line: + f.write(HTML) + found_start = True + continue + if '' in line: + found_start = False + f.write(line) + continue + + #regexp = r'.*()(.*)().*' + #print (re.search(regexp, contents, re.MULTILINE | re.DOTALL)) + #contents = re.sub(regexp, r'\1 MYREPLACE \3', contents, re.DOTALL | re.MULTILINE) diff --git a/roles/developer/build/tasks/main.yml b/roles/developer/build/tasks/main.yml index 5156927bea..380f67d876 100644 --- a/roles/developer/build/tasks/main.yml +++ b/roles/developer/build/tasks/main.yml @@ -24,6 +24,11 @@ # tags: # - developer.fedoraproject.org +- name: install rss.py script + copy: name=rss.py dest=/usr/local/bin/rss.py mode=0755 owner=root group=root + tags: + - developer.fedoraproject.org + - name: Install the syncDeveloper and rss feed update jobs copy: > src={{item}}.cron dest=/etc/cron.d/{{item}}.cron