Page MenuHomePhabricator

add WbTime.today() to pywikibot
Closed, ResolvedPublic

Description

Method for turning todays date into a WbTime. This is used whenever setting fetch dates etc. for references.

Something like:

def today_as_WbTime():
    """Get todays date as a WbTime object.

    @return: Todays date correctly formated
    @rtype: pywikibot.WbTime
    """
    today = datetime.today()
    date = pywikibot.WbTime(year=today.year,
                            month=today.month,
                            day=today.day)
    return date

Related Objects

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptApr 2 2016, 3:51 PM

Alternatively instead of sticking this in __-init.py__.WbTime it could go inte some helper class... if someone can recommedn a good place.

Xqt added a subscriber: Xqt.Apr 2 2016, 5:45 PM

Couldn't Timestamp be used for that?

True if we introduce a fromTimestamp() to __-init.py__.WbTime which goes from (possibly both ways) pywikibot.Timestamp to WbTime

then:
today = pywikibot.WbTime.fromTimestamp(pywikibot.Timestamp.today()) should do it.

techically this can be done already using
today = pywikibot.WbTime.fromTimestr(pywikibot.Timestamp.today().isoformat()) but I think it would make sense to have a converter to go from one of our time formats to the other.

jayvdb added a subscriber: jayvdb.Apr 3 2016, 11:19 AM

Where do we need to use this today value in wikidata? i.e. What is an example use for this, in a statement for which property?

Lokal_Profil added a comment.EditedApr 3 2016, 12:05 PM

Any time a statement is sourced/referenced using a web page accessed during the run (i.e. P813). I.e. essentially any bot which adds references.

Change 281301 had a related patch set uploaded (by Lokal Profil):
Make WbTime from Timestamp and vice versa

https://gerrit.wikimedia.org/r/281301

Found the open patchset related to this. There is still a need for it and the patch should still be mergeable (I just rebased it).

If someone would be willing to review or argue for why it isn't needed.

Thanks for the feedback @jayvdb I've implemented the suggestions in a new patch-set.

Xqt closed this task as Resolved.Apr 12 2017, 12:50 PM
Xqt claimed this task.
Xqt triaged this task as High priority.

Change 281301 merged by jenkins-bot:
[pywikibot/core@master] Make WbTime from Timestamp and vice versa

https://gerrit.wikimedia.org/r/281301