Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to process templates. #8

Open
miki725 opened this issue Dec 6, 2014 · 3 comments
Open

How to process templates. #8

miki725 opened this issue Dec 6, 2014 · 3 comments

Comments

@miki725
Copy link
Contributor

miki725 commented Dec 6, 2014

I am trying to process a wikimedia database dump and this is the only library I found which actually does what I need however I can't figure out how to process wiki templates. Any suggestions?

here is the page on the wiki I am processing from the dump:
http://en.wikivoyage.org/wiki/%27s-Hertogenbosch

page in the mediawiki format:
https://gist.github.com/miki725/991793c24b4fc2bf41b2

processed html:
https://gist.github.com/miki725/f3df910f63525f9fc47d

As you can see a bunch of places are not processed such as sleep section - https://gist.github.com/miki725/f3df910f63525f9fc47d#file-processed-L115-L123

@lambdafu
Copy link
Owner

lambdafu commented Dec 7, 2014

Hi, thanks for your input! I haven't looked at your example yet, but in general, the way to load templates is to inherit from mw.Preprocessor and override the get_template method. There is an example here: https://github.com/lambdafu/smc.mw/blob/master/tests/mwtests.py#L71
Is this adequate?

@miki725
Copy link
Contributor Author

miki725 commented Dec 7, 2014

what am I suppose to return there? this did not work for me:

class MWPreprocessor(Preprocessor):
    def get_template(self, namespace, pagename):
        if pagename.lower() == 'pagebanner':
            return 'hello world'
        return super(MWPreprocessor, self).get_template(namespace, pagename)

@lambdafu
Copy link
Owner

lambdafu commented Dec 7, 2014

Mh, dunno what went wrong for you, but with 6017eb5 there is a simpler example now:

 $ echo '{{NEWS}}' | PYTHONPATH=. python smc/mw/tool.py -T . 
 <html><body><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div><ul>
 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants