Last modified: 2014-07-24 12:56:03 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T57149, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 55149 - DataPage should get the content once defined
DataPage should get the content once defined
Status: RESOLVED WONTFIX
Product: Pywikibot
Classification: Unclassified
Wikidata (Other open bugs)
compat-(1.0)
All All
: Lowest enhancement
: ---
Assigned To: Pywikipedia bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-05 04:33 UTC by Kunal Mehta (Legoktm)
Modified: 2014-07-24 12:56 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Kunal Mehta (Legoktm) 2013-10-05 04:33:09 UTC
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\(\)
Comment 1 Kunal Mehta (Legoktm) 2013-10-05 04:33:11 UTC
- **summary**: settime for wikidata doesn't work! --> setitem for wikidata doesn't work!
Comment 3 Kunal Mehta (Legoktm) 2013-10-05 04:33:15 UTC
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\(\)
Comment 4 Kunal Mehta (Legoktm) 2013-10-05 04:33:17 UTC
three :\)
Comment 5 Kunal Mehta (Legoktm) 2013-10-05 04:33:18 UTC
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
>>>
Comment 6 Kunal Mehta (Legoktm) 2013-10-05 04:33:20 UTC
If I don't make in DataPage a second time it will show this error

Updating page \[\[wikidata:None\]\] via API
Comment 7 Kunal Mehta (Legoktm) 2013-10-05 04:33:22 UTC
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\(\).
Comment 8 Kunal Mehta (Legoktm) 2013-10-05 04:33:24 UTC
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'آبشار\_لاتون\_\(بارزاو\)'\}\)
Comment 9 Kunal Mehta (Legoktm) 2013-10-05 04:33:25 UTC
I tested it and it worked:
http://www.wikidata.org/w/index.php?title=Q5058182&diff=prev&oldid=7790985
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'آبشار\_لاتون\_\(بارزاو\)'\}\)
Comment 10 Kunal Mehta (Legoktm) 2013-10-05 04:33:27 UTC
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.
Comment 11 Kunal Mehta (Legoktm) 2013-10-05 04:33:29 UTC
The line is not useless. If the item doesn't exist you will have an error instead of doing nothing
Comment 12 Kunal Mehta (Legoktm) 2013-10-05 04:33:31 UTC
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.
Comment 13 Kunal Mehta (Legoktm) 2013-10-05 04:33:32 UTC
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.
Comment 14 Kunal Mehta (Legoktm) 2013-10-05 04:33:34 UTC
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\)

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\!
Comment 15 Kunal Mehta (Legoktm) 2013-10-05 04:33:36 UTC
How could you update an item without knowing its content?
Comment 16 Kunal Mehta (Legoktm) 2013-10-05 04:33:38 UTC
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
Comment 17 Kunal Mehta (Legoktm) 2013-10-05 04:33:39 UTC
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?
Comment 18 Kunal Mehta (Legoktm) 2013-10-05 04:33:41 UTC
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
Comment 19 Kunal Mehta (Legoktm) 2013-10-05 04:33:43 UTC
Ok I agree. Sorry for misunderstanding you.
Comment 20 Kunal Mehta (Legoktm) 2013-10-05 04:33:45 UTC
Please add it to setitem :\)
Comment 21 Amir Ladsgroup 2014-07-24 09:21:54 UTC
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
Comment 22 Ricordisamoa 2014-07-24 12:56:03 UTC
Per consistency with Page (also, to avoid loading data when not needed)

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links