summaryrefslogtreecommitdiff
path: root/scripts/rss.py
blob: 26dee5b4cc30c7b83db98533e1e8e735cb6c692a (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3

"""

rss.py

Originally designed for use in generating https://fcm.andrewyu.org,
just makes RSS out of articles with plain UNIX-like ls -l

Python 3.8+ required!

Copyright (C) 2022  Andrew Yu <andrew@andrewyu.org>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""

import sys
import os

head = """<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Free Computing Movement</title>
<link>https://fcm.andrewyu.org/</link>
<description>Liberty in computing, both free software and free hardware.</description>
"""

item = """<item>
    <title>{title}</title>
    <link>{link}</link>
    <!--guid></guid-->
    <pubDate>{date}</pubDate>
    <description>{}</description>
</item>
"""

tail = """</channel>
</rss>"""

def car(l):
    return l[0]

def cdr(l):
    return l[1:]

def generate(toscan):
    if type(toscan) == str:
        if os.path.isfile(toscan):
            print(toscan)
        elif os.path.isdir(toscan):
            generate([toscan + '/' + f for f in os.listdir(toscan)])
        else:
            print(f"[!] toscan ({toscan}) is nonexistant", file=sys.stderr)
    elif type(toscan) == list:
        if len(toscan) != 0:
            generate(car(toscan))
            if len(toscan) > 1:
                generate(cdr(toscan))
    else:
        print("[!] len(toscan) is zero", file=sys.stderr)

generate(sys.argv[1])