File: usage_example.py

package info (click to toggle)
feedgenerator 2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: python: 1,011; sh: 8; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 923 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import tempfile
import feedgenerator

feed = feedgenerator.Rss201rev2Feed(
    title="Poynter E-Media Tidbits",
    link="http://www.poynter.org/column.asp?id=31",
    description="""A group Weblog by the sharpest minds in online media/journalism/publishing.
    Umlauts: äöüßÄÖÜ
    Chinese: 老师是四十四,是不是?
    Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin.
    """,
    language="en",
)
feed.add_item(
    title="Hello",
    link="http://www.holovaty.com/test/",
    description="Testing."
)

FN_PREFIX = 'feed_py3-'

# Usage example in feedgenerator docs opens the file in text mode, not binary.
# So we do this here likewise.
fd, filename = tempfile.mkstemp(prefix=FN_PREFIX, suffix='.txt', text=True)
try:
    fh = os.fdopen(fd, 'w')
    feed.write(fh, 'utf-8')
finally:
    fh.close()