Beispiel #1
0
 def make_rss_item(self):
     """ Generate PyRSS2Gen Item from the commit info """
     item_title = "Revision " + self.revision
     item_link = url + "?rev=" + self.revision
     rss_item = PyRSS2Gen.RSSItem(title = item_title,
                                  link = item_link,
                                  description = self.make_rss_item_desc(),
                                  guid = PyRSS2Gen.Guid(item_link),
                                  pubDate = datetime.datetime.now())
     return rss_item
Beispiel #2
0
    def get_feed(self, num=50):
        api = Twitter(auth=OAuth(
            self.config.access_token_key, self.config.access_token_secret,
            self.config.consumer_key, self.config.consumer_secret))

        rss = PyRSS2Gen.RSS2(self.title,
                             self.link,
                             self.description,
                             lastBuildDate=datetime.datetime.now(),
                             items=[])
        if self.statuses_file:
            twitter_statuses = open(self.statuses_file, 'w')
            twitter_statuses.write('')
            twitter_statuses.close()
            twitter_statuses = open(self.statuses_file, 'a')
        statuses_sum = api.statuses.home_timeline(count=num)

        statuses_sum.sort(key=lambda tweet: tweet['created_at'], reverse=False)

        for tweet in statuses_sum:
            tweet_text = tweet['text'].replace('і', 'i').replace(
                'є', 'je').replace('ї', 'ji').replace('Є', 'je').replace(
                    'Ї', 'ji').replace('І', 'I')
            item = PyRSS2Gen.RSSItem(title='@' + tweet['user']['screen_name'] +
                                     ': ' + tweet_text)
            tweet_url = r'https://twitter.com/' + tweet['user'][
                'screen_name'] + r'/status/' + tweet['id_str']
            if tweet['in_reply_to_status_id']:
                tweet_replied = api.statuses.show(
                    id=tweet['in_reply_to_status_id'])
                text_replied = tweet_replied['text']
                item.description = str(
                    r'In reply to: <a href=https://twitter.com/' +
                    tweet['in_reply_to_screen_name'] + r'/status/' +
                    tweet['in_reply_to_status_id_str'] + '>' +
                    tweet['in_reply_to_screen_name'] + '</a>: ' +
                    text_replied) + ' <br>The original text: ' + tweet_text
            else:
                item.description = r'<a href=' + tweet_url + '>tweet link</a><br> ' + tweet_text
            if tweet['entities']['urls']:
                item.link = tweet['entities']['urls'][0]['expanded_url']

            item.guid = PyRSS2Gen.Guid(tweet_url)
            item.pubDate = tweet['created_at']
            item.author = tweet['user']['name']

            rss.items.append(item)
            '''if self.statuses_file:
                twitter_statuses.write(tweet['user']['name']) + '\n'
                twitter_statuses.write(tweet['text']) + '\n'
			'''
        rss.write_xml(open(self.xml_out_file, "w"), encoding='utf-8')
        if self.statuses_file:
            twitter_statuses.close()
Beispiel #3
0
def generate_rss(f, e):
    """Generate rss"""
    for file in f[:10]:
        RSS.items.append(
            PyRSS2Gen.RSSItem(title=file['title'],
                              link=BASEURL + file['url'],
                              description=file['content'],
                              author="Ronan",
                              guid=PyRSS2Gen.Guid(BASEURL + file['url']),
                              pubDate=datetime.datetime(
                                  file['year'], file['month'], file['day'])))
    RSS.write_xml(open(DESTINATION + "feed.xml", "w"))
Beispiel #4
0
def make_rss_item(system_config, page_list, item, project_url):
    global rss_item_list
    location = "{0}/post/{1}".format(project_url, item["name"])
    raw_document = yield from file.async_read_file("./document/{0}.md".format(
        item["name"]))
    desc = yield from async_markdown(system_config, raw_document)
    rss_item_list[page_list.index(item)] = rss_item(
        title=item["title"],
        link=location,
        description=desc,
        guid=PyRSS2Gen.Guid(location),
        pubDate=datetime.datetime.fromtimestamp(item["time"]))
