forked from conoro/tiktok-rss-flat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postprocessing.py
52 lines (40 loc) · 1.76 KB
/
postprocessing.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 TikTokApi import TikTokApi
import csv
from feedgen.feed import FeedGenerator
from datetime import datetime, timezone
# Normal GitHub Pages URL
# ghPagesURL = "https://balentay.github.io/tiktok-rss-flat/"
# Custom Domain
ghPagesURL = "https://tiktokrss.conoroneill.com/"
api = TikTokApi.get_instance()
count = 10
with open('subscriptions.csv') as f:
cf = csv.DictReader(f, fieldnames=['username'])
for row in cf:
user = row['username']
print (user)
tiktoks = api.by_username(user, count=count)
fg = FeedGenerator()
fg.id('https://www.tiktok.com/@' + user)
fg.title(user + ' TikTok')
fg.author( {'name':'Conor ONeill','email':'[email protected]'} )
fg.link( href='http://tiktok.com', rel='alternate' )
fg.logo(ghPagesURL + 'tiktok-rss.png')
fg.subtitle('OK Boomer, all the latest TikToks from ' + user)
fg.link( href=ghPagesURL + 'rss/' + user + '.xml', rel='self' )
fg.language('en')
# Set the last modification time for the feed to be the most recent post, else now.
updated=None
for tiktok in tiktoks:
fe = fg.add_entry()
link = "https://www.tiktok.com/@" + user + "/video/" + tiktok['id']
fe.id(link)
ts = datetime.fromtimestamp(tiktok['createTime'], timezone.utc)
fe.published(ts)
fe.updated(ts)
updated = max(ts, updated) if updated else ts
fe.title(tiktok['desc'])
fe.link(href=link)
fe.description("<img src='" + tiktok['video']['cover'] + "' />")
fg.updated(updated)
fg.atom_file('rss/' + user + '.xml', pretty=True) # Write the RSS feed to a file