Пример #1
0
def post2rss(post, digest=False, pic=None):
    if post['type'] == 'answer':
        title = '[回答] %s' % post['question']['title']
        url = 'https://www.zhihu.com/question/%s/answer/%s' % (
            post['question']['id'], post['id'])
        t_c = post['created_time']

    elif post['type'] == 'article':
        title = '[文章] %s' % post['title']
        url = 'https://zhuanlan.zhihu.com/p/%s' % post['id']
        t_c = post['created']

    elif post['type'] in ['roundtable', 'live', 'column']:
        return
    else:
        logger.warn('unknown type: %s', post['type'])
        return

    if digest:
        content = post['excerpt']
    else:
        content = post['content']

    content = content.replace('<code ', '<pre><code ')
    content = content.replace('</code>', '</code></pre>')

    doc = fromstring(content)
    tidy_content(doc)
    if pic:
        base.proxify_pic(doc, re_zhihu_img, pic)
    content = tostring(doc, encoding=str)

    pub_date = datetime.datetime.fromtimestamp(t_c)

    item = PyRSS2Gen.RSSItem(
        title=title.replace('\x08', ''),
        link=url,
        description=content.replace('\x08', ''),
        pubDate=pub_date,
        author=post['author']['name'],
    )
    return item
    def render(self, request):

        data = self.construct()
        rss_items = []
        for item in data:
            rss_items.append(
                PyRSS2Gen.RSSItem(
                    title=item['title'],
                    description=item['synopsis'],
                    link=item['url'],
                    pubDate=item['date_created'],
                ))

        rss = PyRSS2Gen.RSS2(title="RSS for Something",
                             link="http://news.something.com",
                             description="Test",
                             lastBuildDate=datetime.datetime.utcnow(),
                             items=rss_items)

        return rss.to_xml(encoding="utf-8")
Пример #3
0
def getNetatmoData():
    authorization = lnetatmo.ClientAuth()
    devList = lnetatmo.WeatherStationData(authorization)

    when = datetime.fromtimestamp(int(devList.lastData()['Balcon']['When']))

    string = str(
        devList.lastData()['Balcon']['Temperature']) + " °C at " + str(
            datetime.fromtimestamp(int(devList.lastData()['Balcon']['When'])).
            strftime('%d-%m-%Y %H:%M:%S'))

    rss.items = [
        PyRSS2Gen.RSSItem(title=string,
                          link="",
                          description=string,
                          pubDate=when)
    ]

    rss.lastBuildDate = when
    rss.write_xml(open("/pyrss2gen.xml", "w"))
Пример #4
0
def show(name):
    rss = PyRSS2Gen.RSS2(title=name,
                         link="https://github.com/miaowm5",
                         description="RSSGen By Miaowm5")
    for e in get_all_feed(name):
        title = e.get('title')
        time = e.get('time')
        time = datetime(*(time.utctimetuple()[0:6]))
        link = e.get('link')
        content = e.get('content')
        item = PyRSS2Gen.RSSItem(title=title,
                                 pubDate=time,
                                 link=link,
                                 description=content)
        rss.items.append(item)
    r = rss.to_xml(encoding='utf-8')
    return r.replace(
        '<rss version="2.0">',
        '<?xml-stylesheet type="text/xsl" href="../static/xml_style.xsl" ?><rss version="2.0">'
    )
Пример #5
0
 def export_rss(self):
     url_base = 'http://' + self.request.headers.get('host', 'events.hackerdojo.com')
     events = Event.get_recent_past_and_future()
     rss = PyRSS2Gen.RSS2(
         title = "Hacker Dojo Events Feed",
         link = url_base,
         description = "Upcoming events at the Hacker Dojo in Mountain View, CA",
         lastBuildDate = datetime.now(),
         items = [PyRSS2Gen.RSSItem(
                     title = "%s @ %s: %s" % (
                         event.start_time.strftime("%A, %B %d"),
                         event.start_time.strftime("%I:%M%p").lstrip("0"), 
                         event.name),
                     link = url_base + event_path(event),
                     description = event.details,
                     guid = url_base + event_path(event),
                     pubDate = event.updated,
                     ) for event in events]
     )
     return 'application/xml', rss.to_xml()