Beispiel #5
0
def rss_items(context, request):
    api = TemplateAPI(context, request)
    items = result_items(context, request)
    return [
        RSS2.RSSItem(
            title=item.title,
            link=api.url(item),
            description=item.description,
            guid=RSS2.Guid(api.url(item)),
            pubDate=item.modification_date,
        ) for item in items
    ]
def feed(items, data=FEED_DATA):
    return RSS2.RSS2(
        **data,
        items = [RSS2.RSSItem(
            title = i['title'],
            link  = i['link'],
            description = i['description'],
            guid  = RSS2.Guid(i['guid']),
            enclosure = RSS2.Enclosure(url=i['file'], type='audio/mpeg', length=i['bytes']),
            pubDate = i['date'],
        ) for i in items ]
    )
Beispiel #7
0
def getProductsList():
	forecast = define_source("http://www.met.ie/forecasts/")
	#forecast = forecast[0:1]


	response.headers['Content-Type'] = 'application/rss+xml'
	
	rss = PyRSS2Gen.RSS2(
	    title = "Andrew's PyRSS2Gen feed",
	    link = "http://www.dalkescientific.com/Python/PyRSS2Gen.html",
	    description = "The latest news about PyRSS2Gen, a "
	                  "Python library for generating RSS2 feeds",

	    lastBuildDate = datetime.datetime.now(),

	    items = [
	       PyRSS2Gen.RSSItem(
	         title = "PyRSS2Gen-0.0 released",
	         link = "http://www.dalkescientific.com/news/030906-PyRSS2Gen.html",
	         description = "Dalke Scientific today announced PyRSS2Gen-0.0, "
	                       "a library for generating RSS feeds for Python.  ",
	         guid = PyRSS2Gen.Guid("http://www.dalkescientific.com/news/"
	                          "030906-PyRSS2Gen.html"),
	         pubDate = datetime.datetime(2003, 9, 6, 21, 31)),
	       PyRSS2Gen.RSSItem(
	         title = "Thoughts on RSS feeds for bioinformatics",
	         link = "http://www.dalkescientific.com/writings/diary/"
	                "archive/2003/09/06/RSS.html",
	         description = "One of the reasons I wrote PyRSS2Gen was to "
	                       "experiment with RSS for data collection in "
	                       "bioinformatics.  Last year I came across...",
	         guid = PyRSS2Gen.Guid("http://www.dalkescientific.com/writings/"
	                               "diary/archive/2003/09/06/RSS.html"),
	         pubDate = datetime.datetime(2003, 9, 6, 21, 49)),
	    ])


	#rss.write_xml(open("pyrss2gen.xml", "w"))
	return rss.to_xml()
Beispiel #8
0
    def getAsRssItem(self):
        statinfo = os.stat(self.abs_filepath)
        file_length = statinfo.st_size

        return PyRSS2Gen.RSSItem(
            title=self.title,
            link=self.target_url,
            description="No Description for " + self.title,
            guid=PyRSS2Gen.Guid(self.target_url),
            pubDate=datetime.datetime.now(),
            enclosure=PyRSS2Gen.Enclosure(self.target_url, file_length,
                                          'audio/mpeg'),
        )
