Bugs item #3605830, was opened at 2013-02-24 11:21
Message generated for change (Comment added) made by nobody
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=3605830&group_id=93107

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: reza  (reza1615)
Assigned to: Nobody/Anonymous (nobody)
Summary: setitem for wikidata doesn't work!

Initial Comment:
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 By: Nobody/Anonymous (nobody)
Date: 2013-02-26 05:05

Message:
The line is not useless. If the item doesn't exist you will have an error
instead of doing nothing

----------------------------------------------------------------------

Comment By: reza  (reza1615)
Date: 2013-02-26 05:02

Message:
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 By: Nobody/Anonymous (nobody)
Date: 2013-02-26 04:45

Message:
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 By: reza  (reza1615)
Date: 2013-02-26 04:32

Message:
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 By: xqt (xqt)
Date: 2013-02-25 23:38

Message:
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 By: reza  (reza1615)
Date: 2013-02-25 04:40

Message:
If I don't make in DataPage a second time it will show this error

Updating page [[wikidata:None]] via API


----------------------------------------------------------------------

Comment By: xqt (xqt)
Date: 2013-02-25 03:43

Message:
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 By: reza  (reza1615)
Date: 2013-02-25 02:35

Message:
three :)

----------------------------------------------------------------------

Comment By: reza  (reza1615)
Date: 2013-02-25 02:34

Message:
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 By: Amir  (amird)
Date: 2013-02-24 21:58

Message:
fixed in r11114
http://www.wikidata.org/w/index.php?title=Q5058182&diff=prev&oldid=7673026
http://www.wikidata.org/w/index.php?title=Q5058182&diff=prev&oldid=7673011

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=3605830&group_id=93107

_______________________________________________
Pywikipedia-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-bugs

Reply via email to