[Pywikipedia-l] workon.py

Shane Geiger shane.geiger at gmail.com
Sat Apr 2 19:19:02 UTC 2011


Is there any interest in a script that quickly switches pywikipedia 
between wikis?  This is something I created quickly to do the job.  If 
there is interest in this, what would need to be changed?  Is there any 
interest in incorporating it into the distribution of pywikipedia?

(There is a os.chdir call and some os.system calls that would obviously 
need to be changed.)




#!/usr/bin/env python
"""
This script enables pywikipedia to be switched between different wikis 
quickly.

Simply create various config files with this format:   
user-config.py_<configname>

Then run the script:  ./workon.py [optional argument]

"""
import glob
import os
import sys

os.chdir('/Users/sg/pywikipedia')

configs = [x[15:] for x in glob.glob("user-config.py_*")]

def lines_from(filename,splice="[:]"):
     """ allows you specify a splice so you can skip part of the file.
     """
     file = open(filename, "r")
     return file.read().splitlines()

def print_current_wiki():
     for line in lines_from('user-config.py'):
         try:
             exec(line)
         except:
             pass
     print "working on:",family

if __name__ == '__main__':
     args = sys.argv[1:]
     if args == []:
         print_current_wiki()
     elif args[0] in configs:
         if os.path.exists('user-config.py_' + args[0]):
             os.system('rm -f user-config.py')
             os.system('cp user-config.py_' + args[0] + ' user-config.py')
             print_current_wiki()
     else:
             print "Not a valid option.  Did you create the 
'user-config.py_<name>' file?"
             print "Valid options: " + ", ".join(configs)






-- 
Shane Geiger
shane.geiger at gmail.com
Phone: 347-237-7108

"Principles for the development of a complete mind:
Study the science of art.
Study the art of science.
Develop your senses--especially learn how to see.
Realize how everything connects to everything else."
   -- Leonardo DaVinci




More information about the Pywikipedia-l mailing list