Beispiel #9
0
def get(date):
    time = date.strftime('%Y-%m-%d')
    data = []

    jsons = pool.map(lambda c: json.load(urllib.urlopen(URL.format(c, time))),
                     ['C', 'Q', 'Hp'])

    t = jsons[0]['contentEntity']
    data.append(
        gen.RSSItem(title=t['strContTitle'],
                    author=t['strContAuthor'],
                    description=t['strContent'],
                    link=t['sWebLk'],
                    pubDate=parse(t['strLastUpdateDate']),
                    guid=gen.Guid('content' + t['strContentId'])))

    t = jsons[1]['questionAdEntity']
    data.append(
        gen.RSSItem(title=t['strQuestionTitle'],
                    author='',
                    description=(t['strQuestionContent'] + '<br/><br/>' +
                                 t['strAnswerTitle'] + '<br/>' +
                                 t['strAnswerContent']),
                    link=t['sWebLk'],
                    pubDate=parse(t['strLastUpdateDate']),
                    guid=gen.Guid('question' + t['strQuestionId'])))

    t = jsons[2]['hpEntity']
    data.append(
        gen.RSSItem(title=t['strHpTitle'],
                    author=t['strAuthor'],
                    description=('<a href="{}"><img src="{}"></a><br/>'.format(
                        t['strOriginalImgUrl'], t['strThumbnailUrl']) +
                                 t['strContent']),
                    link=t['sWebLk'],
                    pubDate=parse(t['strLastUpdateDate']),
                    guid=gen.Guid('hp' + t['strHpId'])))
    return datetime.strptime(t['strMarketTime'], '%Y-%m-%d'), data
Beispiel #10
0
def append_rss_items(rss_feed, items):
    """Append items to rss feed object"""
    if not rssgen:
        return None
    for raw_entry in items:
        entry = rss_defaults.copy()
        entry.update(raw_entry)
        item = rssgen.RSSItem(title=entry["title"],
                              link=entry["link"],
                              description=entry["description"],
                              guid=rssgen.Guid(entry["guid"]),
                              pubDate=entry["publish_date"])
        rss_feed.items.append(item)
    return rss_feed
Beispiel #11
0
def makerss():
    lst_title = []
    lst_category = []
    lst_text = []
    lst_url = []
    lst_pubdate = []
    lst_author = []
    lst_reply = []
    lst_recom = []

    db = MySQLdb.connect(config.mysql_server,
                         config.mysql_id,
                         config.mysql_password,
                         config.mysql_db,
                         charset='utf8')
    curs = db.cursor(MySQLdb.cursors.DictCursor)

    rss = PyRSS2Gen.RSS2(title="clien_hot10",
                         link="http://www.clien.net",
                         description="RSS_clien_hot10",
                         lastBuildDate=datetime.datetime.now(),
                         items=[])

    rowcount = curs.execute("""SELECT * FROM rss order by sn DESC limit 80 """)

    for r in curs.fetchall():
        lst_title.append(r['title'])
        lst_category.append(r['category'])
        lst_text.append(r['text'])
        lst_url.append(r['url'])
        lst_pubdate.append(r['pubdate'])
        lst_author.append(r['author'])

        lst_reply.append(r['reply'])
        lst_recom.append(r['recom'])

    for i, title in enumerate(lst_title):
        tt = "[%s][%s]" % (str(lst_reply[i]), str(lst_recom[i]))
        item = PyRSS2Gen.RSSItem(
            title=lst_title[i] + tt,
            link='https://www.clien.net' + lst_url[i],
            guid=PyRSS2Gen.Guid('https://www.clien.net' + lst_url[i]),
            description=lst_text[i],
            # pubDate = datetime.datetime.fromtimestamp(lst_pubdate[i]),
            pubDate=lst_pubdate[i],
            author=lst_author[i])

        rss.items.append(item)

    rss.write_xml(open(BASEPATH + 'rss_clien_hot10.htm', 'w'))
Beispiel #12
0
    def _add_tweet(self, tweet):
        """Adds a Tweet. into the feed."""

        text = tweet.get('text', 'Twitter without text')

        item = PyRSS2Gen.RSSItem(title=text,
                                 link=tweet.get('url', 'Twitter without link'),
                                 description=text,
                                 guid=PyRSS2Gen.Guid(
                                     tweet.get('guid', 'Some guid')),
                                 pubDate=tweet.get('pubDate', None),
                                 author=tweet.get('author', None))

        self._rss_items.append(item)