Пример #6
0
    def parse_detail(self, response):
        title_xpath = "//title/text()"
        detail_xpath = '//div[@class="eltd-text-holder"]'

        title = response.xpath(title_xpath).extract()[0].split("|")[0]
        detail = response.xpath(detail_xpath).extract()[0]
        date = response.xpath(
            '//div[@class="eltd-post-info-date"]/text()').extract()[0].strip()
        url = response.url
        item = RssclientItem()
        rss_item = PyRSS2Gen.RSSItem(title=title,
                                     link=url,
                                     description=detail,
                                     guid=PyRSS2Gen.Guid(url),
                                     pubDate=datetime.datetime.strptime(
                                         date, '%Y-%m-%d'))
        rss.items.append(rss_item)
        item["rss"] = rss
        if len(rss.items) == 35:
            return item
Пример #7
0
def comment2rss(url, comment):
    rid = comment.get('id')
    url = '%s#%s' % (url, rid)
    content = comment.xpath('.//div[@class="reply_content"]')[0]
    author = comment.xpath('.//strong/a')[0].text
    content_text = content.text_content()
    if len(content_text) > 30:
        title = "%s 说: %s……" % (author, content_text[:30])
    else:
        title = "%s 说: %s" % (author, content_text)

    content = tostring(content, encoding=str).strip().replace('\r', '')

    item = PyRSS2Gen.RSSItem(
        title=title,
        link=url,
        description=content,
        author=author,
    )
    return item
Пример #8
0
def addRSSPass(satellite, filename, date):

    # Generate item content, here being images
    image = ""
    if satellite.downlink == "APT":
        image = "Visible + Infrared : <\p>" + "<img src=\"" + filename + ".png\">"
    elif satellite.downlink == "LRPT":
        image = "Visible : <\p>" + "<img src=\"" + filename + " - Visible.png\">" + "<\p>" + "Infrared : <\p>" + "<img src=\"" + filename + " - Infrared.png\">"

    # Add it to the feed
    rss.items.append(PyRSS2Gen.RSSItem(
        title = satellite.name + " on " + date.strftime('%H:%-M %d, %b %Y'),
        link = "",
        description = image,
        guid = PyRSS2Gen.Guid(""),
        pubDate = date)
    )

    # Write the file to push the update
    rss.write_xml(open(config.output_dir + "/rss.xml", "w"))
Пример #9
0
def videos2rss(videos):
    items = []
    videos = sorted(videos, key=cmp)
    videos = videos[:100]
    for video in videos:
        item = PyRSS2Gen.RSSItem(title=video2title(video),
                                 description=video2des(video),
                                 link=video2link(video),
                                 author=video2author(video),
                                 comments=video2pic(video),
                                 guid=video2bvid(video),
                                 pubDate=video2time(video))
        items.append(item)
    rss = PyRSS2Gen.RSS2(
        title='bilibili',
        link='https://gitee.com/shuifengche/rss/raw/master/bili.xml',
        description='bilibili',
        lastBuildDate=datetime.datetime.utcnow(),
        items=items)
    rss.write_xml(open('bilibili.xml', 'w'), encoding='utf-8')
Пример #10
0
def main():
    # create output feed
    rss = PyRSS2Gen.RSS2(title="{{{FEEDNAME}}}",
                         link="",
                         description="",
                         lastBuildDate=datetime.datetime.now())

    # parse input lines
    for line in fileinput.input():
        (title, link, description, updated) = line.split("\t")

        # insert item into output feed
        rss.items.append(
            PyRSS2Gen.RSSItem(title=title,
                              link=link,
                              description=description,
                              pubDate=updated))

    # done, write out entire feed
    rss.write_xml(sys.stdout)
Пример #11
0
def tweet_to_rss_item(tweet_data):
    """
    Converts a single tweet to an RSS item.

    Inputs:
    - tweet_data: a dictionary with selected status fields, coming
                  from process_tweet_items().

    Outputs:
    - rss_item: a properly formatted PyRSS2Gen.RSSItem object.
    """
    link = tweet_data['urls'][0] if tweet_data['urls'] else tweet_data[
        'source_url']
    title = "@%s: %s" % (tweet_data['screen_name'], tweet_data['text'])
    rss_item = PyRSS2Gen.RSSItem(title=title,
                                 link=link,
                                 guid=PyRSS2Gen.Guid(link),
                                 pubDate=tweet_data['created_at'],
                                 description=tweet_data['text_html'])
    return (rss_item)
