summaryrefslogtreecommitdiff
path: root/tests/usage_example.py
blob: 69f258ba898ee44f93d4a277eb8fb15079012230 (plain)
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
31
32
33
34
35
36
37
38
# -*- encoding: utf-8 -*-

from __future__ import unicode_literals

import os
import tempfile
import six
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."
)

if six.PY3:
    FN_PREFIX = 'feed_py3-'
else:
    FN_PREFIX = 'feed_py2-'

# 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()