Beispiel #13
0
def list_orders_feed(email):
    # browser hit this url, need to handle # TODO: Is this still used?
    # user auth for both use cases
    if 'Authorization' in request.headers:  # FIXME: pretty sure this is gone
        # coming in from bulk downloader
        logger.info("Apparent bulk download attempt, headers: %s" %
                    request.headers)
        auth_header_dec = base64.b64decode(request.headers['Authorization'])
        uauth = tuple(auth_header_dec.split(":"))
    else:
        if 'logged_in' not in session or session['logged_in'] is not True:
            return redirect(url_for('index', next=request.url))
        else:
            uauth = (session['user'].username, session['user'].wurd)
    orders = api_up("/list-orders/{}".format(email),
                    uauth=uauth,
                    json={'status': 'complete'})

    order_items = dict()
    for orderid in orders:
        item_status = api_up('/item-status/{}'.format(orderid), uauth=uauth)
        item_status = item_status.get(orderid, {})
        item_status = map(lambda x: Scene(**x), item_status)
        order_info = api_up('/order/{}'.format(orderid), uauth=uauth)
        order_items[orderid] = dict(scenes=item_status,
                                    orderdate=order_info['order_date'])

    rss = PyRSS2Gen.RSS2(
        title='ESPA Status Feed',
        link='http://espa.cr.usgs.gov/ordering/status/{0}/rss/'.format(email),
        description='ESPA scene status for:{0}'.format(email),
        language='en-us',
        lastBuildDate=datetime.datetime.now(),
        items=[])

    for orderid, order in order_items.items():
        for scene in order['scenes']:
            if scene.status != 'complete':
                continue
            description = ('scene_status:{0},orderid:{1},orderdate:{2}'.format(
                scene.status, orderid, order['orderdate']))
            new_rss_item = PyRSS2Gen.RSSItem(title=scene.name,
                                             link=scene.product_dload_url,
                                             description=description,
                                             guid=PyRSS2Gen.Guid(
                                                 scene.product_dload_url))

            rss.items.append(new_rss_item)

    return rss.to_xml(encoding='utf-8')
Beispiel #14
0
def build_rss(links, rssfile):
    rss = PyRSS2Gen.RSS2(
        title="brmzkw links feed",
        link="http://www.brmzkw.info",
        description="My tech readings",
        lastBuildDate=datetime.datetime.utcnow(),
        items=[
            PyRSS2Gen.RSSItem(title=item['url'],
                              link=item['url'],
                              description=' '.join(item['keywords']),
                              guid=PyRSS2Gen.Guid(item['url']),
                              pubDate=datetime.datetime.strptime(
                                  item['date'], '%Y/%m/%d')) for item in links
        ])
    rss.write_xml(rssfile)
def item_creator(new_paper):  # Create RSS-items out of all new papers
    items = []
    for paper in new_paper:
        heading = paper.snp + ": " + paper.title
        item = PyRSS2Gen.RSSItem(title=heading)
        description = "Written by " + paper.author + "\n"
        description = description + "Published in " + paper.journal + "\n"
        description = description + "Abstract: " + paper.abstract + "\n"
        description = description + "PMID: " + paper.pmid
        link = "http://www.ncbi.nlm.nih.gov/pubmed?term=" + paper.pmid
        item.description = description
        item.link = link
        item.guid = PyRSS2Gen.Guid(link)
        items.append(item)
    return items
Beispiel #16
0
def gen_rss(items):
    items_rss = []
    for item in items:
        rss_item = PyRSS2Gen.RSSItem(title=item['full_name'],
                                     link=item['url'],
                                     description=item['des'],
                                     guid=PyRSS2Gen.Guid(item['url']),
                                     pubDate=item['update_time'])
        items_rss.append(rss_item)
    rss = PyRSS2Gen.RSS2(title="private code feed",
                         link=code_url,
                         description="private code feed",
                         lastBuildDate=datetime.datetime.now(),
                         items=items_rss)
    rss.write_xml(open(file_path, 'w', encoding='utf-8'), encoding='utf-8')
