-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First take (that I don't like at all). Time for redesign!
- Loading branch information
1 parent
31148c6
commit 623eee7
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/local/bin/python | ||
# -*- coding: utf-8 -*- | ||
# not /Library/Frameworks/Python.framework/Versions/3.1/bin/python3 | ||
|
||
import os | ||
import markdown | ||
from urllib import unquote | ||
|
||
languages = ('English', 'Russian', 'German', 'Dutch', 'French', 'Abbreviated as') | ||
|
||
''' | ||
* English: _waterfall model_ ([Wikipedia](http://en.wikipedia.org/wiki/Waterfall model)) | ||
* Russian: _каскадная модель_ ([Wikipedia](http://ru.wikipedia.org/wiki/Каскадная модель)) | ||
* Dutch: _watervalmethode_ ([Wikipedia](http://nl.wikipedia.org/wiki/Watervalmethode)) | ||
* German: _Wasserfallmodell_ ([Wikipedia](http://de.wikipedia.org/wiki/Wasserfallmodell)) | ||
''' | ||
def readmd(fn): | ||
names = [] | ||
html = '' | ||
f = open('wiki/%s' % fn, 'r') | ||
for line in f.readlines(): | ||
if not line.strip(): | ||
continue | ||
wrds = line.split(': ') | ||
if len(wrds) == 2: | ||
lhs = wrds[0].split('* ')[1] | ||
rhs = wrds[1].strip() | ||
if lhs in languages: | ||
term = line.split('_')[1] | ||
# print 'A language:',{lhs:term} | ||
if term.find('/') < 0: | ||
names.append(term) | ||
else: | ||
names.extend(term.split('/')) | ||
# else: | ||
# print 'Not a language:',{lhs:rhs} | ||
# lang = line.split('* ')[1].split(': _')[0] | ||
# term = line.split('_')[1] | ||
# links = | ||
try: | ||
# print markdown.markdown(unicode(line.strip())) | ||
html += markdown.markdown(line.strip().decode('unicode-escape')) | ||
# print markdown.markdown(line.strip().decode('unicode-escape')) | ||
except UnicodeDecodeError: | ||
print('"%s" cannot be decoded' % line) | ||
# print '???' | ||
f.close() | ||
for name in names: | ||
try: | ||
f = open('up/%s.html' % name,'w') | ||
f.write('<html><head><title>%s</title></head><body>%s</body></html>' % (name, html.encode('unicode-escape'))) | ||
f.close() | ||
except IOError: | ||
print('"%s" cannot be accessed' % name) | ||
|
||
for root, dirs, filenames in os.walk('wiki/'): | ||
for f in filter(lambda x:x.endswith('.md'),filenames): | ||
# home.write('* [[%s]]\n' % f[:-3]) | ||
print(f) | ||
readmd(f) | ||
# home.close() |