Пример #12
0
 def getcontent(self, total):
     rsp = self.request(self.baseurl, self.cookies, self.proxies)
     soup = BeautifulSoup(rsp)
     ul = soup.find('div', {'id': 'browse-items-primary'})
     count = 0
     for li in ul.findAll('div', {'class': 'yt-lockup-content'}):
         if count == total:
             print(count)
             break
         h3 = li.find('h3')
         thumbnail = li.find_previous('div',
                                      {'class': 'yt-lockup-thumbnail'})
         if h3 is not None:
             alink = h3.find('a')
             if alink is not None:
                 title = alink.get('title')
                 link = alink.get('href')
                 #img= thumbnail.find('span',{'class':'yt-thumb-simple'}).find('img')
         div = li.find('div', {'class': 'yt-lockup-byline'})
         if div is not None:
             author = div.find('a')
             if author is not None:
                 fromwhere = author.get_text()
             else:
                 fromwhere = ''
         div = li.find('div', {'class': 'yt-lockup-description'})
         img1 = '<br><img src=' + 'https://i.ytimg.com/vi/' + link.split(
             '=')[1] + '/hqdefault.jpg' + '><br>'
         img2 = '<a href=' + 'https://i.ytimg.com/vi/' + link.split(
             '='
         )[1] + '/maxresdefault.jpg' + '>https://i.ytimg.com/vi/' + link.split(
             '=')[1] + '/maxresdefault.jpg</a><br>'
         rss = PyRSS2Gen.RSSItem(
             title=title,
             link="https://www.youtube.com" + link,
             author=fromwhere,
             description=img1 + img2,
         )
         print(title, link, fromwhere, img1 + img2)
         self.myrss.items.append(rss)
         count += 1
Пример #13
0
def rss_wall(page, opener):
    data = []
    parsedPage = etree.HTML(page)
    divs = parsedPage.xpath("//div")
    for div in divs:
        try:
            if div.attrib['class'] == "app_wall_item_container":
                l = len(div)
                if l == 3:
                    idata = []
                    for element in div:
                        if element.attrib['class'] == "app_wall_item_content":
                            bs = element.xpath(".//b")
                            for b in bs:
                                if b.attrib['class'] == "wallTit":
                                    linkdeb = b.xpath(".//a")[0]
                                    idata.append(linkdeb.text.encode("utf-8"))
                                    idata.append(
                                        linkdeb.attrib['href'].encode("utf-8"))
                            spans = element.xpath(".//span")
                            for span in spans:
                                if span.attrib['class'] == "wallFecha":
                                    idata.append(span.text.encode("utf-8"))
                                if span.attrib['class'] == "wallDescr":
                                    idata.append(span.text.encode("utf-8"))
                    data.append(idata)
        except:
            pass
    items = [
        PyRSS2.RSSItem(title=d[0], link=d[1], description=d[2] + ": " + d[3])
        for d in data
    ]

    rss = PyRSS2.RSS2(
        title="Wall Emagister",
        link=("http://localhost:8080/statics/feeds/wall.rss"),
        description="",
        lastBuildDate=dt.utcnow(),
        items=items,
    )
    rss.write_xml(open("static/feeds/wall.rss", "w"))
