-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmakerss.py
More file actions
executable file
·109 lines (100 loc) · 5.9 KB
/
Copy pathmakerss.py
File metadata and controls
executable file
·109 lines (100 loc) · 5.9 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/local/bin/python
# Copyright (c) 2006 Jack Twilley <jmt@twilley.org>
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Generate RSS files for Morse code files. An RSS file will be
# created for each pair of number-of-characters and speed, with one
# element for each of the days -- much like other RSS files.
import os,sys
from stat import *
import time
import datetime
import PyRSS2Gen
import md5
webtop = "http://www.twilley.org/~jmt/morse"
filetop = "/home/jmt/public_html/morse"
def get_hash(filename):
""" Return md5 hash (from dupes.py on the net) """
f = open(filename,'rb')
hsh = md5.new()
while 1:
data = f.read(2048)
if not data: break
hsh.update(data)
f.close()
return hsh.hexdigest()
for ncindex in range(2, 43):
for spindex in (20, 13, 5):
filebase = "%d-%d" % (ncindex, spindex)
rss = PyRSS2Gen.RSS2(
title = "Morse code practice - %d WPM - %d chars" % (spindex, ncindex),
link = "%s/rss/%s.rss" % (webtop, filebase),
description = "Morse code practice sessions automatically generated by newkoch.pl and tomorse.",
lastBuildDate = datetime.datetime.now(),
items = [
PyRSS2Gen.RSSItem(
title = "Practice file for today",
link = "%s/today/%s.mp3" % (webtop, filebase),
description = "Practice file for today",
pubDate = datetime.datetime.fromtimestamp(time.mktime(time.localtime(os.stat("%s/today/%s.mp3" % (filetop, filebase))[ST_CTIME]))),
enclosure = PyRSS2Gen.Enclosure("%s/today/%s.mp3" % (webtop, filebase), os.stat("%s/today/%s.mp3" % (filetop, filebase))[ST_SIZE], "audio/mpeg"),
guid = PyRSS2Gen.Guid(get_hash("%s/today/%s.mp3" % (filetop, filebase)), 0),
),
PyRSS2Gen.RSSItem(
title = "Answer file for today",
link = "%s/today/%s.mp3" % (webtop, ncindex),
description = "Answer file for today",
pubDate = datetime.datetime.fromtimestamp(time.mktime(time.localtime(os.stat("%s/today/%s.mp3" % (filetop, ncindex))[ST_CTIME]))),
enclosure = PyRSS2Gen.Enclosure("%s/today/%s.mp3" % (webtop, ncindex), os.stat("%s/today/%s.mp3" % (filetop, ncindex))[ST_SIZE], "audio/mpeg"),
guid = PyRSS2Gen.Guid(get_hash("%s/today/%s.mp3" % (filetop, ncindex)), 0),
),
PyRSS2Gen.RSSItem(
title = "Practice file for yesterday",
link = "%s/yesterday/%s.mp3" % (webtop, filebase),
description = "Practice file for yesterday",
pubDate = datetime.datetime.fromtimestamp(time.mktime(time.localtime(os.stat("%s/yesterday/%s.mp3" % (filetop, filebase))[ST_CTIME]))),
enclosure = PyRSS2Gen.Enclosure("%s/yesterday/%s.mp3" % (webtop, filebase), os.stat("%s/yesterday/%s.mp3" % (filetop, filebase))[ST_SIZE], "audio/mpeg"),
guid = PyRSS2Gen.Guid(get_hash("%s/yesterday/%s.mp3" % (filetop, filebase)), 0),
),
PyRSS2Gen.RSSItem(
title = "Answer file for yesterday",
link = "%s/yesterday/%s.mp3" % (webtop, ncindex),
description = "Answer file for yesterday",
pubDate = datetime.datetime.fromtimestamp(time.mktime(time.localtime(os.stat("%s/yesterday/%s.mp3" % (filetop, ncindex))[ST_CTIME]))),
enclosure = PyRSS2Gen.Enclosure("%s/yesterday/%s.mp3" % (webtop, ncindex), os.stat("%s/yesterday/%s.mp3" % (filetop, ncindex))[ST_SIZE], "audio/mpeg"),
guid = PyRSS2Gen.Guid(get_hash("%s/yesterday/%s.mp3" % (filetop, ncindex)), 0),
),
PyRSS2Gen.RSSItem(
title = "Practice file for the day before yesterday",
link = "%s/daybefore/%s.mp3" % (webtop, filebase),
description = "Practice file for the day before yesterday",
pubDate = datetime.datetime.fromtimestamp(time.mktime(time.localtime(os.stat("%s/daybefore/%s.mp3" % (filetop, filebase))[ST_CTIME]))),
enclosure = PyRSS2Gen.Enclosure("%s/daybefore/%s.mp3" % (webtop, filebase), os.stat("%s/daybefore/%s.mp3" % (filetop, filebase))[ST_SIZE], "audio/mpeg"),
guid = PyRSS2Gen.Guid(get_hash("%s/daybefore/%s.mp3" % (filetop, filebase)), 0),
),
PyRSS2Gen.RSSItem(
title = "Answer file for the day before yesterday",
link = "%s/daybefore/%s.mp3" % (webtop, ncindex),
description = "Answer file for day before yesterday",
pubDate = datetime.datetime.fromtimestamp(time.mktime(time.localtime(os.stat("%s/daybefore/%s.mp3" % (filetop, ncindex))[ST_CTIME]))),
enclosure = PyRSS2Gen.Enclosure("%s/daybefore/%s.mp3" % (webtop, ncindex), os.stat("%s/daybefore/%s.mp3" % (filetop, ncindex))[ST_SIZE], "audio/mpeg"),
guid = PyRSS2Gen.Guid(get_hash("%s/daybefore/%s.mp3" % (filetop, ncindex)), 0),
),
])
rss.write_xml(open("%s/rss/%s.rss" % (filetop, filebase), "w"))