All Projects → tomayac → pageviews.js

tomayac / pageviews.js

Licence: Apache-2.0 license
A lightweight JavaScript client library for the Wikimedia Pageviews API for Wikipedia and various of its sister projects for Node.js and the browser.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to pageviews.js

wikipedia for humans
No description or website provided.
Stars: ✭ 44 (+83.33%)
Mutual labels:  wikipedia, wikipedia-api
pageviews
Pageviews Analysis tool for Wikimedia Foundation wikis
Stars: ✭ 95 (+295.83%)
Mutual labels:  wikipedia, pageviews
wikiapi
JavaScript MediaWiki API for node.js
Stars: ✭ 28 (+16.67%)
Mutual labels:  wikipedia, wikipedia-api
wikipedia-live-monitor
No description or website provided.
Stars: ✭ 19 (-20.83%)
Mutual labels:  wikipedia, wikipedia-api
wiki-tui
A simple and easy to use Wikipedia Text User Interface
Stars: ✭ 74 (+208.33%)
Mutual labels:  wikipedia, wikipedia-api
wikifox
A clean and simplified WikiPedia powered by wikifox.js
Stars: ✭ 50 (+108.33%)
Mutual labels:  wikipedia, wikipedia-api
go-wikidata
Wikidata API bindings in go.
Stars: ✭ 27 (+12.5%)
Mutual labels:  wikipedia, wikipedia-api
wikipedia-api-docs
Wikipedia API documentation
Stars: ✭ 61 (+154.17%)
Mutual labels:  wikipedia, wikipedia-api
Zimpedia
Offline reader for Wikipedia
Stars: ✭ 18 (-25%)
Mutual labels:  wikipedia
word2vec-on-wikipedia
A pipeline for training word embeddings using word2vec on wikipedia corpus.
Stars: ✭ 68 (+183.33%)
Mutual labels:  wikipedia
citationhunt
A fun tool for quickly browsing unsourced snippets on Wikipedia.
Stars: ✭ 83 (+245.83%)
Mutual labels:  wikipedia
fetch
wik is use to get information about anything on the shell using Wikipedia.
Stars: ✭ 335 (+1295.83%)
Mutual labels:  wikipedia
lascallesdelasmujeres
Proyecto colaborativo para fomentar la generación de contenidos en OSM y Wikipedia, sobre mujeres.
Stars: ✭ 45 (+87.5%)
Mutual labels:  wikipedia
linkcount
Web program to see the number of links to a page in any Wikimedia project.
Stars: ✭ 26 (+8.33%)
Mutual labels:  wikipedia
illuminsight
💡👀 Read EPUB books with built-in insights from wikis, definitions, translations, and Google.
Stars: ✭ 55 (+129.17%)
Mutual labels:  wikipedia
entity-fishing
A machine learning tool for fishing entities
Stars: ✭ 176 (+633.33%)
Mutual labels:  wikipedia
Laosheng.top
老生常谈,节约您的搜寻时间。Laosheng.top 中国新闻云媒体,中央外宣与一带一路云媒体,五大洲的报纸、电视、通讯社;The Belt and Road Cloud Media。 解放军微博阵列,明星微博粉丝榜。中央有关部门大全,政府政协人大两院。中国千县地名图,联合国有关部门。 大萌望海楼,找法不用愁。中国法律体系概览,大萌法律读本。 老生常谈排行榜,难搜到的好网站。LSIP 大规模集成网页。😤
Stars: ✭ 21 (-12.5%)
Mutual labels:  wikipedia
youtube-video-maker
📹 A tool for automatic video creation and uploading on YouTube
Stars: ✭ 134 (+458.33%)
Mutual labels:  wikipedia
scalawiki
scalawiki is a MediaWiki client in Scala
Stars: ✭ 30 (+25%)
Mutual labels:  wikipedia-api
wikitable2csv
A web tool to convert Wiki tables to CSV 📈
Stars: ✭ 112 (+366.67%)
Mutual labels:  wikipedia

pageviews.js

Greenkeeper badge

A lightweight JavaScript client library for the Wikimedia Pageviews API for Wikipedia and various of its sister projects for Node.js and the browser.

Installation

With npm:

$ npm install pageviews

Usage in Node.js

The client library requires native or polyfilled Promises support. Below are some samples of how to use it in practice.

var pageviews = require('pageviews');

