User talk:Twhk2011
- 維基百科鼓勵勇於修改,所以放膽寫!「維基百科五大支柱」係百科、中立、內容自由、行為規範、冇死板嘅規則。
- 寫文嗰陣,想像自己用廣東話講正經嘢嗰時會點講,然後將你把口講嘅嘢寫低,「粵文」係將粵語直接寫低嘅文字。
- 如果有啲粵語當中嘅字你識講唔識寫嘅話,可以去呢度問,甚至可以索性寫拼音。
- 如果閣下覺得未有信心親自寫文,可以去參考吓粵維啲正文同好文。
- 維基百科唔鼓勵搞破壞,如果搞破壞,就會俾人封鎖。
- 順便提提,响討論版發言之後,記得打四隻(半形)波浪紋嚟簽名,即係噉~~~~。
- 有乜嘢問題,可以去我塊討論版問我,亦可以嚟呢度搵答案。有嘢講?請去Wikipedia:新維基友留言。
- 我哋發展緊翻譯外文專有名詞嘅一套指引《Wikipedia:翻譯》,你可以參考同埋俾意見。希望你鍾意嚟呢度寫嘢。
- 得閒嘅多啲嚟嘆杯茶,同粵維友一齊車天車地!
- Welcome to Cantonese Wikipedia. If you cannot understand Cantonese, you can write to our Ambassador. Enjoy yourself.
- = )< Hillgentleman|書|二零一零年八月七號(星期六)格林尼治 22點43分12秒。>
Python[編輯]
如何用pywikipedia[編輯]
meta:python wikipedia bot, meta:wikipedia.py
- 先在 http://python.org/download 下載python。
- 安裝 python
- 裝pywikipediabot
測試:
下載粤語維基百科首頁:
做一個文件夾 C:\python\loadGuongDongWhaTouBan.py
import wikipedia enWikisrcSite = wikipedia.getSite('zh-yue', 'wikipedia') # loading a defined project's page page = wikipedia.Page(enWikisrcSite, '%E9%A0%AD%E7%89%88') text = page.get() # Taking the text of the page print text wikipedia.stopme()
然後入 C:\python\python loadGuongDongWhaTouBan.py
(連白痴都會:如果你用 windows, 記住把文件夾和 python.exe 要放在同一個 directory。)
認真的來了,你必須要開文件夾 user-config.py
:
設定[編輯]
user-config.py
family='wikipedia' mylang='zh-yue' usernames['wikipedia']['zh-yue'] = 'R. Hillgentleman' usernames['wikiversity']['beta'] = 'R. Hillgentleman' console_encoding = 'utf-8'
登入[編輯]
開始運行 C:\python\python login.py
自動或協助你登入 user-config.py
內設定的網站 (family='wikipedia' , mylang='zh-yue')。
只須要運行一次就可以了。
範例程式[編輯]
pywikiBoilerplate.py
import wikipedia
#set up
site = wikipedia.getSite()
page = wikipedia.Page(site, u"pageName")
#to get a page:
text = page.get(get_redirect = True)
#to update a page:
page.put(u"newText", u"Edit comment")
#CategoryPageGenerator
import wikipedia
import pagegenerators
import catlib
site = wikipedia.getSite()
cat = catlib.Category(site,'Category:%E9%A1%9E') # %E9%A1%9E={{subst:urlencode:類}}
gen = pagegenerators.CategorizedPageGenerator(cat)
for page in gen:
#Do something with the page object, for example:
text = page.get()
編輯[編輯]
在wikipedia:sandbox加入下面的句子:
import wikipedia # Define the main function def main(): site = wikipedia.getSite() pagename = 'wikipedia:Sandbox' page = wikipedia.Page(site, pagename) wikipedia.output(u"Loading %s..." % pagename) # Please, see the "u" before the text try: text = page.get(force = False, get_redirect=False, throttle = True, sysop = False, nofollow_redirects=False, change_edit_time = True) # text = page.get() <-- is the same except wikipedia.NoPage: # First except, prevent empty pages text = '' except wikipedia.IsRedirectPage: # second except, prevent redirect wikipedia.output(u'%s is a redirect!' % pagename) exit()# wikipedia.stopme() is in the finally, we don't need to use it twice, exit() will only close the script except wikipedia.Error: # third exception, take the problem and print wikipedia.output(u"Some Error, skipping..") exit() newtext = text + '\nHello, World!' page.put(newtext, comment='Bot: Test', watchArticle = None, minorEdit = True) # page.put(newtext, 'Bot: Test') <-- is the same if __name__ == '__main__': try: main() finally: wikipedia.stopme()
category:類這兒有甚麼分類?[編輯]
查看一下category:類這兒有哪幾頁?,然後放入wikipedia:sandbox。[1]
getCategoryWriteYue.py
import wikipedia
import pagegenerators
import catlib
site = wikipedia.getSite()
cat = catlib.Category(site,'Category:%E9%A1%9E') # %E9%A1%9E={{subst:urlencode:類}}
gen = pagegenerators.CategorizedPageGenerator(cat)
list=''
for page in gen:
list =list+ '\n' + page.title()
#write the list at the end of [[wikipedia:sandbox]]
sandbox = wikipedia.Page(site, u"wikipedia:sandbox")
sandboxtext = sandbox.get(get_redirect = True)
sandboxtext = sandboxtext + '\n' + list
sandbox.put(sandboxtext, comment='Mechanical test: get pages in [[Category:%E9%A1%9E]] and dump them on [[wikipedia:sandbox]]', watchArticle = None, minorEdit = True)
找一下在分類之中,分了哪幾類[編輯]
C:\python>python category.py -family:wikipedia -lang:zh-yue listify -from:%E7%B6%AD%E5%9F%BA%E7%99%BE%E7%A7%91
(如果加了" -recurse:True ",這樣子類别內的子類别。。。也都會包括在內)[2]。
查詢一個類別內,有甚麼網頁=[編輯]
C:\python>python pagegenerators.py -family:wikipedia -lang:zh-yue subcat:%E7%B6%AD%E5%9F%BA%E7%99%BE%E7%A7%91
移動類別[編輯]
C:\python>python category.py move -from:A類 -to:B類
# 中文字要用啲%%%嘅unicode表示
示範:[3]
改 regex[編輯]
C:\python>python replace.py -linkes:pagename -regex "Template:(.*?)" "Template:\1"
或者簡單嘅見字代字:
C:\python>python replace.py -cat:A類 "xxx舊字" "yyy新字"
查詢wikipedia:sandbox的編輯沿革[編輯]
#getting the history of [[wikipedia:sandbox]]
import wikipedia #importing the wikipedia.py module
pg = wikipedia.Page(wikipedia.getSite(), 'wikipedia:sandbox') #creating the Page object corresponding to [[wikipedia:sandbox]]
x=pg.getVersionHistoryTable() #calling the function getVersionHistoryTable() in the wikipedia.py module
print x
查下Main Page嘅沿革,然後氹落wikipedia:sandbox[編輯]
getSandboxHistoryWrite.py
#get the history of a [[Main Page]] and dump it on [[wikipedia:sandbox]]
import wikipedia #importing the wikipedia.py module
site=wikipedia.getSite() #setting the variable site = (wikipedia, zh-yue)
pg = wikipedia.Page(site, 'Main Page') #creating the Page object corresponding to [[wikipedia:sandbox]]
x=pg.getVersionHistoryTable() #calling the function getVersionHistoryTable() in the wikipedia.py module
#writing the result on [[wikipedia:sandbox]]
sand = wikipedia.Page(site, 'wikipedia:sandbox') #create the object corresponding to sandbox
y = sand.get() #read sandbox
y = y+x #append x, the page history of [[Main Page]]
sand.put( y , 'Robot testing: dumping the history of [[Main Page]] on [[wikipedia:sandbox]]') #write
示範:[4]
查下template:copyvio嘅編者,然後氹落wikipedia:sandbox[編輯]
getPageContributingUsersWrite.py
#get the history of [[template:copyvio]] and dump it on [[wikipedia:sandbox]]
import wikipedia #importing the wikipedia.py module
site=wikipedia.getSite() # setting the site, from configuration
pg = wikipedia.Page(site, 'template:copyvio') #creating the Page object in question
x=pg.contributingUsers() #getting the contributing users
sand = wikipedia.Page(site, 'wikipedia:sandbox')
y = sand.get() #getting the current sandbox
for i in x:
y = y+i #appending the crap
sand.put( y , 'Robot testing: getting the contributing users of the page [[template:copyvio]] and dump the result on [[wikipedia:sandbox]]')
示範:
[5]
查看一下 special:newpages[編輯]
#to get a list of newpages from wikipedia.newpages()
import wikipedia
site=wikipedia.getSite()
newPageList = site.newpages()
for i in newPageList:
page, timestamp, length, empty, username, comment = i
t = page.title()
wikipedia.output('User:'+username+'.....Title:'+t)
示範:
C:\Python25\pywikipedia>python newPages.py
Checked for running processes. 2 processes currently running, including the curr
ent process.
User:Contributions/219.79.136.159.....Title:闆呰檸鐭ヨ瓨+
User:Contributions/219.79.136.159.....Title:XD
User:Contributions/219.79.136.159.....Title:Orz
User:Contributions/219.79.136.159.....Title:鍥?
User:Contributions/59.112.213.23.....Title:娓呴洸绉戞妧澶у
User:Happynewyear.....Title:1250骞?
User:Happynewyear.....Title:1251骞?
User:Happynewyear.....Title:1252骞?
User:Happynewyear.....Title:1253骞?
User:Happynewyear.....Title:1254骞?
C:\Python25\pywikipedia>
Perl[編輯]