Monday, July 23, 2018

‘datetime.time object’ has no attribute ‘date’

How can lino_xl.lib.cal.Guest.waiting_since contain a datetime.time value?

>>> from lino import startup
>>> startup('lino_welfare.projects.eupen.settings.doctests')
>>> from lino.api.doctest import *
>>> translation.activate('fr')
>>> from django.utils import timezone
>>> now = timezone.now()
>>> now.date()
datetime.date(2018, 7, 23)
>>> type(now)
<type 'datetime.datetime'>

The presence_certificate.body.html was using lino_xl.lib.excerpts.Excerpt.time instead of lino_xl.lib.excerpts.Excerpt.date.

It took me half an hour to verify that this issue was actually already fixed in January 2018. But they didn’t yet upgrade since then, and I didn’t register the issue as a ticket. So now I opened #2443.

Using data from Wikidata

Yesterday I did my first steps with pywikibot.

My first script:

import pywikibot
site = pywikibot.Site('en', 'wikipedia')
page = pywikibot.Page(site, 'User:LucSaffre/sandbox')
page.text = page.text.replace('foo', 'bar')
page.save('Replaced foo by bar')  # Saves the page using the given summary

My second script:

from pprint import pprint
import pywikibot
site = pywikibot.Site('en', 'wikipedia')  # The site we want to run our bot on
if False:  # works
    page = pywikibot.Page(site, 'User:LucSaffre/sandbox')
    page.text = page.text.replace('foo', 'bar')
    page.save('kkk')  # Saves the page

# compare https://www.wikidata.org/wiki/Q3462598    
page = pywikibot.Page(site, "Vana-Vigala")
item = pywikibot.ItemPage.fromPage(page)
#print(item.get()['sitelinks'])
claims = item.get()['claims']
for k in claims.keys():
    print(k, claims[k])
    break

My first script with a concrete goal (it would be nice if my commondata project would become useless):

..literalinclude:: pwb/list_countries_and_isocode.py

Next step on that script would be to also print the claims (as explained in Data Harves tutorial). I got stuck when I realized that the ISO code fields seem to be empty when I run that query on https://query.wikidata.org

EDIT: I later also forked the wikidata project on GitHub and got the following script to tun:

from wikidatafun import getAllCountries
for i, c in enumerate(getAllCountries()):
    print(i, c)



TODO: