For faster navigation, this Iframe is preloading the Wikiwand page for User:Paoting/英语维基百科特色条目/脚本.

User:Paoting/英语维基百科特色条目/脚本

用到的API

[编辑]

在Wikidata中用英语维基(enwiki)条目名`DNA'进行检索 得到中文维基(zhwiki)的结果:

"zhwiki": {
    "site": "zhwiki",
    "title": "\u8131\u6c27\u6838\u7cd6\u6838\u9178",
    "badges": [
        "Q17437796"
    ]
}

在奖章(badges)中,Q17437796代表特色条目,Q17437798代表优良条目。

代码

[编辑]
#!/usr/bin/perl

use Encode;
use utf8::all;
use LWP::Simple;

my $FA_list_html = get 'https://en.wikipedia.org/w/index.php?title=Wikipedia:Featured_articles&action=edit';
my ($FA_list_wiki) = ($FA_list_html =~ m/(==Art, .*)((WikiProject cleanup/s);

for my $line (split "\n", $FA_list_wiki) {
  $line =~ s/((FA\/BeenOnMainPage\|(.*)))/$1/;
  if ($line =~ m/(\|[^\]]+)]]/) {
    $line =~ s/\[\[/[[:en:/g;
  } else {
    $line =~ s/\[\[([^\]]+)/[[:en:$1|$1/g;
  }
  if ($line =~ m/:en:(.*)\|/) {
    my $article_name = $1;
    my $api_url = 'https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&utf8'
                  . '&sites=enwiki&titles=' . $article_name;
    my $json_text = get $api_url;
    if ($json_text =~ m/{"site":"zhwiki","title":"([^"]+)","badges":\[([^\]]*)\]}/) {
      my $zh_title = decode_utf8($1);
      if ($2) {
        if ($2 =~ m/Q17437796/) {
          $line .= "<small>(((Faico)) [[$zh_title]])</small>";
        } else {
          $line .= "<small>(((Gaico)) [[$zh_title]])</small>";
        }
      } else {
        $line .= "<small>([[$zh_title]])</small>";
      }
    } else {
      $line .= "<small>([[$article_name]])</small>"
    }
  }
  print $line, "\n";
}

测试片段

[编辑]
==Art, architecture, and archaeology==
((FA/BeenOnMainPage|[[Statue of Liberty]]))
· ((FA/BeenOnMainPage|[[Four Freedoms (Norman Rockwell)|''Four Freedoms'' (Norman Rockwell)]]))
· [[Andean condor]]
· [[Alpine chough]]

((WikiProject cleanup listing|Wikipedia:Featured articles))

结果

[编辑]
==Art, architecture, and archaeology==
[[:en:Statue of Liberty|Statue of Liberty]]<small>(((Faico)) [[自由女神像]])</small>
· [[:en:Four Freedoms (Norman Rockwell)|''Four Freedoms'' (Norman Rockwell)]]<small>([[Four Freedoms (Norman Rockwell)]])</small>
· [[:en:Andean condor|Andean condor]]<small>(((Gaico)) [[安地斯神鷹]])</small>
· [[:en:Alpine chough|Alpine chough]]<small>([[黄嘴山鸦]])</small>

Statue of Liberty( 自由女神像) · Four Freedoms (Norman Rockwell)(Four Freedoms (Norman Rockwell)) · Andean condor( 安地斯神鷹) · Alpine chough(黄嘴山鸦)

Bug

[编辑]

因为需要访问4684次WikidataAPI页面,有时候会访问失败。

{{bottomLinkPreText}} {{bottomLinkText}}
User:Paoting/英语维基百科特色条目/脚本
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?