User:Rick Bot/scripts/newnoms

#!/bin/bash

# find newly promoted FAs and propose a nominator

# figure out this month and last month
YEAR=`date +%Y`
MONTH=`date +%B`

function prevmonth () {
  case $1 in
    January) echo "December";;
    February) echo "January";;
    March) echo "February";;
    April) echo "March";;
    May) echo "April";;
    June) echo "May";;
    July) echo "June";;
    August) echo "July";;
    September) echo "August";;
    October) echo "September";;
    November) echo "October";;
    December) echo "November";;
  esac
}

function check_month () {
  # $1 is MONTH, $2 is YEAR
  M=$1
  Y=$2
  echo "checking month - $M $Y"

  # get the noms for this month
  /usr/bin/curl "http://en.wikipedia.org/w/index.php?title=Wikipedia:Featured_article_candidates/Featured_log/${M}_${Y}&action=raw" >FAnoms.$Y.$M

  # get the current year list by nominator
  if [ ! -s FAnoms.$Y -a -s FAnoms.$Y.test ]; then
    cp FAnoms.$Y.test FAnoms.$Y 
  fi

  if [ ! -s FAnoms.$Y ]; then
    /usr/bin/curl "http://en.wikipedia.org/w/index.php?title=Wikipedia:Featured_articles_promoted_in_${Y}&action=raw" >FAnoms.$Y
    if [ ! -s FAnoms.$Y ]; then
      echo "*--- No Wikipedia:Featured_articles_promoted_in_${Y}?"
      exit
    fi
  fi

  echo "Wikipedia:Featured_article_candidates/Featured_log/${M}_${Y}"
  rm -f FAadd.$M
  MATCHED_ONE="no"
  # figure out nominator for each article we don't know about yet
  echo | cat FAnoms.$Y.$M - | while read FANOM; do
    FAFILE=`echo "$FANOM" | sed -e "s/^{{Wikipedia:Featured.article.candidates.//" -e "s/}}$//"`
    FA=${FAFILE%/archiv*}
    if [ "$FANOM" = "$FA" ]; then
      continue
    fi
    grep "^[|][|] *[[][[]$FA\]]" FAnoms.$Y >/dev/null
    if [ $? -eq 0 ]; then
      echo "Already know about $FA"
      MATCHED_ONE="yes"
      break
    fi
    NOM=`getnom "$FAFILE"`
    echo -n "Newnom: $FA --> $NOM ? "
    read ANS <&2
    if [ "$ANS" != "" ]; then
      NOM=$ANS
    fi
    echo "addnom||$FA||$NOM" >> FAadd.$M
  done

  if [ -s FAadd.$M ]; then
    addnoms $M $Y
  fi
}

function getnom () {
  # $1 is article
  echo getnom $1 >&2
  # f=`echo "$1" | cut -n -d '|' -f1 | tr " " "_"`
  f=`echo "$1" | cut -d '|' -f1 | tr " " "_"`
  echo "f=$f" >&2
  /usr/bin/curl "http://en.wikipedia.org/w/index.php?title=Wikipedia:Featured_article_candidates/$f&action=raw" | awk -v YEAR=$YEAR -v MONTH=$MONTH '
{
  gsub(/[=][=][=][=]/,"",$0)
}
$0 ~ "^===" {
  sub(/^[=][=][=]/,"",$0)
  article=$0
  sub(/[=][=][=].*/,"",article)
}

/[[][[][uU][sS][eE][rR]:/ {
  if (article != "") {
    noms=1
    user[noms] = $0
    while ( user[noms] ~ /[[][[][uU][sS][eE][rR]:/ && user[noms] !~ /^[[][[][uU][sS][eE][rR]:/ ) {
      sub(/^.[^[]*/,"",user[noms])
      if (user[noms] ~ /^[[][[][uU][sS][eE][rR]:/ ) {
        sub(/^[^[]*[[][[][uU][sS][eE][rR]:/,"",user[noms])
        user[noms+1] = user[noms]
        sub(/].*/,"",user[noms])
        sub(/[|].*/,"",user[noms])
        users[user[noms]] = users[user[noms]] + 1
        noms=noms+1
      }
    }
    # [[August]] [[2005]] ||  || [[Gray Wolf]] || [[user:Sango123|Sango123]]
    printf ("%s", "[[user:" user[1] "|" user[1] "]]")
    for (i=2; i<noms; i++) {
       printf(" & %s",  "[[user:" user[i] "|" user[i] "]]")
    }
    printf("\n")
    article = ""
  }
}' 

}

function addnoms() {
  # $1 is MONTH
  # $2 is YEAR
  echo addnoms $1 $2 >&2
  cat FAadd.$1 FAnoms.$2 | awk -v YEAR=$2 -v MONTH=$1 '
BEGIN {
  FS="\\|\\|"
  n=0
}

/^addnom/ {
  n++
  art[n] = $2
  nom[n] = $3
  next
}

/^== Promoted in |[[][[]Category:/ && (n>0) {
  if ($0 ~ MONTH " " YEAR) {
    print $0
    while ( $0 !~ /!Article!!Main page date/ ) {
      getline
      print $0
    }
    for (i=1; i <= n; i++) {
      print "|-"
      print "|| [[" art[i] "]] ||  || " nom[i]
    }
  } else {
    print "== Promoted in " MONTH " " YEAR " =="
    print ":'"''"'See logs at [[Wikipedia:Featured article candidates/Featured log/" MONTH " " YEAR "]]'"''"'"
    print "{| class=\"wikitable\" style=\"margin:auto;\" width=\"90%\""
    print "|-"
    print "!Article!!Main page date!!Nominator"
    for (i=1; i <= n; i++) {
      print "|-"
      print "|| [[" art[i] "]] ||  || " nom[i]
    }
    print "|}"
    print ""
    print $0
  }
  n=0
  next
}

{
  print $0
}' >FAnoms.$2.new

}

LASTMONTH=`prevmonth $MONTH`
LASTYEAR=$YEAR
if [ $LASTMONTH = "December" ]; then
  let LASTYEAR=$LASTYEAR-1
fi

rm -f FAnoms.$YEAR
rm -f FAnoms.$LASTYEAR
rm -f FAnoms.$YEAR.new
rm -f FAnoms.$LASTYEAR.new

check_month $LASTMONTH $LASTYEAR
if [ -s FAnoms.$LASTYEAR.new ]; then
  mv FAnoms.$LASTYEAR.new FAnoms.$LASTYEAR
fi

check_month $MONTH $YEAR
if [ -s FAnoms.$YEAR.new ]; then
  mv FAnoms.$YEAR.new FAnoms.$YEAR
fi

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.