Skip to content

Instantly share code, notes, and snippets.

@yoonbae81
Last active December 26, 2018 03:39
Show Gist options
  • Save yoonbae81/37d88714b29f0ad6daf4d6012266c04b to your computer and use it in GitHub Desktop.
Save yoonbae81/37d88714b29f0ad6daf4d6012266c04b to your computer and use it in GitHub Desktop.
Generate RSS feed for EBS radio
#!/usr/bin/python3
# usage: podcast grammar
from os import listdir
from os.path import isfile, join, getsize, getmtime
import datetime
import sys
from feedgen.feed import FeedGenerator
PROGRAMS = {
'speaking' : '입이 트이는 영어',
'listening' : '귀가 트이는 영어',
'easy' : 'Easy English',
'power' : 'Power English',
'TOEICspeaking' : 'TOEIC Speaking',
'business' : '김과장, 영어로 날다',
'grammar' : '입이 트이는 영문법',
'pocket' : 'Pocket English',
'test' : 'test'
}
# sys.argv = ['a', 'grammar']
PROGRAM_CODE = sys.argv[1]
PROGRAM_NAME = PROGRAMS[PROGRAM_CODE]
WEBROOT = 'http://www.xcv.kr/ebs/'
FILEDIR = '/var/www/html/ebs/' + PROGRAM_CODE
files = [f for f in sorted(listdir(FILEDIR), reverse=False) if f.endswith('.m4a')]
fg = FeedGenerator()
fg.load_extension('podcast')
fg.language('ko-kr')
fg.title(PROGRAM_NAME)
fg.description(PROGRAM_NAME)
fg.link(href=WEBROOT)
fg.logo(WEBROOT + "logo.png")
for filename in files:
s = getsize(join(FILEDIR, filename))
d = datetime.datetime.strptime(filename[:8], '%Y%m%d')
fe = fg.add_entry()
fe.title(PROGRAM_NAME)
fe.id(filename)
fe.enclosure(url=join(WEBROOT, PROGRAM_CODE, filename), length=str(s), type='audio/mp4')
fe.pubDate(datetime.datetime.strftime(d, '%Y-%m-%dT%H:%M:%SZ'))
# print(fg.rss_str(pretty=True).decode('utf-8'))
with open(FILEDIR + '/index.html', 'w') as outfile:
outfile.write(fg.rss_str(pretty=True).decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment