[pywikibot] Re: Private wiki configuration/Get page from id

2023-05-12 Thread mlois_-gr
I realize that setting isPublic to false actually does not solve my problems :( 
There is something wrong in my local settings…
But… Thank you so much JJMC89 !!!
This works :
> import pywikibot as pwb
> import pywikibot.pagegenerators as pwbpg
> 
> site = pwb.Site()
> 
> def get_page_by_id(site, id):
> res = None
> for pg in pwbpg.PagesFromPageidGenerator(str(id), site):
> if res == None:
> res = pg
> else:
> raise Exception("Too many results") #probably useless
> return res
___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/JNM3BOICN53F4QYYEQ7OAYBDCSHK7RFK/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Private wiki configuration/Get page from id

2023-05-11 Thread Bináris
JJMC89  ezt írta (időpont: 2023. máj. 12., P,
1:12):

> There isn't a way to instantiate `Page` from an id.
>

But perhaps should be. Title is not always good for restoring the same page.

Your page id is 1. Sb. renames it – the actual article will have other
title with id 1, the redirect page the old title with new id. However, you
cannot be sure that the redirect leads to the old page at any time! While
manually check the logs is simply, to create an algorithm that finds the
original is very complicated.

The other case is deletion and recreation, that is not a big problem.

So I think page from id is a legal use case.
___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/DVPQASBZZWETZ5BXFTS4PIJ5GO7SFQRH/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Private wiki configuration/Get page from id

2023-05-11 Thread JJMC89
There isn't a way to instantiate `Page` from an id. You need a title.
What you are attempting with page_from_repository is for sites with a
Wikibase repository and uses the Wikibase QID, not the page id from the
database.

The closest is site.load_pages_from_pageids
,
which creates a generator yielding `Page`s by querying for the titles.
pagegenerators.PagesFromPageidGenerator

wraps around that for use on the CLI (-pageid).
I usually have some variation of the below when using pywikibot's page
generators on the CLI.

local_args = pywikibot.handle_args()
site = pywikibot.Site()
gen_factory = pywikibot.pagegenerators.GeneratorFactory(site)
script_args = gen_factory.handle_args(local_args)
gen = gen_factory.getCombinedGenerator(preload=True)

If you're querying your DB, you may find pagegenerators.MySQLPageGenerator

(-mysqlquery)
useful.


Regards,
JJ


On Thu, May 11, 2023 at 3:13 PM  wrote:

> It seems problem2 was just about adding
> >def isPublic(self):
> >return False
> in my family file :
> https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis#Bot_&_private_wikis
> Sorry I hadn't found that earlier.
>
> Problem 1 remains :
> >I'm trying to instantiate a `Page` based on its id, but I can't seem to
> find
> >something that does… The closest to it seems to be
> >"page_from_repository(pageId)", but I get
> "pywikibot.exceptions.UnknownExtensionError: Wikibase is not implemented
> for [mywikifamily:fr]."
> >From there on, I don't know what to do.
> ___
> pywikibot mailing list -- pywikibot@lists.wikimedia.org
> Public archives at
> https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/OEEY4APDQGS2QTZ2ME5H4TR3VBIV6VFL/
> To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org
>
___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/4MDJSVXBAD7RVY2DUYGQ4KBW67SL7BCV/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Private wiki configuration/Get page from id

2023-05-11 Thread mlois_-gr
It seems problem2 was just about adding 
>def isPublic(self):
>return False
in my family file : 
https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis#Bot_&_private_wikis
Sorry I hadn't found that earlier.

Problem 1 remains : 
>I'm trying to instantiate a `Page` based on its id, but I can't seem to find
>something that does… The closest to it seems to be
>"page_from_repository(pageId)", but I get  
>"pywikibot.exceptions.UnknownExtensionError: Wikibase is not implemented for 
>[mywikifamily:fr]."
>From there on, I don't know what to do.
___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/OEEY4APDQGS2QTZ2ME5H4TR3VBIV6VFL/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Private wiki configuration/Get page from id

2023-05-11 Thread mlois_-gr
when I say page id it is the page id in the database, which can be used 
directly using curid, e.g : https://en.wikipedia.org/wiki/?curid=
___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/4CDKGGJQX5AVXOGEZIVAMD7ULOJUMAGV/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org