-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from spencermountain/dev
Dev
- Loading branch information
Showing
23 changed files
with
359 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tests | ||
contributing.md | ||
scratch.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,54 @@ | ||
const config = require('../config'); | ||
const chalk = require('chalk'); | ||
const niceNumber = require('../lib/fns').niceNumber; | ||
const MongoClient = require('mongodb').MongoClient | ||
const openDb = require('../src/lib/open-db') | ||
const niceNumber = require('../src/lib/fns').niceNumber; | ||
const dbName = process.argv[2] || 'enwiki' | ||
|
||
const open = function(_dbName, callback) { | ||
let url = 'mongodb://localhost:27017/' + _dbName | ||
MongoClient.connect(url, function(err, db) { | ||
if (err) { | ||
console.log(err) | ||
process.exit(1) | ||
const showPage = async function(col) { | ||
// int = parseInt(int, 10) | ||
let docs = await col.aggregate( | ||
{ | ||
$sample: { | ||
size: 1 | ||
} | ||
} | ||
callback(db) | ||
}) | ||
} | ||
) | ||
console.log(docs) | ||
// let docs = await col.find({}, { | ||
// skip: int, | ||
// limit: 1 | ||
// }) | ||
// console.log(docs.toArray()) | ||
// let doc = docs[0] | ||
// console.log(chalk.blue('\npage #' + niceNumber(int) + `: -- ${chalk.green(chalk.underline(doc.title))} --`)) | ||
// let sections = doc.sections || [] | ||
// let str = ' ' + chalk.red(`${(doc.sections || []).length} sections`) | ||
// str += ' - ' + chalk.red(`${(doc.infoboxes || []).length} infoboxes`) | ||
// str += ' - ' + chalk.red(`${(doc.categories || []).length} categories`) | ||
// str += ' - ' + chalk.red(`${(doc.citations || []).length} citations`) | ||
// console.log(str, '\n') | ||
// sections.forEach((sec) => { | ||
// let heading = '='.repeat(sec.depth + 2) | ||
// console.log(chalk.grey(' ' + heading + ' ' + (sec.title || '(intro)') + ' ' + heading)) | ||
// //print first sentence | ||
// if (sec.sentences && sec.sentences[0]) { | ||
// let sen = sec.sentences[0].text || '' | ||
// console.log(chalk.yellow(` "${sen.slice(0, 170)}..."`)) | ||
// } | ||
// }) | ||
console.log('\n\n\n') | ||
|
||
const showPage = function(col, int) { | ||
col.find({}, { | ||
skip: int, | ||
limit: 1 | ||
}).toArray(function(err, docs) { | ||
let doc = docs[0] | ||
console.log(chalk.blue('\npage #' + niceNumber(int) + `: -- ${chalk.green(chalk.underline(doc.title))} --`)) | ||
let sections = doc.sections || [] | ||
let str = ' ' + chalk.red(`${(doc.sections || []).length} sections`) | ||
str += ' - ' + chalk.red(`${(doc.infoboxes || []).length} infoboxes`) | ||
str += ' - ' + chalk.red(`${(doc.categories || []).length} categories`) | ||
str += ' - ' + chalk.red(`${(doc.citations || []).length} citations`) | ||
console.log(str, '\n') | ||
sections.forEach((sec) => { | ||
let heading = '='.repeat(sec.depth + 2) | ||
console.log(chalk.grey(' ' + heading + ' ' + (sec.title || '(intro)') + ' ' + heading)) | ||
//print first sentence | ||
if (sec.sentences && sec.sentences[0]) { | ||
let sen = sec.sentences[0].text || '' | ||
console.log(chalk.yellow(` "${sen.slice(0, 170)}..."`)) | ||
} | ||
}) | ||
console.log('\n\n\n') | ||
}) | ||
} | ||
|
||
|
||
open(dbName, (db) => { | ||
let col = db.collection(config.collection) | ||
col.count().then((count) => { | ||
console.log(chalk.blue('\n\n ----------- ' + niceNumber(count) + ' pages total -----------\n')) | ||
let showPages = [1] | ||
showPages.push(Math.floor(count / 6)) | ||
showPages.push(Math.floor(count / 5)) | ||
showPages.push(Math.floor(count / 4)) | ||
showPages.push(Math.floor(count / 3)) | ||
showPages.push(Math.floor(count / 2)) | ||
showPages.push(Math.floor(count / 1.5)) | ||
let i = 0 | ||
let repeat = setInterval(function() { | ||
if (!showPages[i]) { | ||
clearInterval(repeat) | ||
db.close() | ||
return | ||
} | ||
showPage(col, showPages[i]) | ||
i += 1 | ||
}, 2000) | ||
|
||
//cool moves, | ||
const main = async function() { | ||
let obj = await openDb({ | ||
db: dbName | ||
}) | ||
}) | ||
let count = await obj.col.count() | ||
console.log(chalk.blue('\n\n ----------- ' + niceNumber(count) + ' pages total -----------\n')) | ||
await showPage(obj.col) | ||
// await showPage(obj.col, count / 5) | ||
await obj.client.close() | ||
} | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,37 +2,35 @@ | |
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)", | ||
"name": "dumpster-dive", | ||
"description": "get a wikipedia dump parsed into mongodb", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/spencermountain/wikipedia-to-mongodb.git" | ||
}, | ||
"bin": { | ||
"dumpster": "./bin/dumpster.js", | ||
"dumpster-report": "./bin/report.js" | ||
"dumpster": "./bin/dumpster.js" | ||
}, | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
"main": "./src/index.js", | ||
"scripts": { | ||
"test": "\"node_modules/.bin/tape\" \"./tests/*.test.js\" | \"node_modules/.bin/tap-spec\" --color", | ||
"test": "\"node_modules/.bin/tape\" \"./tests/*.test.js\" | \"node_modules/.bin/tap-dancer\" --color", | ||
"cleanup": "rm /tmp/worker.logs && touch /tmp/worker.logs", | ||
"watch": "node ./scratch.js" | ||
}, | ||
"dependencies": { | ||
"chalk": "2.4.1", | ||
"line-by-line": "0.1.6", | ||
"mongodb": "3.0.7", | ||
"ora": "2.1.0", | ||
"prettysize": "1.1.0", | ||
"sunday-driver": "1.0.1", | ||
"worker-nodes": "1.6.0", | ||
"wtf_wikipedia": "^3.1.1", | ||
"yargs": "11.0.0" | ||
}, | ||
"devDependencies": { | ||
"shelljs": "^0.8.1", | ||
"tap-spec": "4.1.1", | ||
"shelljs": "0.8.2", | ||
"tap-dancer": "0.0.3", | ||
"tape": "4.9.0" | ||
}, | ||
"license": "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.