Пример #14
0
def add_rss_item(status, msg, direction):
    if direction == "in":
        feed = status.feed_in
        title = "%s %s entered NEW" % (msg['Source'], msg['Version'])
        pubdate = msg['Date']
    elif direction == "out":
        feed = status.feed_out
        if 'Leave-Reason' in msg:
            title = "%s %s left NEW (%s)" % (msg['Source'], msg['Version'],
                                             msg['Leave-Reason'][0])
        else:
            title = "%s %s left NEW" % (msg['Source'], msg['Version'])

        pubdate = datetime.utcnow()
    else:
        return False

    description = "<pre>Description: %s\nChanges: %s\n</pre>" % \
            (cgi.escape(msg['Description']),
             cgi.escape(msg['Changes']))

    link = "https://ftp-master.debian.org/new/%s_%s.html" % \
            (msg['Source'], msg['Version'])
    guid = msg['Checksums-Sha256'][0]['sha256']

    if 'Processed-By' in msg:
        author = msg['Processed-By']
    else:
        changedby = parseaddr(msg['Changed-By'])
        author = "%s (%s)" % (changedby[1], changedby[0])

    feed.items.insert(0,
        PyRSS2Gen.RSSItem(
            title,
            pubDate=pubdate,
            description=description,
            author=cgi.escape(author),
            link=link,
            guid=guid
        )
    )
Пример #15
0
 def export_rss(self):
     url_base = 'http://' + self.request.headers.get(
         'host', 'events.hackerdojo.com')
     events = Event.all().filter(
         'status IN', ['approved', 'canceled']).order('start_time')
     rss = PyRSS2Gen.RSS2(
         title="Hacker Dojo Events Feed",
         link=url_base,
         description=
         "Upcoming events at the Hacker Dojo in Mountain View, CA",
         lastBuildDate=datetime.now(),
         items=[
             PyRSS2Gen.RSSItem(
                 title=event.name,
                 link=url_base + event_path(event),
                 description=event.details,
                 guid=url_base + event_path(event),
                 pubDate=event.updated,
             ) for event in events
         ])
     return 'application/xml', rss.to_xml()
Пример #16
0
def add_rss_feed(rss_feed, external_rss_link):
    """
    Add all the posts of link (rssfeed) to rss_feed
    :param rss_feed: rss feed to publish on
    :param external_rss_link: rss feed that has the posts
    """
    feed = feedparser.parse(external_rss_link)
    for item in feed['items']:
        title = item['title']
        try:
            external_rss_link = item['external_rss_link']
        except KeyError:
            external_rss_link = None

        description = item['description']
        pubdate = item['published']
        new_item = PyRSS2Gen.RSSItem(title=title,
                                     link=external_rss_link,
                                     description=description,
                                     pubDate=pubdate)
        rss_feed.items.insert(0, new_item)
Пример #17
0
def generate_rss(notifications):
    items = []
    for notification in notifications:
        title = "[" + notification["repository"]["name"] + "] " + \
            notification["subject"]["title"]
        description = "[" + notification["reason"] + "] " + \
            notification["subject"]["type"]
        items.append(
            PyRSS2Gen.RSSItem(title=title,
                              link=notification["subject"]["url"],
                              description=description,
                              guid=PyRSS2Gen.Guid(notification["url"]),
                              pubDate=dt.strptime(notification["updated_at"],
                                                  "%Y-%m-%dT%H:%M:%S%z")))
    rss = PyRSS2Gen.RSS2(
        title="GitHub Notifications Feed",
        link="https://github.com/notifications",
        description="The latest notifications from your GitHub account.",
        lastBuildDate=datetime.datetime.now(),
        items=items)
    rss.write_xml(open("./output/feed.xml", "w"))
Пример #18
0
def post2rss(baseurl, post, *, digest=False, pic=None):
    url = urljoin(baseurl, post['url'])
    if digest:
        content = post['summary']
    elif post.get('titleImage'):
        content = '<p><img src="%s"></p>' % post['titleImage'] + post['content']
    else:
        content = post['content']

    content = process_content(content)
    if pic is not None:
        content = proxify_pic(content, pic)

    item = PyRSS2Gen.RSSItem(
        title=post['title'].replace('\x08', ''),
        link=url,
        description=content,
        pubDate=parse_time(post['publishedTime']),
        author=post['author']['name'],
    )
    return item
Пример #19
0
 def outputRSS(sets):
     articles = db.query(mPosts).order_by(sa.desc(mPosts.times)).limit(12)
     items = []
     for article in articles:
         content = md.html(article.content, extensions=md.EXT_STRIKETHROUGH)
         url = sets['url'] + 'p/' + str(article.times)
         items.append(
             PyRSS2Gen.RSSItem(
                 title=article.title,
                 link=url,
                 description=content,
                 guid=PyRSS2Gen.Guid(url),
                 pubDate=datetime.datetime.fromtimestamp(
                     float(article.times)),
             ))
     rss = PyRSS2Gen.RSS2(title=sets['title'],
                          link=sets['url'],
                          description=sets['desc'],
                          lastBuildDate=datetime.datetime.now(),
                          items=items).to_xml()
     return rss
