Browse Source

Removing old WordPress import files

pull/1/head
Annika Backstrom 1 year ago
parent
commit
f46a25acff

+ 0
- 63
sixohthree-import/add-fields-from-xml.py View File

@@ -1,63 +0,0 @@
1
-import os
2
-import sys
3
-import xml.etree.ElementTree as ET
4
-
5
-NS_MAP = {
6
-    'excerpt': 'http://wordpress.org/export/1.2/excerpt/',
7
-}
8
-
9
-for (a, b) in NS_MAP.iteritems():
10
-    ET.register_namespace(a, b)
11
-
12
-tree = ET.parse('../sixohthree-import/sixohthreecom.wordpress.2013-01-15.xml')
13
-root = tree.getroot()
14
-
15
-for item in root.iter('item'):
16
-    excerpt_text = post_format_text = ''
17
-
18
-    excerpt = item.find('{http://wordpress.org/export/1.2/excerpt/}encoded')
19
-    post_format = item.find('category[@domain="post_format"]')
20
-    post_name = item.find('{http://wordpress.org/export/1.2/}post_name').text
21
-    post_id = item.find('{http://wordpress.org/export/1.2/}post_id').text
22
-    post_type = item.find('{http://wordpress.org/export/1.2/}post_type').text
23
-
24
-    if post_type != 'post':
25
-        sys.stderr.write("Skipping [%s] %s (%s)\n" % (post_type, post_name, post_id))
26
-        continue
27
-
28
-    try:
29
-        excerpt_text = excerpt.text
30
-    except AttributeError:
31
-        pass
32
-
33
-    try:
34
-        post_format_text = post_format.text
35
-    except AttributeError:
36
-        pass
37
-
38
-    if excerpt_text == None and post_format == None:
39
-        continue
40
-
41
-    filename = "../content/%s-%s.md" % (post_id, post_name)
42
-
43
-    try:
44
-        f = open(filename, 'r')
45
-    except IOError:
46
-        sys.stderr.write("Cannot find file %s\n" % filename)
47
-        continue
48
-
49
-    contents = f.read()
50
-
51
-    tmp = open(filename + '.tmp', 'w')
52
-
53
-    if excerpt_text:
54
-        tmp.write('Summary: %s\n' % excerpt_text)
55
-
56
-    if post_format_text:
57
-        tmp.write('WordPress-Post-Format: %s\n' % post_format_text)
58
-
59
-    tmp.write(contents)
60
-
61
-    # print excerpt_text, post_format_text
62
-
63
-print "Done."

+ 0
- 16
sixohthree-import/addslug.py View File

@@ -1,16 +0,0 @@
1
-#!/usr/bin/python2.7
2
-
3
-import sys
4
-
5
-filenames = sys.argv[1:]
6
-
7
-for filename in filenames:
8
-    f = open(filename, 'r')
9
-    text = f.read()
10
-
11
-    slug = filename[:-3].replace('-', '/', 1) + '/'
12
-
13
-    tmp = open(filename + '.tmp', 'w')
14
-    tmp.write('Slug: %s\n' % slug)
15
-
16
-    tmp.write(text)

+ 0
- 53
sixohthree-import/directorize.py View File

@@ -1,53 +0,0 @@
1
-#!/usr/bin/python
2
-
3
-import os
4
-import re
5
-
6
-MAP = {
7
-    "WordPress Post ID": "post_id"
8
-}
9
-
10
-def read_headers(filename):
11
-    if filename[-3:] != '.md':
12
-        return False
13
-
14
-    f = open(filename, 'r')
15
-
16
-    result = {}
17
-
18
-    for line in f:
19
-        line = line[:-1]
20
-
21
-        if line == "":
22
-            break
23
-
24
-        header, value = line.split(": ", 1)
25
-
26
-        try:
27
-            result[MAP[header]] = value
28
-        except KeyError:
29
-            pass
30
-
31
-    return result
32
-
33
-for dirname, dirnames, filenames in os.walk('.'):
34
-    for filename in filenames:
35
-        headers = read_headers(filename)
36
-
37
-        if not headers:
38
-            print "BAD %s" % filename
39
-            continue
40
-
41
-        if not os.path.isdir(headers['post_id']):
42
-            os.mkdir(headers['post_id'])
43
-
44
-        newname = os.path.join(headers['post_id'], filename)
45
-
46
-        if os.path.isfile(newname):
47
-            os.unlink(filename)
48
-            print "EXISTS  %s" % newname
49
-            continue
50
-
51
-        print "%s -> %s" % (filename, newname)
52
-        os.link(filename, newname)
53
-        os.unlink(filename)

+ 0
- 1873
sixohthree-import/sitemap.xml
File diff suppressed because it is too large
View File


+ 0
- 39482
sixohthree-import/sixohthreecom.wordpress.2013-01-15.xml
File diff suppressed because it is too large
View File


+ 0
- 74
sixohthree-import/tagmerge.py View File

@@ -1,74 +0,0 @@
1
-#!/usr/bin/python2.7
2
-
3
-import markdown
4
-import os
5
-
6
-from markdown.extensions.meta import META_RE, META_MORE_RE
7
-
8
-MetaPreprocessor = markdown.extensions.meta.MetaPreprocessor
9
-
10
-MAP = {
11
-    'wordpress-post-id': 'WordPress-Post-ID',
12
-    'wordpress-post-type': 'WordPress-Post-Type',
13
-    'wordpress-post-format': 'WordPress-Post-Format',
14
-}
15
-
16
-ORDER = [
17
-    'Title',
18
-    'Slug',
19
-    'Summary',
20
-    'Date',
21
-    'Author',
22
-    'Tags',
23
-    'WordPress-Post-ID',
24
-    'WordPress-Post-Type',
25
-    'WordPress-Post-Format',
26
-]
27
-
28
-def headerfix(s):
29
-    try:
30
-        return MAP[s]
31
-    except KeyError:
32
-        return s.capitalize()
33
-
34
-def parse_file(f):
35
-    text = f.read()
36
-    lines = text.split("\n")
37
-
38
-    md = markdown.Markdown()
39
-    mp = MetaPreprocessor(markdown)
40
-    lines = mp.run(lines)
41
-    text = "\n".join(lines)
42
-    meta = mp.markdown.Meta
43
-
44
-    tags = []
45
-
46
-    if 'category' in meta:
47
-        tags += meta['category']
48
-        del meta['category']
49
-
50
-    if 'tags' in meta:
51
-        tags += meta['tags']
52
-        del meta['tags']
53
-
54
-    if tags:
55
-        meta['tags'] = [", ".join(tags)]
56
-
57
-    headers = [(headerfix(k), v[0]) for k, v in meta.items()]
58
-    headers.sort(key=lambda k: ORDER.index(k[0]))
59
-    headers = "\n".join(["{0}: {1}".format(k, v) for k, v in headers])
60
-
61
-    return "%s\n\n%s" % (headers, text)
62
-
63
-for dirname, dirnames, filenames in os.walk('.'):
64
-    for filename in filenames:
65
-        if filename[-3:] != '.md':
66
-            continue
67
-
68
-        f = open(filename, 'r')
69
-        fixed = parse_file(f)
70
-        f.close()
71
-
72
-        f = open(filename, 'w')
73
-        f.write(fixed)
74
-        f.close()

Loading…
Cancel
Save