Want to help improve the guide? Create an account now to get started!

User talk:Jpatokal/post.py

From Wikitravel
Jump to: navigation, search

post.py is a Pywikipediabot script for automated uploading of skeleton articles.

Installation[edit]

This script is intended for Pywikipediabot, which must be installed and configured first. Configure your account in user-config.py and run python2 login.py before attempting to run the bot.

Known issue: The default Pywikipediabot login.py can't recognize a successful login to Wikitravel, as Wikitravel returns three cookies, not four on successful login. Change the line that says

if len(L) == 4:

to

if len(L) > 1:

Note that Pywikipediabot's interface is not particularly stable and you will probably need to hand-hack the script a little to make it work with newer versions. Please update the script here after any changes.

Configuration[edit]

post.py works by reading .dat files, injecting the content into a template and posting the merged document to a specified Wikitravel version.

The .dat file consists of key-value pairs like this:

NAME Akita
LCASE akita
JAPANESE 秋田
CAPITAL Akita

Keys should use alphabetic characters in the range A-Z only. The special key NAME is used as the title of the article to be created. Values can contain anything, including UTF-8 characters (which should be used for any non-ASCII characters) and continue until the end of the line. Generating the dat files is left up to you!

The template is simply a plain text file containing the skeleton Wiki article and variables flagged by '$':

[[Image:Japan_$LCASE_map_small.png|right]]
 
'''$NAME prefecture''' ($JAPANESE ''$NAME-ken'') is in [[Japan]].
 
==Understand==
 
==Cities==
* [[$CAPITAL]] — The prefectural capital

Variable substitutions are performed against all variables listed in the dat file. Any variables not found in the dat file are ignored.

The command to actually run post.py is:

python2 post.py -uusername -ttemplate.wiki  -nfile.date -e/bin/true

Once you have perfected the automated entry of a single file, you can use a shell loop to upload everything:

for i in dat-directory/*; do
  python2 post.py  -uusername -ttemplate.wiki -n$i -e/bin/true
done

Questions and bug reports[edit]

This may be a stupid question but... Where do you enter the title for each new page or .dat file?

Very good question! The parameter NAME is automatically used as the title. Jpatokal 11:59, 19 March 2007 (EDT)

Mac[edit]

Sorry for being ignamoorse, but can Pywikipediabot be used on a Mac? -- Sapphire(Talk) • 01:55, 23 February 2008 (EST)

Yes. -- Colin 11:35, 23 February 2008 (EST)
BTW, I'm fairly sure that post.py in its present form is not going to work with current versions of pywikipediabot, which is revised continually and regularly breaks old code. Sigh. Jpatokal 14:21, 23 February 2008 (EST)

Variants

Actions

Destination Docents

In other languages