Пример #20
0
    def enterpage(self,url):
        # pattern = re.compile(r'\d{4}\S\d{2}\S\d{2}\s\d{2}\S\d{2}')
        rsp=self.useragent(url)
        soup=BeautifulSoup(rsp)
        timespan=soup.find('div',{'class':'BlogStat'})
        timespan=str(timespan).strip().replace('\n','').decode('utf-8')
        match=re.search(r'\d{4}\S\d{2}\S\d{2}\s\d{2}\S\d{2}',timespan)
        timestr=str(datetime.date.today())
        if match:
            timestr=match.group()
            #print timestr
        ititle=soup.title.string
        div=soup.find('div',{'class':'BlogContent'})
        rss=PyRSS2Gen.RSSItem(
                              title=ititle,
                              link=url,
                              description = str(div),
                              pubDate = timestr
                              )

        return rss
Пример #21
0
def writeRSS(name, pubs):
    title = name
    link = ""
    description = ""
    lastBuildDate = datetime.datetime.now()
    try:
        items = [
            PyRSS2Gen.RSSItem(title=p["Title"],
                              link=p["URL"],
                              description=p["Abstract"],
                              guid=PyRSS2Gen.Guid(link)) for p in pubs
        ]
    except KeyError:
        print KeyError
        pass
    rss = PyRSS2Gen.RSS2(title=title,
                         link=link,
                         description=description,
                         lastBuildDate=lastBuildDate,
                         items=items)
    rss.write_xml(open(name + ".xml", "w"))
Пример #22
0
def generate_rss_feed(request, task_pair):
    rss = PyRSS2Gen.RSS2(
        title=task_pair.effect_options['feed_title'],
        link=task_pair.effect_options['feed_link'],
        description=task_pair.effect_options['feed_description'],
        lastBuildDate=datetime.datetime.now(),
        items=[
            PyRSS2Gen.RSSItem(title=event['item_title'],
                              link=event['item_link'],
                              description=event['item_description'],
                              guid=PyRSS2Gen.Guid(event['item_guid']),
                              pubDate=datetime.datetime.strptime(
                                  event['item_pubdate'][:19],
                                  '%Y-%m-%dT%H:%M:%S'))
            for event in get_from_event_store(task_pair.id, 'effect')
        ])
    strio = StringIO()
    rss.write_xml(strio)
    strio.seek(0)

    return HttpResponse(strio.read(), content_type='application/rss+xml')
Пример #23
0
def gen_rss(index, logs):
    global entry_count
    rss_items = []

    if not entry_count: 
        entry_count = len(logs)
    else:
        entry_count = int(entry_count)
    if entry_count > len(logs):
        entry_count = len(logs)

    for i in range(entry_count):
        file = codecs.open(logs[i], encoding="utf-8")

        # first line is title
        entry_title = file.readline().strip('\n')
        entry_link = "http://www.uludag.org.tr/bulten/arsiv/"+basename(logs[i])[:-3]+"html"
        entry_desc = file.read()
        mtime = index.get_mtime(logs[i])
        entry_date = ctime(mtime)
        # SACMALIK: tarih RFC822 standardinda yazilmali, fakat boye de yapilmaz :(
        t = entry_date.split()
        entry_date = " ".join([t[0]+",", t[2], t[1], t[4], t[3]+" GMT"])

        rss_items.append(PyRSS2Gen.RSSItem(
                title = entry_title,
                link = entry_link,
                description = entry_desc,
                guid = PyRSS2Gen.Guid(entry_link),
                pubDate = entry_date))

    rss = PyRSS2Gen.RSS2(
	title = "Uludağ Bülteni",
	link = "http://www.uludag.org.tr",
	description = "Uludağ Bülteni",
	lastBuildDate = datetime.datetime.now(),
	items = rss_items
	)
                                                                            
    rss.write_xml(open("bulten.xml", "w"))
