views:

67

answers:

2

Hi guys, I'm writing a bot for Wikipedia but have a problem. When I want to get stuff from another Wikimedia site I get the error - error-name 'wikiquote' is not defined.

This is when I start the code off like this-

import wikipedia

site = wikiquote.getSite()

Yet if I was to start it with wikipedia written instead of wikiquote, it works. From what I can understand it should work on other Mediawiki sites?

Help gratefully appreciated!

Thanks!

+2  A: 

wikiquote is not defined or imported anywhere in your script. So it is understandable that your code does not work.

According to documentation of pywikipedia, you need to use this instead:

import wikipedia
site = wikipedia.getSite('en', 'wikiquote')
Ayman Hourieh
Sorry, me being very stupid! Thanks.
Solihull
A: 

If you're only running this for yourself, it doesn't matter, but pywikipedia bots should let the user control which site they're run against (and which account is used). Users specify these settings in the user-config.py file, as described here. In this case they'd set:

family = 'wikiquote'

which your bot should process. You can look at the login.py file to see an example of how to consume these configuration settings.

Matt G