Manual talk:Pywikibot

Jump to navigation Jump to search

About this board

Archives 


Please use one of the communication channels listed on Manual:Pywikibot/Communication rather than using this discussion board. There is very little traffic here, so it may take a while before you get a response.

How to disable "Sleeping for N seconds" on PyWikiBot

5
Summary by Dvorapa

Sleeping for N seconds should not be disabled as it makes load to servers

95.188.216.190 (talkcontribs)

How to disable "Sleeping for N seconds" on PyWikiBot

Xqt (talkcontribs)

You shouldn't. This is necessary to throttle writing to the site high frequently and it is restricted on most wiki's.

Framawiki (talkcontribs)

Why you want to disable a security ? Not a good idea I think :)

Sergezolotukhin (talkcontribs)
Xqt (talkcontribs)

maxthrottle isn't the right parameter for that.

Deleting blank lines with replace.py inside templates

6
Theklan (talkcontribs)

Hello! I have been using replace.py to delete obsolete lines inside templates, but now I have some empty lines. I can't find a way to delete them... can someone help with this? Thanks!

Matěj Suchánek (talkcontribs)

Please share more information: What is your regex, what does your input look like, what do you expect?

Theklan (talkcontribs)
Matěj Suchánek (talkcontribs)

Don't you want to replace it with a single newline \n? The problem I can see is that there were some spaces between the newlines, which you can fix with \n *\n *\n.

Theklan (talkcontribs)

Thanks for the clue! Is there any other script to delete blank lines only inside templates?

Matěj Suchánek (talkcontribs)

None that I know.

Reply to "Deleting blank lines with replace.py inside templates"
Summary by Dvorapa

Everybody can use pywikibot, but please be careful to local community restrictions

SamiIslam (talkcontribs)

Hi,

Can a normal user use the pywikibot functionality from a wiki site to create a site from a text file? Or is that something only an admin would have to do on the server hosting the wiki?

Thanks!

Sami

Xqt (talkcontribs)

There is a script "pagefromfile.py" to do this but it is may be local community restrictions to allow or discard edits in this way.

Summary by Dvorapa

The combination of movepages.py and redirect.py can effectively move pages and update redirects. There is currently no script, which could do both actions at once

Jc86035 (talkcontribs)

Does movepages.py update redirects as well to avoid creating double redirects?

This post was hidden by Jc86035 (history)
Xqt (talkcontribs)

Currently not.

Jc86035 (talkcontribs)

Are there any scripts which do so?

XXN (talkcontribs)

redirect.py

Pagegenerator in different language.

3
Summary by Dvorapa

Pagegenerator for the Czech Wikipedia is -family:wikipedia -lang:cs

Walter Klosse (talkcontribs)

How i make pagegenerator for category on wikipedia in czech language?

Framawiki (talkcontribs)

Hello, do you want something like

python pwb.py replace "1" "2" -lang:cz -category:test

?

Dvorapa (talkcontribs)

correct is -lang:cs

Replacing template with text

4
Summary by Dvorapa

To work with templates there is a template.py script. It can easily get e.g. category of templates to process by -cat parameter

87.0.79.89 (talkcontribs)

Hi,

I need a script that:

1) Select pages that are in a specific category

2) Delete in those pages an old template with its parameters (that could also be sub-templates); the template is the same, but the content is different for all, so I can't specify manually the text

3) And replace it with a text (a new template with standard content for all)

It's possible? I see something in ''replace.py'' (point 1 and 3), but I'm not sure it can do the 2nd; and it seems that ''template.py'' can only replace the template name.

Glz19

Xqt (talkcontribs)

Try template.py script.

Glz19 (talkcontribs)

Thank you for the answer. It's possible with it selecting a category, for work only on pages in it? I read the documentation page but I can't see it.

Xqt (talkcontribs)

All scripts have a documentation with it. Just use -help option. In your case -cat:<categoryname> should do it.

148.177.1.215 (talkcontribs)

Hello,

I'm new to pywikibot and am stuck on getting a login failed (aborted) message.

When I try to use redirect.py with the argument "double" and am prompted for what action to take, whenever I choose to "accept changes" I get that the Login failed(aborted) even when I manually input the bot password.

The login works for other scripts such as pagefromfile or just simply using the login.py script.

Thanks for the help

Framawiki (talkcontribs)
148.177.1.215 (talkcontribs)

Thanks for the help,

here is the shell history after I ran the redirect.py command.

https://tools.wmflabs.org/paste/view/7003368e

The wikibot is initially able to login, but after it wants to make the first change it prompts the user for the password (The login will fail even with the right password).

Reply to "redirect.py Login Failed (Aborted)"

removing references from wikidata doesn't work

5
Summary by Soued031

false alarm

Soued031 (talkcontribs)

Hello, I found a bug in pywikibot but I am not sure if I use the method correctly. Deleting a reference does not seem to work. I'm using the last version from git. If you want I have a fix, but since I cannot find any documentation about pywikibot or an explanation of how a method should be written the fix seems out of place. Link with diff and the code that I'm right now using to modify wikidata: https://drive.google.com/drive/folders/1SgQym9-Gv0FGKw8tUuUyDEIIViEN_Eak?usp=sharing

Matěj Suchánek (talkcontribs)

The docstring of Claim.removeSources says: @type sources: list of pywikibot.Claim, which item.claims['P1082'][i].sources is not. That is a list of key: list of pywikibot.Claim mappings.

Soued031 (talkcontribs)

Thanks for you answer! So how does the code need to be changed as I haven't seen any example of removeSource(s)?I mean I understand that the type is wrong but how do I achieve the "right" type?

Matěj Suchánek (talkcontribs)

I hope this will work (it should remove all references attached to a statement):

sources = []
for source in claim.sources:
    for value in source.values():
        sources.extend(value)
item.removeSources(sources)
Soued031 (talkcontribs)

Thanks a lot your code snippet works!

Soued031 (talkcontribs)

Hello,

I've written a script whose goal is to write the population for https://www.wikidata.org/wiki/Q985476 (only at the moment) per year, which can be found here: https://drive.google.com/drive/folders/1s5ypAGF3u_PGtj9gyIkR7v0CCWdHBUNy?usp=sharing. When running the script I actually get 3 Warnings;

WARNING: /home/edson/Bureau/core/pywikibot/site.py:1331: _NotImplementedWarning: claim without on_item set is deprecated.

  return fn(self, *args, **kwargs)

WARNING: /home/edson/Bureau/core/pywikibot/site.py:1331: UserWarning: Neither claim.on_item nor baserevid provided

  return fn(self, *args, **kwargs)

WARNING: API error noclaim: The "claim" parameter must be set.

Traceback (most recent call last):

  File "pwb.py", line 263, in <module>

   if not main():

  File "pwb.py", line 256, in main

   run_python_file(filename, [filename] + args, argvu, file_package)

  File "pwb.py", line 120, in run_python_file

   main_mod.__dict__)

  File "./addPopulation.py", line 38, in <module>

   populationClaim.addQualifier(qualifier)

  File "/home/edson/Bureau/core/pywikibot/page.py", line 5002, in addQualifier

   data = self.repo.editQualifier(self, qualifier, **kwargs)

  File "/home/edson/Bureau/core/pywikibot/site.py", line 1331, in callee

   return fn(self, *args, **kwargs)

  File "/home/edson/Bureau/core/pywikibot/site.py", line 7813, in editQualifier

   data = req.submit()

  File "/home/edson/Bureau/core/pywikibot/data/api.py", line 2195, in submit

   raise APIError(**result['error'])

pywikibot.data.api.APIError: noclaim: The "claim" parameter must be set. [help:See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]

<class 'pywikibot.data.api.APIError'>

CRITICAL: Closing network session.

What am I doing wrong?

Dvorapa (talkcontribs)
Matěj Suchánek (talkcontribs)

How does your code look like?

Soued031 (talkcontribs)
Matěj Suchánek (talkcontribs)

Oops, I see now.

The solution is to move the bottom line (item.addClaim) just before # add qualifier to claim.

Soued031 (talkcontribs)

@Matěj Suchánek Great it works! Thanks for the fast answer. Do I need to do something special to ask for bot rights?

Matěj Suchánek (talkcontribs)

If you want to run a bot on Wikidata, I strongly recommend you requesting the flag at d:WD:RFBOT.

Soued031 (talkcontribs)

Thanks I will look at it.

148.177.1.215 (talkcontribs)

When I try to create a webpage on a 3rd party wiki using the pagefromfile script, it required me to log into my bot account a second time despite being already logged in (I used the python pwb.py login -sysop command prior),

The bot also has the proper rights to write/read a page on the wiki.

The page will properly post once I manually put in the bot password but if possible I would like to automate the process so that it does not require any input after calling the Pagefromfile function.

The paramters I am currently using are -file, -begin, -end, -notitle, -force.

The bot can use other functions such as weblinkchecker without requesting me to log in a second time

Reply to "Pagefromfile requires additional login"