User:Þjarkur/Project watchlist maker.js

/*

This is a Node.js script to create WikiProject watchlists. It is not a userscript.

const request = require('request') var fs = require('fs');

request({ method: 'GET',  rejectUnauthorized: false,  url: "https://petscan.wmflabs.org/",  headers: {    "Content-Type": "application/json",    "Accept": "application/json"  },  qs: {    categories: 'All Wikipedia vital articles',    language: 'en',    project: 'wikipedia',    depth: 2,    combination: 'subset',    show_redirects: 'both',    subpage_filter: 'either',    common_wiki: 'auto',    sortby: 'title',    sortorder: 'ascending',    wikidata_item: 'no',    wpiu: 'any',    cb_labels_yes_l: 1,    cb_labels_any_l: 1,    cb_labels_no_l: 1,    format: 'json',    output_compatability: 'catscan',    min_redlink_count: 1,    doit: 'Do it!',    interface_language: 'en',    active_tab: 'tab_output',  }, }, function (error, response, body) {  const data = JSON.parse(body)['*'][0]['a']['*'] //.slice(0, 10)  // console.log(data)  const entries = data.map(entry => { let namespace if (entry.namespace % 2) { namespace = entry.namespace - 1 } else { namespace = entry.namespace }   if (namespaces[namespace] !== undefined) { return { namespace, title: entry.title.replace(/_/g, ' ') }   } else { return null } }).filter(Boolean)  var d = new Date;

let doc = `__NOINDEX__

This page lists all Vital articles. It is used in order to show recent changes. It is a temporary solution until T117122 is resolved.

The list contains ${entries.length} articles and was last updated in ${m_names[d.getMonth]} of ${d.getFullYear}. ` let lastTitle = '' entries.forEach(({ title, namespace }) => {   if (lastTitle.slice(0, 1) !== title.slice(0, 1)) {      doc += `\n==${title.slice(0, 1)}==`    }    lastTitle = title    doc += `\n${namespaces[namespace]}${title}`    doc += ` `    doc += `•`  })

fs.writeFile(`WikiProjectMaker.txt`, doc, function (err) {   if (err) throw err;  }) });

const namespaces = { 0: '', 1: 'Talk:', 4: 'Wikipedia:', 5: 'Wikipedia talk:', 10: 'Template:', 11: 'Template talk:', 14: ':Category:', 15: 'Category talk:', }

var m_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];