#!./env/bin/python # -*- coding: utf-8 -*- from datetime import datetime import collections from feedgen.feed import FeedGenerator import glob import json from lxml import etree import re import os.path I2P_OS = os.getenv("I2P_OS", "") I2P_BRANCH = os.getenv("I2P_BRANCH", "") DATA_DIR = os.path.join('data') RELEASE_DIR = os.path.join(DATA_DIR, I2P_OS, I2P_BRANCH) ENTRIES_FILE = os.path.join(DATA_DIR, 'entries.html') PLATFORM_ENTRIES_FILE = os.path.join(DATA_DIR, I2P_OS, I2P_BRANCH, 'entries.html') TRANSLATED_ENTRIES_FILES = os.path.join(DATA_DIR, 'translations/entries.*.html') TRANSLATED_PLATFORM_ENTRIES_FILES = os.path.join(DATA_DIR, I2P_OS, I2P_BRANCH, 'translations/entries.*.html') RELEASES_FILE = os.path.join(RELEASE_DIR, 'releases.json') CRL_FILES = os.path.join(DATA_DIR, 'crls/*.crl') BLOCKLIST_FILE = os.path.join(DATA_DIR, 'blocklist.xml') BUILD_DIR = os.path.join('build', I2P_OS, I2P_BRANCH) NEWS_FILE = os.path.join(BUILD_DIR, 'news.atom.xml') TRANSLATED_NEWS_FILE = os.path.join(BUILD_DIR, 'news_%s.atom.xml') def load_feed_metadata(fg): fg.id('urn:uuid:60a76c80-d399-11d9-b91C-543213999af6') fg.link( href='http://i2p-projekt.i2p/' ) fg.link( href='http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/news.atom.xml', rel='self' ) fg.link( href='http://dn3tvalnjz432qkqsvpfdqrwpqkw3ye4n4i2uyfr4jexvo3sp5ka.b32.i2p/news/news.atom.xml', rel='alternate' ) def load_entries(fg, entries_file, platform_entries_file=None): metadatas = {} finalentries = {} print('Loading entries from %s' % entries_file) entries = prepare_entries_file(fg, entries_file) # split() creates a junk final element with trailing for entry_str in entries[:-1]: entry_parts = entry_str.split('', 1) md = extract_entry_metadata(entry_parts[0]) metadatas[md['published']] = md finalentries[md['id']] = entry_parts[1] if os.path.exists(platform_entries_file) and platform_entries_file != entries_file and platform_entries_file is not None and platform_entries_file != "data/entries.html": print('Loading platform entries from %s' % platform_entries_file) entries = prepare_entries_file(fg, platform_entries_file) for entry_str in entries[:-1]: entry_parts = entry_str.split('', 1) md = extract_entry_metadata(entry_parts[0]) metadatas[md['updated']] = md finalentries[md['id']] = entry_parts[1] sorted_metadata = collections.OrderedDict(sorted(metadatas.items())) for metadata in sorted_metadata.values(): fe = fg.add_entry() fe.id(metadata['id']) fe.title(metadata['title']) fe.summary(metadata['summary']) fe.link( href=metadata['href'] ) fe.author( name=metadata['author'] ) fe.published(metadata['published']) fe.updated(metadata['updated']) fe.content(finalentries[metadata['id']], type='xhtml') def prepare_entries_file(fg, entries_file=None): with open(entries_file) as f: entries_data = f.read().strip('\n') # Replace HTML non-breaking space with unicode entries_data = entries_data.replace(' ', '\u00a0') # Strip the leading