// Getting pageviews for a single article
pageviews.getPerArticlePageviews({
  article: 'Berlin',
  project: 'en.wikipedia',
  start: new Date(new Date() - 3 * 24 * 60 * 60 * 1000), // YYYYMMDD string or Date object
  end: new Date(new Date() - 2 * 24 * 60 * 60 * 1000) // YYYYMMDD string or Date object
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting pageviews for multiple articles
pageviews.getPerArticlePageviews({
  articles: ['Berlin', 'Hamburg'], // Plural
  project: 'en.wikipedia',
  start: new Date(new Date() - 3 * 24 * 60 * 60 * 1000),  // YYYYMMDD string or Date object
  end: new Date(new Date() - 2 * 24 * 60 * 60 * 1000) // YYYYMMDD string or Date object
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting aggregated pageviews for a single project
pageviews.getAggregatedPageviews({
  project: 'en.wikipedia',
  start: '2015120101', // YYYYMMDDHH string or Date object
  end: '2015120102' // YYYYMMDDHH string or Date object
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting aggregated pageviews for multiple projects
pageviews.getAggregatedPageviews({
  projects: ['en.wikipedia', 'de.wikipedia'], // Plural
  start: '2015120101', // YYYYMMDDHH string or Date object
  end: '2015120101' // YYYYMMDDHH string or Date object
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting top-n items ranked by pageviews for a single project
pageviews.getTopPageviews({
  project: 'en.wikipedia',
  year: '2015',
  month: '12',
  day: '01',
  limit: 2 // Limit to the first n results
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting top-n items ranked by pageviews for multiple projects
pageviews.getTopPageviews({
  projects: ['en.wikipedia', 'de.wikipedia'], // Plural
  year: '2015',
  month: '12', // Can also use integers like 12
  day: '01', // Can also use integers like 1
  limit: 2 // Limit to the first n results
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting top-n items ranked by pageviews for multiple projects
pageviews.getTopPageviews({
  projects: ['en.wikipedia', 'de.wikipedia'], // Plural
  date: new Date(new Date() - 2 * 24 * 60 * 60 * 1000), // YYYYMMDD string or Date object
  limit: 2 // Limit to the first n results
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting unique devices
pageviews.getUniqueDevices({
  project: 'en.wikipedia',
  start: '20160301',
  end: '20160301',
  accessSite: 'desktop-site'
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

// Getting legacy pagecounts
pageviews.getAggregatedLegacyPagecounts({
  project: 'en.wikipedia',
  start: new Date(2008, 12, 1, 1),
  end: new Date(2008, 12, 1, 2)
}).then(function(result) {
  console.log(JSON.stringify(result, null, 2));
}).catch(function(error) {
  console.log(error);
});

Usage in the browser

You can build a minified version of pageviews.js by running the build script.

$ npm run build

You can then use the file in the browser as follows.

<script src="pageviews.min.js"></script>
<script>
  // Getting pageviews for a single article
  pageviews.getPerArticlePageviews({
    article: 'Berlin',
    project: 'en.wikipedia',
    start: new Date(new Date() - 3 * 24 * 60 * 60 * 1000), // YYYYMMDD string or Date object
    end: new Date(new Date() - 2 * 24 * 60 * 60 * 1000) // YYYYMMDD string or Date object
  }).then(function(result) {
    console.log(JSON.stringify(result, null, 2));
  }).catch(function(error) {
    console.log(error);
  });

  /* All functions as defined in the Node.js section */
</script>

API

The API is modeled along the Wikimedia Pageviews API and the Wikimedia Unique Devices API and offers the following methods:

/**
 * This is the root of all pageview data endpoints. The list of paths that
 * this returns includes ways to query by article, project, top articles,
 * etc. If browsing the interactive documentation, see the specifics for
 * each endpoint below.
 */
getPageviewsDimensions

/**
 * Given a Mediawiki article and a date range, returns a daily timeseries of
 * its pageview counts. You can also filter by access method and/or agent
 * type.
 */
getPerArticlePageviews

/**
 * Given a date range, returns a timeseries of pageview counts. You can
 * filter by project, access method and/or agent type. You can choose
 * between daily and hourly granularity as well.
 */
getAggregatedPageviews

/**
 * Lists the 1000 most viewed articles for a given project and timespan
 * (year, month or day). You can filter by access method.
 */
getTopPageviews

/**
 * Given a date range between December 2007 and August 2016,
 * returns a timeseries of pageview counts. You can filter by
 * project and access method. You can choose between daily,
 * hourly and monthly granularity as well.
 */
 getAggregatedLegacyPagecounts

/**
 * Given a project and a date range, returns a timeseries of unique devices
 * counts. You can filter by access site and choose between daily and
 * monthly granularity.
 */
getUniqueDevices

Contributors

License

Copyright 2017 Thomas Steiner (@tomayac)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

NPM

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].