User:Nichalp-bot
From Wikipedia, the free encyclopedia
Bot account of User:Nichalp. Please direct any queries to Nichalp.
Contents |
[edit] Re: Need a simple bot
I saw your request for a simple bot. Have you ever used pywikipedia framework? --AllyUnion (talk) 04:07, 8 September 2005 (UTC)
- It's very easy to set up if you can install Python. Do you use Windows or Linux? --AllyUnion (talk) 04:13, 8 September 2005 (UTC)
-
-
- In Linux, you will want to run the CVS command that is on the pywikipedia bot framework page:
-
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/pywikipediabot login cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/pywikipediabot co pywikipedia
-
-
-
- You'll want this one: 08/25/2005 --AllyUnion (talk) 05:13, 8 September 2005 (UTC)
-
-
-
-
-
-
- Unzip the files, install python, copy the config.py to user-config.py, edit user-config.py to modify the settings to:
-
-
-
# -*- coding: utf-8 -*-
############## ACCOUNT SETTINGS ##############
# The family of sites we are working on. wikipedia.py will import
# families/xxx_family.py so if you want to change this variable,
# you need to write such a file.
family = 'wikipedia'
# The language code of the site we're working on.
mylang = 'en'
# The dictionary usernames should contain a username for each site where you
# have a bot account. Please set your usernames by adding such lines to your
# user-config.py:
#
# usernames['wikipedia']['de'] = 'myGermanUsername'
# usernames['wiktionary']['en'] = 'myEnglishUsername'
#
#usernames = {}
usernames['wikipedia']['en'] = 'USERNAME_HERE'
############## USER INTERFACE SETTINGS ##############
# the encoding that's used in the user's console, i.e. how strings are encoded
# when they are read by raw_input(). On Windows systems' DOS box, this should
# be 'cp850' ('cp437' for older versions). Linux users might try 'iso-8859-1'
# or 'utf-8'. If this variable is set to None, the default is 'cp850' on
# windows, and iso-8859-1 on other systems
console_encoding = None
# tkinter isn't yet ready
userinterface = 'terminal'
# Should the system bell be ringed if the bot expects user input?
ring_bell = False
--AllyUnion (talk) 05:21, 8 September 2005 (UTC)
Also, I made small modifications to wikipedia.py in order to get mine working: In the file wikipedia.py:
def output(text, decoder = None, colors = [], newline = True):
"""
Works like print, but uses the encoding used by the user's console
(console_encoding in the configuration file) instead of ASCII.
If decoder is None, text should be a unicode string. Otherwise it
should be encoded in the given encoding.
colors is a list of integers, one for each character of text. If a
list entry is None, the default color will be used for the
character at that position.
If newline is True, a linebreak will be added after printing the text.
"""
if decoder:
text = unicode(text, decoder)
elif type(text) != type(u''):
print "DBG> BUG: Non-unicode passed to wikipedia.output without decoder!"
print traceback.print_stack()
print "DBG> Attempting to recover, but please report this problem"
try:
text = unicode(text, 'utf-8')
except UnicodeDecodeError:
text = unicode(text, 'iso8859-1')
if logfile:
# save the text in a logfile (will be written in utf-8)
logfile.write(text + '\n')
logfile.flush()
# ui.output(text, colors = colors, newline = newline)
print text
#def input(question):
# return ui.input(question)
#def inputChoice(question, answers, hotkeys, default = None):
# return ui.inputChoice(question, answers, hotkeys, default)
Your script would be something like this:
f = file('something.csv')
text = f.readlines()
for line in text:
items = line.replace('\n','').split(',')
name = items[0]
state = items[1]
population = items[2]
area = items[3]
newtext = name + " is a district in " + state + " with a population of " + population + " and an area of " + area
wikipedia.Page(wikipedia.getSite(), 'User:Nichlap/Sandbox').put(newtext)
Or something like that. Read the file. Good luck. --AllyUnion (talk) 05:38, 8 September 2005 (UTC)
Replace 'USERNAME_HERE' with 'Nichalp' but if you plan to use a bot, you should sign up an account separate from your username. --AllyUnion (talk) 16:09, 9 September 2005 (UTC)
- Also your custom script is a separate file. You will call the modules by importing. See the Python documentation here for more info. --AllyUnion (talk) 06:27, 10 September 2005 (UTC)
No, you put that into a new file, the f = file('something.csv') (etc) and make a python program. --AllyUnion (talk) 18:54, 10 September 2005 (UTC)
[edit] More help
Some python basics:
import module_name - This imports a module or file into your program, same as #include in C++
Calling functions from this module would be module.function_name
You can read more at www.python.org where they have a tutorial. The main modules you will be calling are: wikipedia and config
You'll be calling your programs by the following:
python <filename>.py
You will not have to do this if you are calling the python interpreter by a shbang.
The extensions for python are typically .py
.pyc files are compiled versions of the .py that the program is using.
In order for your bot to log in, you have to call (only once every so month... maybe):
python login.py
In a clean, separate file, you need at the top:
# -*- coding: utf-8 -*- import wikipedia, config
In order to create a Page object in which you will use to get and put pages, you have to something like this:
mypage = wikipedia.Page(wikipedia.getSite(), 'User talk:Cool Cat')
That creates a page object linked to your talk page in the above example.
To get the wiki text from the page, you'd call (following from the previous example):
mypage.get()
You can save that data into a variable if you wish. To put a page you do something like this:
mypage.put('New text to replace old text', 'Fill out the comment field in this field.')
Where "New text" is where you want to replace the existing text, and the second portion is the comment note in the history. Default is something like: "Wikipedia python library"
If you want to add to the text, do something like this:
mypage.put(mypage.get() + 'Added text here', 'Bot adding text')
That is all you should need to program your script in Python and get your bot working. I don't believe you need any other function. The code I gave you above is an outline for your program for you to use. If you have any further questions, please don't hestitate to leave me a message. --AllyUnion (talk) 20:01, 16 September 2005 (UTC)
[edit] Current config
user-config.py
# The family of sites we are working on. wikipedia.py will import
# families/xxx_family.py so if you want to change this variable,
# you need to write such a file.
family = 'wikipedia'
# The language code of the site we're working on.
mylang = 'en'
# The dictionary usernames should contain a username for each site where you
# have a bot account. Please set your usernames by adding such lines to your
# user-config.py:
#
# usernames['wikipedia']['de'] = 'myGermanUsername'
# usernames['wiktionary']['en'] = 'myEnglishUsername'
#
#usernames = {}
usernames['wikipedia']['en'] = 'Nichalp-bot'
############## USER INTERFACE SETTINGS ##############
# the encoding that's used in the user's console, i.e. how strings are encoded
# when they are read by raw_input(). On Windows systems' DOS box, this should
# be 'cp850' ('cp437' for older versions). Linux users might try 'iso-8859-1'
# or 'utf-8'. If this variable is set to None, the default is 'cp850' on
# windows, and iso-8859-1 on other systems
console_encoding = None
# tkinter isn't yet ready
userinterface = 'terminal'
# Should the system bell be ringed if the bot expects user input?
ring_bell = False
In a separate file, like bot.py:
import wikipedia, config
if __name__ == "__main__":
f = file('names.csv')
text = f.readlines()
for line in text:
items = line.replace('\n','').split(',')
name = items[0]
state = items[1]
population = items[2]
area = items[3]
newtext = name + " is a district in " + state + " with a population of " + population + " and an area of " + area + "\n"
currentpage = wikipedia.Page(wikipedia.getSite(), 'User:Nichlap/Sandbox')
currentpage.put(currentpage.get() + newtext)
[edit] CSV
- contents of the csv file
District,Headquarters,Population,Area,Density,Abbr Changlang,Changlang,124994,4662,27,AR-CH Dibang Valley,Anini,57543,13029,4,AR-DV East Kameng,Seppa,57065,4134,14,AR-EK East Siang,Pasighat,87430,4005,22,AR-ES

