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
|
#!/usr/bin/env python
"""A better reconstitution of the original shell archives from the Google HTML files.
Example (for part 09):
curl https://groups.google.com/g/alt.sources/c/w0LgGPVB6f0/m/SDnD377as9IJ \
| egrep '<section>' \
| sed -e 's/.*<section>//' -e 's:</section>.*::' \
| python shar/sharify.py > shar/python-0.9.1-09-21.shar
"""
import html
import re
import sys
shar = sys.stdin.read()
for (pat, repl) in (
(r'X\t', r'X '),
(r'X \t', r'X '),
(r'X \t', r'X '),
(r'X \t', r'X '),
):
shar = shar.replace(pat, repl)
for (pat, repl) in (
(',[2,[[1,[null,"', ''),
(r'\u0026lt;\u003c', '<'),
(r'\u003e\u0026gt;', '>'),
(r'\u003c', '<'),
(r'\u003d', '='),
(r'\u003e', '>'),
(r'\u0026', '&'),
(r'\"', '"'),
(r'"]', ''),
):
shar = shar.replace(pat, repl)
shar = html.unescape(shar)
for (pat, repl) in (
('<br>', '\n'),
):
shar = shar.replace(pat, repl)
for (pat, repl) in (
(r'<a href="[^"]+" target="_blank" rel="nofollow"'
r' data-saferedirecturl="[^"]+">([^<]+)</a>',
r'\1'),
(r'<a href data-email-masked rel="nofollow">([^<]+)</a>', r'\1'),
):
shar = re.sub(pat, repl, shar)
sys.stdout.write(shar.rstrip())
|