Beispiel #17
0
 def __init__(self, base_url, rel_file, full_name):
     """
     Override PyRSS2Gen.RSSItem constructor to simplify constructor args for user
     """
     tag = TinyTag.get(rel_file)
     if tag.title is None:
         tag.title, ext = os.path.splitext(os.path.basename(rel_file))
     super().__init__(
         title=tag.title,
         link=urllib.parse.quote(rel_file),
         author=tag.artist,
         enclosure=PyRSS2Gen.Enclosure(base_url + "/" + urllib.parse.quote(rel_file), tag.filesize, "audio/mpeg"),
         guid=PyRSS2Gen.Guid(hashlib.sha256(full_name.encode('utf-8')).hexdigest(), isPermaLink=False),
         pubDate=tag.year
     )
Beispiel #18
0
def pageToRSS(page,args):
    try:
        url = "https://%s/%s" % (getDomain(args),page['publishPath'])
        item = PyRSS2Gen.RSSItem(
            title = page['title'],
            link = url,
            description = page['description'],
            guid = PyRSS2Gen.Guid(url),
            pubDate = dt.datetime.combine(page['date']['original'], dt.datetime.min.time())
        )
    except KeyError as e:
        print("Error generating RSS entry for page")
        pp.pprint(page)
        raise(e)

    return(item)
Beispiel #19
0
 def generate_rss(self):
     rss = PyRSS2Gen.RSS2(title=conf.SITE_NAME,
                          link=conf.SITE_URL,
                          description=conf.SITE_DESCRIPTION,
                          lastBuildDate=datetime.datetime.utcnow(),
                          items=[])
     for i, e in enumerate(self.feed):
         item = PyRSS2Gen.RSSItem(title=e['title'],
                                  link=e['link'],
                                  description=e['description'],
                                  guid=PyRSS2Gen.Guid(e['link']),
                                  pubDate=datetime.datetime.fromtimestamp(
                                      e['pubDate']))
         rss.items.append(item)
         if i == 15: break
     rss.write_xml(open(os.path.join(conf.OUTPUT_PATH, "feed.xml"), "w"))
Beispiel #20
0
 def _generate_xml_rss(self):
     posts = []
     for link, content in iter(
             self.content_aggregator.get_latest_posts().items()):
         link = "{0}/{1}".format(self.config['site']['url'], link)
         posts.append(
             PyRSS2Gen.RSSItem(title=content['page_title'],
                               link=link,
                               description=content['page_briefing'],
                               guid=PyRSS2Gen.Guid(link),
                               pubDate=content['page_date_time']))
     return PyRSS2Gen.RSS2(title=self.config['site']['title'],
                           link=self.config['site']['url'],
                           description=self.config['site']['briefing'],
                           lastBuildDate=datetime.now(),
                           items=posts)
