summaryrefslogtreecommitdiff
path: root/wikifolio/rss.py
blob: 81e61225b18ff8eb453e4dce70c25572e16e9190 (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
39
40
41
42
43
44
45
46
47
48
49
50
from . import model

import time
import typing

from ll.xist import xsc
from ll.xist.ns import xml, rss20


def dump_comments(cert: model.Certificate, comments: typing.Iterable[model.Comment]):
    title = "{.name} / {.isin}".format(cert, cert)
    items = []
    for comment in comments:
        items.append(rss20.item(
            rss20.title("Kommentar: " + title),
            rss20.author(comment.author),
            rss20.pubDate(time.strftime("%a, %d %b %Y %T %z",
                                        comment.pubDate)),
            rss20.guid(comment.guid),
            rss20.link(comment.link),
            rss20.description(comment.description)
        ))
    return xsc.Frag(xml.XML(),
                    rss20.rss(rss20.channel(
                        rss20.title(title),
                        *items
                    ))).string('utf-8')


def dump_trades(cert: model.Certificate, trades: typing.Iterable[model.Trade]):
    title = "{.name} / {.isin}".format(cert, cert)
    items = []
    for trade in trades:
        trade_title = trade.typ + " " + str(trade.volume) + "@" + str(trade.quote) + " " + trade.share_name
        description = trade.typ + " " + str(trade.volume) + "@" + str(trade.quote) + " " + trade.share_name
        description += " ( " + trade.share_isin + " ) "

        items.append(rss20.item(
            rss20.title(trade_title),
            rss20.author(cert.name),
            rss20.pubDate(trade.timestamp.strftime("%a, %d %b %Y %T %z")),
            rss20.guid(trade.timestamp.strftime("%a, %d %b %Y %T %z")),
            rss20.link(cert.make_url()),
            rss20.description(description)
        ))
    return xsc.Frag(xml.XML(),
                    rss20.rss(rss20.channel(
                        rss20.title(title),
                        *items
                    ))).string('utf-8')