-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed_builder.py
52 lines (44 loc) · 1.69 KB
/
feed_builder.py
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
from html import escape
IDX = {
'it': 0,
'en': 1,
'jb': 2
}
FEED_NAME = [
'Tutti gli avvisi | Unimi',
'Notice board | Unimi',
'Collaborazioni studentesche | Unimi'
]
FEED_DESCR = [
'Avvisi generali dell\'Università degli Studi di Milano "La Statale"',
'General notice board of the University of Milan "La Statale"',
'Bandi delle collaborazioni studentesche dell\'Università degli Studi di Milano "La Statale"'
]
FEED_LINK = [
'https://www.unimi.it/it/archivio-avvisi',
'https://www.unimi.it/en/notice-board',
'https://www.unimi.it/it/studiare/stage-e-lavoro/lavorare-durante-gli-studi/collaborazioni-studentesche/bandi-collaborazioni-studentesche'
]
DECLARATION = '<?xml version="1.0" encoding="UTF-8"?>'
RSS = ['<rss version="2.0">', '</rss>']
CHANNEL = ['<channel>', '</channel>']
TITLE = ['<title>', '</title>']
DESCR = ['<description>', '</description>']
LINK = ['<link>', '</link>']
ITEM = ['<item>', '</item>']
GUID = ['<guid isPermaLink="false">', '</guid>']
# Create an XML RSS feed
def to_feed(entries: list, kind: str):
output: str = f'{DECLARATION}{RSS[0]}{CHANNEL[0]}'
output += f'{TITLE[0]}{FEED_NAME[IDX[kind]]}{TITLE[1]}'
output += f'{DESCR[0]}{FEED_DESCR[IDX[kind]]}{DESCR[1]}'
output += f'{LINK[0]}{FEED_LINK[IDX[kind]]}{LINK[1]}'
for entry in entries:
output += f'{ITEM[0]}'
output += f'{TITLE[0]}{escape(entry.title)}{TITLE[1]}'
output += f'{LINK[0]}{escape(entry.link)}{LINK[1]}'
output += f'{DESCR[0]}{escape(entry.descr)}{DESCR[1]}'
output += f'{GUID[0]}{escape(entry.guid)}{GUID[1]}'
output += f'{ITEM[1]}'
output += f'{CHANNEL[1]}{RSS[1]}'
return output