Пример #24
0
def gen_rss():
    rss_items = []
    for i in pure_data:
        link = config['site_real_rt'] + i['link']
        text = i['content'][0:config['preview_len']]
        res = ''
        text = text.split('\n\n')
        for x in text:
            res += '<p>' + x + '</p>'
        res += "<a href=%s target='_blank'>阅读全文</a>" % link
        rss_items.append(
            PyRSS2Gen.RSSItem(title=i["title"],
                              link=link,
                              description=res,
                              guid=PyRSS2Gen.Guid(link)))
    rss = PyRSS2Gen.RSS2(title=config['site_name'],
                         link=config['site_url'],
                         description=config['site_name'],
                         lastBuildDate=last_build_time,
                         items=rss_items)
    rss.write_xml(open(dest + "/atom.xml", "w", encoding='utf-8'),
                  encoding='utf-8')
Пример #25
0
def generate_rss(packages, herd):
    """Return dynamic RSS feed for given packages"""
    if not packages.count():
        return """<?xml version="1.0" encoding="iso-8859-1"?><rss version="2.0"><channel><title>Meatoo - Gentoo vs. Freshmeat Releases</title><link>http://meatoo.gentooexperimental.org/</link><description>The latest Freshmeat releases with matching Gentoo versions.</description><lastBuildDate>%s</lastBuildDate><generator>PyRSS2Gen-0.1.1</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Herd %s has no entries.</title><link>http://meatoo.gentooexperimental.org/</link><description>There are no entries for %s</description><pubDate>%s</pubDate></item></channel></rss>""" % (datetime.datetime.utcnow(), herd, herd, datetime.datetime.utcnow())
    items = []
    for pkg in packages:
        items.append(PyRSS2Gen.RSSItem(
            title = "%s/%s-%s [%s]" % \
                (pkg.portageCategory, pkg.packageName, pkg.portageVersion, \
                 pkg.latestReleaseVersion),
            description = "Freshmeat Release Date: %s<br><br><b>Portage desc:</b><br> %s<br><br><b>Freshmeat desc:</b><br> %s<br>http://freshmeat.net/projects/%s/" % (pkg.latestReleaseDate, pkg.portageDesc, pkg.descShort, pkg.packageName),
            link = "http://meatoo.gentooexperimental.org/",
            pubDate = datetime.datetime.utcnow()
            ))

    rss = PyRSS2Gen.RSS2(
        title = "Meatoo - Gentoo vs. Freshmeat Releases",
        link = "http://meatoo.gentooexperimental.org/",
        description = "The latest Freshmeat releases with matching Gentoo versions.",
        lastBuildDate = datetime.datetime.utcnow(),
        items = items)
    return rss.to_xml()
Пример #26
0
def produce_feed(subreddit):
    json_url = 'http://reddit.com/r/{}/.json?raw_json=1'.format(subreddit)
    response = requests.get(json_url, headers=HEADERS)
    if response.status_code != 200:
        flask.abort(response.status_code)

    feed = response.json()

    cached_feed = PyRSS2Gen.RSS2(
        generator='reddit-rss.com',
        docs='github.com/jpsnyder/reddit-rss',
        title=subreddit,
        link='TODO: {}'.format(subreddit),
        description=None,
        lastBuildDate=None,
    )

    for item in feed['data']['children']:
        item = item['data']

        # Extract preview url.
        try:
            item['preview_url'] = get_preview_url(item)
        except KeyError:
            item['preview_url'] = None

        cached_item = PyRSS2Gen.RSSItem(
            guid=u'https://www.reddit.com/{}'.format(item['permalink']),
            title=item['title'],
            link=item['permalink'],
            description=flask.render_template('rss_item.html', item=item),
            author=item['author'],
            pubDate=datetime.datetime.utcfromtimestamp(item['created_utc']))
        cached_feed.items.append(cached_item)

    output = io.StringIO()
    cached_feed.write_xml(output)
    output.seek(0)
    return output.read()
