Skip to content

Instantly share code, notes, and snippets.

@gc373
Created August 16, 2017 03:18
Show Gist options
  • Select an option

  • Save gc373/c9c549bece7f04d17f8d33bf6964dfe7 to your computer and use it in GitHub Desktop.

Select an option

Save gc373/c9c549bece7f04d17f8d33bf6964dfe7 to your computer and use it in GitHub Desktop.
・・・・・・・・・というググラビリティが低いグループが出した「CD」というググラビリティの低いCDの感想をTwitterから取得するスクリプト
const Twitter = require('twitter'),
fs = require('fs'),
jconv = require('jconv'),
client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
}),
moment = require('moment'),
jst = +9,
// この辺は自由に変えてもらって ex) moment().add(-1, 'd') とか moment().startOf('month')とか
today = moment().utcOffset(jst).format("YYYY-MM-DD");
let max_id = "999999999999999999",
max_id_old,
getTime = 0;
(async () => {
await getImage();
})()
async function getImage() {
const query = 'CD lang:ja ' + "since:" + today + "_00:00:00_JST" + " until:" + today + "_23:59:59_JST" + ' max_id:' + max_id,
params = {
"q": query,
"count": 100,
"result_type": "recent",
"modules": "status",
};
client.get('search/universal', params, (error, tweets, response) => {
if (!error) { // ↑ そういえば公式のコンシューマーキー使わないと叩けないよ
tweets.modules.forEach((element) => {
max_id = element.status.data.id;
if (element.status.data.text.match("・・・・・・・・・")) {
const url = "https://twitter.com/" + element.status.data.user.screen_name + "/status/" + element.status.data.id_str;
const text = element.status.data.text.replace(/\r|\n/g, " ");
const csvTxt = [url, text].join(",");
console.log(csvTxt);
}
});
console.log("next_max_id", max_id, " / max_id_old", max_id_old);
if (max_id != max_id_old) {
max_id_old = max_id;
return new Promise(resolve => {
setTimeout(resolve(getImage()), (1000 * 60 * 15) / 150);
}); // 検索APIのリミットは 180 / 15min
} else {
return;
}
} else {
console.log(error);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment