使用 Python 更新媒体 wiki 文章?

发布于 2024-10-08 19:49:40 字数 194 浏览 5 评论 0原文

你好 我有一个 cron 作业,它收集有关服务的一些统计信息。我需要 cron 作业以编程方式更新媒体 wiki 页面(附加到页面)。 我在 cron 中使用 python,那么我最好的选择是什么,是否有 mediawiki/python 库的示例,或者 Media wiki 是否公开了我可以使用的任何 HTTP/REST api(可能通过扩展)。

谢谢

Hi
I have a cron job which collects some statistics about a service. I need the cron job to update a media wiki page (append to the page) programmatically.
I am using python for the cron so what are my best options, are there any examples of mediawiki/python libraries or does Media wiki expose any HTTP/REST apis which I can use (may be through an extension).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

强辩 2024-10-15 19:49:40

如果 PyWikipediaBot 太重,请尝试 Python 模块 mwclient

您可以登录、查看页面的当前内容、进行更改,然后在不到 10 行的时间内查看它(示例)

import mwclient
site = mwclient.Site('en.wikipedia.org')
site.login('Pfctdayelise','password')
page = site.Pages['User:Pfctdayelise/Test']
text = page.edit()
print text.encode('utf-8')
newtext = "\n\nTesting the write api without logging in.\n"
page.save(text+newtext,summary='testing write api')

If PyWikipediaBot is too heavy, try the Python module mwclient.

You can login, view a page’s current content, make your change and then view it in less than 10 lines (example).

import mwclient
site = mwclient.Site('en.wikipedia.org')
site.login('Pfctdayelise','password')
page = site.Pages['User:Pfctdayelise/Test']
text = page.edit()
print text.encode('utf-8')
newtext = "\n\nTesting the write api without logging in.\n"
page.save(text+newtext,summary='testing write api')
∞觅青森が 2024-10-15 19:49:40

如果您在与 cron 作业相同的计算机上运行 mediawiki,则可以使用 maintanence 目录中的 edit.php 脚本。

/bin/python /opt/page_renderer.py | php /var/www/mediawiki/maintenance/edit.php -b PageTitle

在此示例中,/opt/page_renderer.py 输出 wiki markdown。这将通过管道传输到具有 -b 标志(将其标记为机器人编辑)和您要编辑的页面标题的编辑脚本。

当然,您可以从任何程序通过管道输入编辑脚本,如果您在不同的地方安装了 mediawiki,则可能需要更改编辑脚本的路径。

If you are running mediawiki on the same computer as the cron job, then you can use the edit.php script found in the maintanence directory.

/bin/python /opt/page_renderer.py | php /var/www/mediawiki/maintenance/edit.php -b PageTitle

In this example, /opt/page_renderer.py outputs wiki markdown. This gets piped to the edit script which has the -b flag (to mark it as a bot edit) and the title of the page you wish to edit.

Naturally, you can pipe from any program into the edit script, and you might need to change the path to the edit script if you have mediawiki installed somewhere different.

缘字诀 2024-10-15 19:49:40

作为
的提交者
https://github.com/WolfgangFahl/py-3rdparty-mediawiki
我推荐这个库的命令行功能,它允许
您可以直接从脚本使用标记。

该库与 Semantic MediaWiki 配合使用效果最佳,您可以在其中查询您感兴趣的页面:

$ wikibackup -s orth --backupPath "/home/user/wikibackup/orth_copy" -q "[[isA::Event]]" --limit 10


downloading 10 pages from orth to /home/user/wikibackup/orth_copy

1/10 (  10%): downloading " DBKDA 2021" ...✅
2/10 (  20%): downloading "ENERGY 2021" ...✅
3/10 (  30%): downloading "ICAS 2021" ...✅
4/10 (  40%): downloading "ICNS 2021" ...✅
5/10 (  50%): downloading 2021 ICIMP ...✅
6/10 (  60%): downloading 3DUI 2020 ...✅
7/10 (  70%): downloading 3IA 2009 ...✅
8/10 (  80%): downloading 3PGIC 2010 ...✅
9/10 (  90%): downloading 4S4D 2017 ...✅
10/10 ( 100%): downloading 5GU 2017 ...✅

修改标记后,您可以使用以下命令恢复页面:

wikirestore -t orth --backupPath "/home/user/wikibackup/orth_copy"

restoring 10 pages from /home/user/wikibackup/orth_copy to orth
1/10 (  10%): restore 2021 ICIMP ...✅
2/10 (  20%): restore "ICNS 2021" ...✅
3/10 (  30%): restore 3PGIC 2010 ...✅
4/10 (  40%): restore 4S4D 2017 ...✅
5/10 (  50%): restore "ENERGY 2021" ...✅
6/10 (  60%): restore 3DUI 2020 ...✅
7/10 (  70%): restore " DBKDA 2021" ...✅
8/10 (  80%): restore 3IA 2009 ...✅
9/10 (  90%): restore "ICAS 2021" ...✅
10/10 ( 100%): restore 5GU 2017 ...✅

As a committer of
https://github.com/WolfgangFahl/py-3rdparty-mediawiki
i am recommending the command line functionality of this library which allows
you to work with the markup directly from a script.

The library works best with a Semantic MediaWiki where you can query the pages your are interested in:

$ wikibackup -s orth --backupPath "/home/user/wikibackup/orth_copy" -q "[[isA::Event]]" --limit 10


downloading 10 pages from orth to /home/user/wikibackup/orth_copy

1/10 (  10%): downloading " DBKDA 2021" ...✅
2/10 (  20%): downloading "ENERGY 2021" ...✅
3/10 (  30%): downloading "ICAS 2021" ...✅
4/10 (  40%): downloading "ICNS 2021" ...✅
5/10 (  50%): downloading 2021 ICIMP ...✅
6/10 (  60%): downloading 3DUI 2020 ...✅
7/10 (  70%): downloading 3IA 2009 ...✅
8/10 (  80%): downloading 3PGIC 2010 ...✅
9/10 (  90%): downloading 4S4D 2017 ...✅
10/10 ( 100%): downloading 5GU 2017 ...✅

after modifying the markup you can restore the pages with:

wikirestore -t orth --backupPath "/home/user/wikibackup/orth_copy"

restoring 10 pages from /home/user/wikibackup/orth_copy to orth
1/10 (  10%): restore 2021 ICIMP ...✅
2/10 (  20%): restore "ICNS 2021" ...✅
3/10 (  30%): restore 3PGIC 2010 ...✅
4/10 (  40%): restore 4S4D 2017 ...✅
5/10 (  50%): restore "ENERGY 2021" ...✅
6/10 (  60%): restore 3DUI 2020 ...✅
7/10 (  70%): restore " DBKDA 2021" ...✅
8/10 (  80%): restore 3IA 2009 ...✅
9/10 (  90%): restore "ICAS 2021" ...✅
10/10 ( 100%): restore 5GU 2017 ...✅
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文