Пример #27
0
def write_rss(metadatas):
    rssfile = os.path.join(OUTPUTDIR, RSSFILE)
    items = []
    pichtml = ""
    for d in metadatas[:RSSCOUNT]:
        d['url'] = "%s/%s" % (RSSMEDIA, d['file'])
        d['title'] = d['file']
        itemhtml = RSSIMG % d
        r = PyRSS2Gen.RSSItem(title=d['file'],
                              description=itemhtml,
                              link=d['url'],
                              pubDate=d['timestamp'])
        items.append(r)

    rss = PyRSS2Gen.RSS2(title=TITLE,
                         link=LINKURL,
                         description=DESCRIPTION,
                         lastBuildDate=datetime.now(),
                         items=items)
    with open(rssfile, "w") as f:
        rss.write_xml(f, encoding="UTF-8")
        f.write("\n")
Пример #28
0
    def csvIm(self, Fcsv):
        csvf = StringIO(Fcsv.decode())
        data = csv.reader(csvf)

        rss = PyRSS2Gen.RSS2(
            title="Sylvia's csv to RSS project",
            link="http://localhost/",
            description="This project will convert CSV to RSS",
            lastBuildDate=datetime.datetime.now(),
            items=[])
        for row in itertools.islice(data, 0, 99999):
            item = PyRSS2Gen.RSSItem(
                title=str(row[1]),
                link=str(row[2]),
                description=row[5] + " " + row[6] + " " + row[7] + " " +
                row[8] + " " + row[9] + " " + row[10] + " " + row[11] + " " +
                row[12] + " ",
                pubDate=str(row[3] + " to " + row[4]),
            )
            rss.items.append(item)

        rss.write_xml(open("D:\Dev\Projects\pyrss2gen.xml", "w"), )
Пример #29
0
    def RSSMaker(self):
        articles = []
        post_dir = self.posts_dir
        file_list = []
        files = os.listdir(post_dir)

        for f in files:
            file_list.append(post_dir + os.sep + f)
        file_list.sort(reverse=True)

        for single_file in file_list:
            article = self.markdown_parser(single_file)
            if article:
                if article['e'] == 0:
                    articles.append(article)

        rss_items = []
        for article in articles:
            link = self.site_url + "/article/" + article["name"]
            rss_item = PyRSS2Gen.RSSItem(title=article["title"],
                                         link=link,
                                         description=article["content"],
                                         guid=PyRSS2Gen.Guid(link),
                                         pubDate=datetime(
                                             int(article["date"][0:4]),
                                             int(article["date"][5:7]),
                                             int(article["date"][8:10]),
                                             int(article["date"][11:13]),
                                             int(article["date"][14:16])))
            rss_items.append(rss_item)

        rss = PyRSS2Gen.RSS2(title=self.site_name,
                             link=self.site_url,
                             description="",
                             lastBuildDate=datetime.utcnow(),
                             items=rss_items)

        rss.write_xml(open("rss.xml", "w"))
Пример #30
0
def post2rss(baseurl, post, *, digest=False, pic=None):
    url = post['url']
    if digest:
        content = post['excerpt']
        content = zhihulib.process_content_for_html(content, pic=pic)
    else:
        article = article_from_cache(post['id'], post['updated'])
        if not article:
            base.STATSC.incr('zhihu.cache_miss')
            content = post['excerpt'] + ' (全文尚不可用)'
            content = zhihulib.process_content_for_html(content, pic=pic)
            try:
                _article_q.put_nowait(str(post['id']))
            except asyncio.QueueFull:
                logger.warning('_article_q full')
                base.STATSC.incr('zhihu.queue_full')
        else:
            # logger.debug('cache hit for %s', post['id'])
            base.STATSC.incr('zhihu.cache_hit')

            content = article['content']
            if pic:
                doc = fromstring(content)
                base.proxify_pic(doc, zhihulib.re_zhihu_img, pic)
                content = tostring(doc, encoding=str)

    if post.get('title_image'):
        content = '<p><img src="%s"></p>' % post['title_image'] + content

    item = PyRSS2Gen.RSSItem(
        title=post['title'].replace('\x08', ''),
        link=url,
        guid=url,
        description=content,
        pubDate=datetime.datetime.fromtimestamp(post['updated']),
        author=post['author']['name'],
    )
    return item