livejournal
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,32 +0,10 @@ | ||
var livejournal = require('./'); | ||
var LiveJournal = require('./'); | ||
// get journal entries | ||
// check http://www.livejournal.com/bots/ | ||
livejournal.getJournal('brad', function(err, journal) { | ||
var links = journal.entry.map(function(entry) { | ||
return entry.link[0]['@'].href; | ||
}); | ||
// get facebook share count for latest posts | ||
livejournal.getFBStatsBatch(links, function(err, stats) { | ||
console.log(stats); | ||
}); | ||
LiveJournal.RPC.getevents({ | ||
journal: 'brad', | ||
auth_method: 'noauth', | ||
selecttype: 'lastn', | ||
howmany: 20 | ||
}, function(err, value) { | ||
console.log(value.events); | ||
}); | ||
// get post details by username and id | ||
livejournal.getPost({ | ||
user: 'brad', | ||
post_id: 29215, | ||
body: true | ||
}, function(err, post) { | ||
console.log(post); | ||
}); | ||
// get comments (shitty html, sorry) | ||
livejournal.getComments({ | ||
user: 'brad', | ||
post_id: 29215 | ||
}, function(err, comments) { | ||
console.log(comments); | ||
}); |
109
index.js
@@ -1,87 +0,3 @@ | ||
var request = require('request'), | ||
cheerio = require('cheerio'), | ||
var RPC = require('./rpc'); | ||
xml2js = require('xml2js'), | ||
parser = new xml2js.Parser(); | ||
var j = request.jar(), | ||
cookie = request.cookie('adult_explicit=1'); | ||
j.add(cookie); | ||
function getComments(post, callback) { | ||
request({ | ||
url: 'http://{username}.livejournal.com/{username}/__rpc_get_thread'.replace(/\{username\}/g, post.user), | ||
qs: { | ||
journal: post.user, | ||
itemid: post.post_id, | ||
page: 1 | ||
}, | ||
json: true | ||
}, function(err, res, body) { | ||
callback(err, body); | ||
}); | ||
} | ||
// @TODO: tags | ||
function getPost(post, callback) { | ||
request({ | ||
url: 'http://m.livejournal.com/read/user/' + post.user + '/' + post.post_id, | ||
jar: j | ||
}, function(err, res, body) { | ||
if (!err && res.statusCode == 200) { | ||
var $ = cheerio.load(body), | ||
title = $('.item-header').text().trim(), | ||
time = new Date( $('.item-meta').text().trim() ), | ||
commentNode = $('.to-all-alone'), | ||
comments, | ||
errorNode = $('.error'); | ||
if (errorNode.length > 0) { | ||
callback(new Error(errorNode.text()), null); | ||
return; | ||
} | ||
if (commentNode.length > 0) { | ||
comments = $('.to-all-alone').text().trim().match(/\d+/)[0]; | ||
} else { | ||
comments = 0; | ||
} | ||
var result = { | ||
title: title, | ||
time: time, | ||
comments: comments | ||
}; | ||
if (post.body) { | ||
result.body = $('.item-text').html(); | ||
} | ||
if (!title) { | ||
console.log('err:', err, 'body:', body); | ||
} | ||
callback(err, result); | ||
} else { | ||
callback(err, null); | ||
} | ||
}); | ||
} | ||
function getFBStats(user, postId, callback) { | ||
request({ | ||
url: 'http://graph.facebook.com/?id=http://' + user + '.livejournal.com/' + postId + '.html', | ||
json: true | ||
}, function(err, res, body) { | ||
if (!err && res.statusCode == 200) { | ||
callback(err, {shares: body.shares || 0 }); | ||
} else { | ||
console.log(err, body); | ||
} | ||
}); | ||
} | ||
function _groupBy(arr, amount) { | ||
@@ -98,3 +14,3 @@ var result = [], offset = 0; | ||
function getFBStatsBatch(urls, callback) { | ||
function getFBStats(urls, callback) { | ||
var groups = _groupBy(urls, 10), | ||
@@ -127,25 +43,6 @@ result = {}, | ||
function getJournal(user, callback) { | ||
request({ | ||
url: 'http://' + user + '.livejournal.com/data/atom' | ||
}, function(err, res, body) { | ||
if (err) { | ||
callback(err, null); | ||
return; | ||
} | ||
parser.parseString(body, function (err, result) { | ||
callback(err, result); | ||
}); | ||
}); | ||
} | ||
module.exports = { | ||
getPost: getPost, | ||
getFBStats: getFBStats, | ||
getFBStatsBatch: getFBStatsBatch, | ||
getComments: getComments, | ||
getJournal: getJournal | ||
RPC: RPC | ||
}; |
{ | ||
"name": "livejournal", | ||
"version": "0.0.1", | ||
"description": "Tools to scrape LiveJournal for data", | ||
"version": "0.0.2", | ||
"description": "LiveJournal XMLRPC", | ||
"keywords": ["livejournal", "blog"], | ||
@@ -12,7 +12,5 @@ "author": "Artem Tyurin <artem.tyurin@gmail.com>", | ||
"dependencies": { | ||
"cheerio": ">=0.11.0", | ||
"request": ">=2.20.0", | ||
"xml2js": ">=0.2.7" | ||
"xmlrpc": ">=1.1.0" | ||
}, | ||
"main": "index" | ||
} |
@@ -1,7 +0,21 @@ | ||
## Tools to scrape LiveJournal for data | ||
## LiveJournal XMLRPC for Node | ||
- This is not an API, some methods work by parsing html | ||
`npm install livejournal` | ||
- See `example.js` for examples | ||
### Docs | ||
- All methods use standart node callback format | ||
* http://wh.lj.ru/s2/developers/f/LiveJournal_XML-RPC_Specification_(EN).pdf | ||
* http://www.livejournal.com/doc/server/ljp.csp.xml-rpc.protocol.html | ||
### Example | ||
```javascript | ||
LiveJournal.RPC.getevents({ | ||
journal: 'brad', | ||
auth_method: 'noauth', | ||
selecttype: 'lastn', | ||
howmany: 20 | ||
}, function(err, value) { | ||
console.log(value.events); | ||
}); | ||
``` |
1
5
22
2749
88
+ Addedxmlrpc@>=1.1.0
+ Addedsax@1.2.4(transitive)
+ Addedxmlbuilder@8.2.2(transitive)
+ Addedxmlrpc@1.3.2(transitive)
- Removedcheerio@>=0.11.0
- Removedrequest@>=2.20.0
- Removedxml2js@>=0.2.7
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.12.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedboolbase@1.0.0(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcheerio@0.22.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removedcss-select@1.2.0(transitive)
- Removedcss-what@2.1.3(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddom-serializer@0.1.1(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.5.1(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedentities@1.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash.assignin@4.2.0(transitive)
- Removedlodash.bind@4.2.1(transitive)
- Removedlodash.defaults@4.2.0(transitive)
- Removedlodash.filter@4.6.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.map@4.6.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedlodash.pick@4.4.0(transitive)
- Removedlodash.reduce@4.6.0(transitive)
- Removedlodash.reject@4.6.0(transitive)
- Removedlodash.some@4.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removednth-check@1.0.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsax@1.3.0(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedxml2js@0.6.2(transitive)
- Removedxmlbuilder@11.0.1(transitive)