Skip to content

Instantly share code, notes, and snippets.

@yosiopp
Created April 7, 2020 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yosiopp/6e3e30614b2599983740865893597495 to your computer and use it in GitHub Desktop.
Save yosiopp/6e3e30614b2599983740865893597495 to your computer and use it in GitHub Desktop.
asken.jpのPC画面で体重データを取得する
const range = (n) => [...Array(n).keys()];
const pad = (n) => ('0' + n).slice(-2);
$ = $J; // asken.jpのjQuery
var begin = 2015; // 開始年
var end = 2020; // 終了年
var timer = null;
var final = () => {
// 最終出力
console.log(JSON.stringify(result.flat()));
};
var result = [];
range(end - begin + 1)
.map(i => [(i + begin), range(12)])
.map(a => a[1].map(i => [a[0] + "", pad(i+1)]))
.flat()
.forEach((item, idx) => {
setTimeout(() => {
// 改ページ
$.post(`/my_diary/view_calendar/${item[0]}/${item[1]}/1/0/`).then(data => {
$('#hm_p_calendar').html(data);
var ym = $.trim($('#calendar_title').text()).replace(/[年月]/g,'');
var y = ym.substring(0,4), m = pad(ym.substring(4));
var ret = $('#calendar_datas > div[class*=calendar_body]')
.map((i, e) => {
var date = parseInt($.trim($(e).find('.val_date').text()));
var ymd = `${y}-${m}-${pad(date)}`;
var weight = parseFloat($.trim($(e).find('.val_weight').text()));
if (item[0] != y || item[1] != m || !weight) {
return null;
}
return { 'date': ymd, 'weight': weight };
}).toArray();
if (0 < ret.length) {
result.push(ret);
}
console.log(item[0] + '-' + item[1], ret.length);
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(final, 1000);
});
}, idx * 300);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment