https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
Web browser: --- Bug ID: 55149 Summary: setitem for wikidata doesn't work! Product: Pywikibot Version: unspecified Hardware: All OS: All Status: NEW Severity: normal Priority: Unprioritized Component: General Assignee: Pywikipedia-bugs@lists.wikimedia.org Reporter: legoktm.wikipedia@gmail.com Classification: Unclassified Mobile Platform: ---
Originally from: http://sourceforge.net/p/pywikipediabot/bugs/1587/ Reported by: reza1615 Created on: 2013-02-24 19:21:13 Subject: setitem for wikidata doesn't work! Original description: I used this code
#!/usr/bin/python # -*- coding: utf-8 -*- import wikipedia,login summary=u'آبشار لاتون,آبشار لاتون'
site=wikipedia.getSite('fa',fam='wikipedia') fapage=wikipedia.Page(site,u'آبشار_لاتون') data=wikipedia.DataPage(fapage)
list=data.get() id=list['entity'].replace('q','') data = wikipedia.DataPage(site.data_repository(), "Q"+id)
data.setitem(summary,items={'type': u'item', 'label': 'glk', 'value':u'آبشار_لاتون'}) data.setitem(summary,items={'type': u'sitelink', 'site': 'glk', 'title':u'آبشار_لاتون_(بارزاو)'})
it shows Updating page [[wikidata:Q5058182]] via API Updating page [[wikidata:Q5058182]] via API
but it doesn't update the page! also please add
def getIdFromPage(data) id=data.get() ['entity'].replace('q','') return id
and add
data = DataPage(site.data_repository(), "Q"+id)
to first line of setitem()
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #1 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- - **summary**: settime for wikidata doesn't work! --> setitem for wikidata doesn't work!
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #2 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- fixed in r11114 http://www.wikidata.org/w/index.php?title=Q5058182&diff=prev&oldid=7... http://www.wikidata.org/w/index.php?title=Q5058182&diff=prev&oldid=7...
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #3 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- Thank you now it works. please add these tree lines to setitem()
list=data.get() id=list['entity'].replace('q','') data = wikipedia.DataPage(site.data_repository(), "Q"+id)
now we should write these tree lines for every DataPage()
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #4 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- three :)
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #5 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- You don't need to create the DataPage a second time with the 'entity' item. Look at this sample which shows that data == d but they are different objects in this sample:
>>> import wikipedia as wp >>> s = wp.getSite() >>> p = wp.Page(s, 'Helium') >>> d = wp.DataPage(p) >>> i = d.get() >>> t = i['entity'].title() >>> data = wp.DataPage(s.data_repository(), t) >>> data DataPage{[[wikidata:Q560]]} >>> d DataPage{[[wikidata:Q560]]} >>> d is data False >>> d == data True >>>
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #6 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- If I don't make in DataPage a second time it will show this error
Updating page [[wikidata:None]] via API
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #7 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- This error looks like you haven't made a DataPage.get() before you tried to update the page. In this cas the title is None as shown. If you recreate the datapage with the entity id you make a explicit get call to retrieve the items data. But this will be enough to get the data's id i.e. the DataPage.title().
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #8 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- please run this code and you will see the none title error !
#!/usr/bin/python # -*- coding: utf-8 -*- import wikipedia,login summary=u'test bot'
site=wikipedia.getSite('fa',fam='wikipedia') fapage=wikipedia.Page(site,u'آبشار_لاتون') data=wikipedia.DataPage(fapage)
data.setitem(summary,items={'type': u'item', 'label': 'glk', 'value':u'آبشار_لاتون'}) data.setitem(summary,items={'type': u'sitelink', 'site': 'glk', 'title':u'آبشار_لاتون_(بارزاو)'})
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #9 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- I tested it and it worked: http://www.wikidata.org/w/index.php?title=Q5058182&diff=prev&oldid=7... We have showing problem. the code works well I think xqt means if you run this way the showing problem will be solved. something like this notice i just add one line: #!/usr/bin/python # -*- coding: utf-8 -*- import wikipedia,login summary=u'test bot'
site=wikipedia.getSite('fa',fam='wikipedia') fapage=wikipedia.Page(site,u'آبشار_لاتون') data=wikipedia.DataPage(fapage) gett=data.get() data.setitem(summary,items={'type': u'item', 'label': 'glk', 'value':u'آبشار_لاتون'}) data.setitem(summary,items={'type': u'sitelink', 'site': 'glk', 'title':u'آبشار_لاتون_(بارزاو)'})
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #10 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- we can load or get data inside setitem()
it is not normal that we type a code that it's variable ( gett=data.get() ) doesn't need! (visually)
it is logic that users only type this code
site=wikipedia.getSite('fa',fam='wikipedia') fapage=wikipedia.Page(site,u'آبشار_لاتون') data=wikipedia.DataPage(fapage) data.setitem(summary,items={'type': u'item', 'label': 'glk','value':u'آبشار_لاتون'})
Library should be let user to type minimal code.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #11 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- The line is not useless. If the item doesn't exist you will have an error instead of doing nothing
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #12 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- No! it is not correct !
now user should write
try: gett=data.get() except: some thing to do (may be saying error)
Instead of these four lines library should tell user that item doesn't exist so code should switch to create a new item.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #13 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- There are two ways doing that task creating an item; i'll explain it with a pseudocode:
1st: repo = repository(localpage) try: repo.createitem() except itemExistError: print repo.title(), 'already exist'
2st: repo = repository(localpage) if not repo.exists(): repo.createitem() else: print repo.title(), 'allready exits'
I prefer the last one. Look at this sample: >>> import wikipedia as wp >>> p = wp.Page('de', 'Helium') >>> d = wp.DataPage(p) >>> d DataPage{[[wikidata:None]]} >>> d.exists() True >>> d DataPage{[[wikidata:Q560]]} >>>
This means you does not need to call DataPage.get() you may also use DataPage.exists() for this test.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #14 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- in this report I don't want to make an item! I know about making an item amir solved it in last report (https://www.mediawiki.org/wiki/Special:Code/pywikipedia/11103%5C)
Now I want update an item with wikipedia.py for updating an item we should call data object with .get() or .exists() or other functions to let wikipedia.py load that data object and it is not good because user should write 4 lines in every part of his code you can add these lines to library to not repeating.
for setitem() you can add
if d.exists(): pass # pass or doing next lines else: print 'page not exist do you want creat it? '# or it can call creatitem() function if user allowed bot to create not existed item
for createitem() you can add
if d.exists(): print 'page exists so creating process is aborted?'# or we can ask user do you want overwrite? else: pass # pass or doing next lines
it should be done by library not users. because minimal coding is much better than writing repeated lines! if I want to create or edit an item I should add these 4 lines to my code but if they are inside wikipedia.py we don't need to write them.
it makes easy for coding . now calling .get() or .exists() is tricky and every user don't know and they will have problem with this!
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #15 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- How could you update an item without knowing its content?
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #16 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- when we write my_data = wp.DataPage(p) my_data should contained item! now for loading data to my_data we shod type .get() or .exist() which are not necessary
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #17 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- What does you meen with .get is not necessary? For getting a content, create an object and assign it to an alias:
# rewrite branch myPage = wikipedia.Page(wikipedia.getSite(), 'Helium') content = myPage.text myPage.text = u'This is a new content' myPage.put() # put it to the web
# trunk release myPage = wikipedia.Page(wikipedia.getSite(), 'Helium') content = myPage.get() content = u'This is a new content' myPage.put(content) # put it to the web
# wikidata myData = wikipedia.DataPage(1234) entity = myData.get() content = {...} myData.setitem('changing an item', content) # put it to the web
In all three samples you do not need to call the getter. But for that case you derived a DataPage from a Page object you have explicit to retrieve the data from the repository site before you can put any data back. Ok I guess you expect something like this should be possible:
myPage = wikipedia.Page(wikipedia.getSite(), 'Helium') myData = wikipedia.DataPage(myPage) content = {...} myData.setitem('changing an item', content) # put it to the web
Am I right?
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #18 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- Yes in my opinion code should be like below (as you said in last comment) and before DataPage() library should load myData by itself without other lines! (minimal code) and this loading could be done in setitem()
myPage = wikipedia.Page(wikipedia.getSite(), 'Helium') myData = wikipedia.DataPage(myPage) content = {...} myData.setitem('changing an item', content) # put it to the web
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #19 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- Ok I agree. Sorry for misunderstanding you.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
--- Comment #20 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- Please add it to setitem :)
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://sourceforge.net/p/p | |ywikipediabot/bugs/1587
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
Nemo federicoleva@tiscali.it changed:
What |Removed |Added ---------------------------------------------------------------------------- Component|General |Wikidata
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
Amir Ladsgroup ladsgroup@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Priority|Unprioritized |Lowest CC| |ladsgroup@gmail.com, | |reza.energy@gmail.com Version|unspecified |compat (1.0) Summary|setitem for wikidata |DataPage should get the |doesn't work! |content once defined Severity|normal |enhancement
--- Comment #21 from Amir Ladsgroup ladsgroup@gmail.com --- After lots of discussions people agreed to add .get() once a person defines a DataPage. I strongly disagree and (we don't run get() once we define a Page).
Honestly I think we need to close this as WONTFIX
https://bugzilla.wikimedia.org/show_bug.cgi?id=55149
Ricordisamoa ricordisamoa@openmailbox.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |WONTFIX
--- Comment #22 from Ricordisamoa ricordisamoa@openmailbox.org --- Per consistency with Page (also, to avoid loading data when not needed)
pywikipedia-bugs@lists.wikimedia.org