Beispiel #21
0
    def gallery_rss(self, img_list, dest_img_list, img_titles, lang, permalink,
                    output_path, title):
        """Create a RSS showing the latest images in the gallery.

        This doesn't use generic_rss_renderer because it
        doesn't involve Post objects.
        """
        def make_url(url):
            return urljoin(self.site.config['BASE_URL'], url.lstrip('/'))

        items = []
        for img, srcimg, title in list(zip(
                dest_img_list, img_list, img_titles))[:self.kw["feed_length"]]:
            img_size = os.stat(
                os.path.join(self.site.config['OUTPUT_FOLDER'], img)).st_size
            args = {
                'title':
                title,
                'link':
                make_url(img),
                'guid':
                rss.Guid(img, False),
                'pubDate':
                self.image_date(srcimg),
                'enclosure':
                rss.Enclosure(make_url(img), img_size,
                              mimetypes.guess_type(img)[0]),
            }
            items.append(rss.RSSItem(**args))
        rss_obj = rss.RSS2(title=title,
                           link=make_url(permalink),
                           description='',
                           lastBuildDate=datetime.datetime.utcnow(),
                           items=items,
                           generator='http://getnikola.com/',
                           language=lang)

        rss_obj.rss_attrs["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"
        rss_obj.self_url = make_url(permalink)
        rss_obj.rss_attrs["xmlns:atom"] = "http://www.w3.org/2005/Atom"
        dst_dir = os.path.dirname(output_path)
        utils.makedirs(dst_dir)
        with io.open(output_path, "w+", encoding="utf-8") as rss_file:
            data = rss_obj.to_xml(encoding='utf-8')
            if isinstance(data, utils.bytes_str):
                data = data.decode('utf-8')
            rss_file.write(data)
def getDetails(url, baseURL):
    page = urllib2.urlopen(url).read()
    soup = BeautifulSoup(page)
    date = soup.findAll('date')[0].text
    pubDate = datetime.datetime.strptime(date, "%A %B %d,%Y")
    img = soup.findAll('div', {'class': 'img-comic-container' })[0].find('img')['src']

    results = {}
    results['item'] = PyRSS2Gen.RSSItem(
        title = 'Dilbert comic for ' + pubDate.strftime("%B %d, %Y"),
        description = "<a href='" + url + "'><img src='" + str(img) + "' /></a>",
        pubDate = pubDate,
        link = url,
        guid = PyRSS2Gen.Guid(url)
    )
    results['prev_href'] = soup.findAll('div', {'class': re.compile('nav-left')})[0].find('a')['href']
    return results
Beispiel #23
0
def list_orders_feed(email):
    # bulk downloader and the browser hit this url, need to handle
    # user auth for both use cases
    url = "/list-orders-feed/{}".format(email)
    if 'Authorization' in request.headers:
        # coming in from bulk downloader
        logger.info("Apparent bulk download attempt, headers: %s" %
                    request.headers)
        auth_header_dec = base64.b64decode(request.headers['Authorization'])
        response = api_get(url, uauth=tuple(auth_header_dec.split(":")))
    else:
        if 'logged_in' not in session or session['logged_in'] is not True:
            return redirect(url_for('login', next=request.url))
        else:
            response = api_get(url)

    if "msg" in response:
        logger.info("Problem retrieving rss for email: %s \n message: %s\n" %
                    (email, response['msg']))
        status_code = 404
        if "Invalid username/password" in response['msg']:
            status_code = 403
        return jsonify(response), status_code
    else:
        rss = PyRSS2Gen.RSS2(
            title='ESPA Status Feed',
            link='http://espa.cr.usgs.gov/ordering/status/{0}/rss/'.format(
                email),
            description='ESPA scene status for:{0}'.format(email),
            language='en-us',
            lastBuildDate=datetime.datetime.now(),
            items=[])

        for item in response:
            for scene in response[item]['scenes']:
                description = 'scene_status:{0},orderid:{1},orderdate:{2}'.format(
                    scene['status'], item, response[item]['orderdate'])
                new_rss_item = PyRSS2Gen.RSSItem(title=scene['name'],
                                                 link=scene['url'],
                                                 description=description,
                                                 guid=PyRSS2Gen.Guid(
                                                     scene['url']))

                rss.items.append(new_rss_item)

        return rss.to_xml(encoding='utf-8')
Beispiel #24
0
def create_rss_feed(poemlink):
    rss = PyRSS2Gen.RSS2(
        title="Jason's PF feed",
        link=poemlink,
        description="Poem of the day",
        lastBuildDate=datetime.now(),
        items=[
            PyRSS2Gen.RSSItem(
                title=f"Poem for {date.today()}",
                link=poemlink,
                guid=PyRSS2Gen.Guid(f"Poem for {date.today()}"),
                pubDate=datetime.now(),
            ),
        ],
    )

    rss.write_xml(open("poem.xml", "w"))
Beispiel #25
0
def create_rss(info: Program, stuff):
    rss = PyRSS2Gen.RSS2(
        title=info.name,
        link="http://fake-link.com",
        description="podcast description",
        lastBuildDate=datetime.now(),
        items=[
            PyRSS2Gen.RSSItem(
                title=s["title"],
                description=s["description"],
                guid=PyRSS2Gen.Guid(s["audio_url"]),
                enclosure=PyRSS2Gen.Enclosure(s["audio_url"], 0, "audio/mpeg"),
                pubDate=s["date"],
            )
            for s in stuff
        ],
    )
    return rss
Beispiel #26
0
def feed():
    prefix = '://'.join(request.urlparts[:2])
    title = 'Malaysian Bill Watcher'
    link = prefix + '/'
    description = 'This is an app for Malaysian to see bill being passed by the Parliament'

    lastBuildDate = datetime.datetime.utcnow()

    session = models.DBSession()
    bills = (session.query(models.Bill).join(
        (models.Bill.bill_revs,
         models.BillRevision)).order_by(models.BillRevision.update_date).all())

    items = []
    for bill in bills[-1:-101:-1]:
        _rev = bill.bill_revs[0]
        _title = bill.long_name
        _description = "year: %s\n" \
  "status: %s\n" \
  "url: %s\n" \
  "name: %s\n" \
  "read_by: %s\n" \
  "supported_by: %s\n" \
  "date_presented: %s" % \
  (_rev.year, _rev.status, _rev.url, bill.name, _rev.read_by,
        _rev.supported_by, _rev.date_presented)
        _link = prefix + '/detail/%s/' % (_rev.id)
        _pubDate = _rev.update_date
        _guid = PyRSS2Gen.Guid(_link)
        item = PyRSS2Gen.RSSItem(title=_title,
                                 description=_description,
                                 link=_link,
                                 guid=_guid,
                                 pubDate=_pubDate)
        items.append(item)

    rss = PyRSS2Gen.RSS2(title=title,
                         link=link,
                         description=description,
                         items=items)
    output = cStringIO.StringIO()
    rss.write_xml(output)
    response.content_type = 'application/rss+xml'
    return output.getvalue()
Beispiel #27
0
def create_feed(feed_info,
                output_stream,
                encoding=DEFAULT_ENCODING,
                max_threads=DEFAULT_MAX_THREADS):
    logger.info("Creating feed \"" + feed_info['title'] + "\".")

    result_feed = []
    with concurrent.futures.ThreadPoolExecutor(
            max_workers=max_threads) as executor:
        future = executor.map(fetch_feed, feed_info['feeds'])
        for feed in future:
            result_feed.extend(feed)

    # Sorting (just to be sure)
    result_feed = sorted(result_feed,
                         key=lambda k: k['published_parsed'],
                         reverse=True)
    # Truncating
    del result_feed[feed_info['size']:]

    # Creating the feed
    rss_items = []
    for item in result_feed:
        rss_items.append(
            PyRSS2Gen.RSSItem(
                title=item['title'],
                link=item['link'],
                description=item['summary'],
                guid=PyRSS2Gen.Guid(item['link']),
                pubDate=format_date(item['published_parsed']),
            ))

    rss = PyRSS2Gen.RSS2(title=feed_info['title'],
                         link=feed_info['link'],
                         description=feed_info['summary'],
                         lastBuildDate=now,
                         items=rss_items)

    logger.info("Writing to stream (encoding: %s)..." % encoding)
    if encoding is DEFAULT_ENCODING:
        rss.write_xml(output_stream, encoding)
    else:
        xml = rss.to_xml(encoding=DEFAULT_ENCODING)
        output_stream.write(xml.encode(DEFAULT_ENCODING).decode(encoding))
Beispiel #28
0
 def generate_feed_items(self):
     self.cursor.execute(
         "select * from posts order by timestamp desc limit 10")
     from_db = self.cursor.fetchall()
     posts = list()
     files = list()
     for (id_, text, enclosure_url, enclosure_media_type,
          timestamp) in from_db:
         post = RSS2.RSSItem(
             title=text,
             description=text,
             link=self.base_url + "%s.html" % id_,
             guid=RSS2.Guid(self.base_url + "%s.html" % id_),
             pubDate=formatdate(
                 totimestamp(dateutil.parser.parse(timestamp))))
         if enclosure_url is not None:
             post.enclosure = RSS2.Enclosure(url=enclosure_url,
                                             type=enclosure_media_type,
                                             length=0)
         posts.append(post)
         html_output = Template(self.template).render(
             rss_title=self.title,
             rss_link=self.link,
             rss_description=self.description,
             rss_feed_link=self.base_url + self.rss_filename,
             post_title=text,
             post_description=text,
             post_timestamp=timestamp,
             post_id=id_,
             enclosure_url=enclosure_url,
             enclosure_media_type=enclosure_media_type)
         html_fname = os.path.join(self.output_dir, "%s.html" % id_)
         with open(html_fname, "wb") as fh:
             fh.write(html_output)
         files.append(html_fname)
     rss = RSS2.RSS2(title=self.title,
                     link=self.link,
                     description=self.description,
                     lastBuildDate=datetime.datetime.utcnow(),
                     items=posts)
     rss_fname = os.path.join(self.output_dir, self.rss_filename)
     rss.write_xml(open(rss_fname, "wb"))
     files.append(rss_fname)
     return files
Beispiel #29
0
def users_rss_private(user_hash):
    import datetime
    import PyRSS2Gen as RSS2

    parts = user_hash.split('_')

    if (len(parts) > 0):
        user_id = parts[0]
        rss_hash = parts[1]

        try:
            user = User.objects(id=user_id)[0]
        except IndexError:
            return 'Wrong hash!'
        else:
            # Check rss hash
            if (user.rss_hash() == rss_hash):
                notes = Note.objects(user=user).order_by('-created_at')[:20]
                notes_items = []

                for note in notes:
                    notes_items.append(
                        RSS2.RSSItem(
                            title=note.title,
                            link=note.get_url_rss(),
                            description=note.get_dropbox_content(),
                            guid=RSS2.Guid("http://jabjot.com/notes/" +
                                           str(note.id)),
                            pubDate=note.created_at))

                rss = RSS2.RSS2(
                    title=user.username + "'s private notes feed - jabjot",
                    link="http://jabjot.com/user/rss/private/" + str(user.id) +
                    '_' + user.rss_hash(),
                    description=user.username + "'s latest notes.",
                    lastBuildDate=datetime.datetime.utcnow(),
                    items=notes_items)

                return rss.to_xml(encoding='utf-8')
            else:
                return 'Wrong hash!'
    else:
        return 'Wrong hash!'
Beispiel #30
0
def generate_rss(articles):
    """Generates RSS feed of Blog Articles."""
    rss_items = []

    for article in articles:
        article_link = BLOG_URL + article['html_file']

        rss_items.append(
            PyRSS2Gen.RSSItem(title=article['friendly_name'],
                              link=article_link,
                              guid=PyRSS2Gen.Guid(article_link),
                              pubDate=get_article_ts(article['html_file'])))

    rss = PyRSS2Gen.RSS2(title=BLOG_TITLE,
                         description=BLOG_DESCRIPTION,
                         link=BLOG_URL,
                         lastBuildDate=datetime.datetime.utcnow(),
                         items=rss_items)
    rss.write_xml(open('index.xml', 'w'))