livejournal
Advanced tools
Comparing version
@@ -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); | ||
}); | ||
``` |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1
-66.67%5
25%22
175%2749
-39.29%88
-40.94%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed