summaryrefslogtreecommitdiffstats
path: root/aurweb/scripts/rendercomment.py
blob: 593cd36a568a1fdfd252e3957aebd4d6f7cc5d2e (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
#!/usr/bin/python3

import sys
import bleach

import aurweb.db


def get_comment(conn, commentid):
    cur = conn.execute('SELECT Comments FROM PackageComments WHERE ID = ?',
                       [commentid])
    return cur.fetchone()[0]


def save_rendered_comment(conn, commentid, html):
    conn.execute('UPDATE PackageComments SET RenderedComment = ? WHERE ID = ?',
                 [html, commentid])


def main():
    commentid = int(sys.argv[1])

    conn = aurweb.db.Connection()

    html = get_comment(conn, commentid)
    html = html.replace('\n', '<br>')
    html = bleach.clean(html, tags=['br'])
    save_rendered_comment(conn, commentid, html)

    conn.commit()
    conn.close()


if __name__ == '__main__':
    main()