가계부를 옮겨보려고 했다. 하지만 복식부기에 익숙하지 않아 (= 댕청해서) 1,000건 쯤 거래내역을 잘못 입력했다. 장고 끝에 이전에 쓰던 가계부 Migration을 포기하기로 결정했다. 그래서 이미 입력해버린 1,000건의 거래내역을 지우기위해 공개된 후잉 API를 이용한 삭제 스크립트를 간단하게 만들어봤다. 본 스크립트를 실행하면 본인 후잉계정의 모든 거래내역을 삭제하게 된다. 이 스크립트로 손실된 데이터에 대한 책임은 본인이…
후잉 웹사이트 > 게시판 > 개발자 > (좌 하단) 나의 앱들 > 앱 등록하기 > 제공하는 기능 전부 체크 > 동의 및 등록 > Token을 가져온다.
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
const axios = require('axios'); | |
const delay = require('delay'); | |
async function getSections() { | |
const res = await axios({ | |
method: 'get', | |
url: 'https://whooing.com/api/sections.json', | |
headers: { | |
'X-API-KEY': `app_id=1234,token=1234,signiture=1234,nounce=asdf,timestamp=${Date.now()}`, | |
}, | |
}); | |
return Object.keys(res.data.results); | |
} | |
async function getEntries(section) { | |
const res = await axios({ | |
method: 'get', | |
url: `https://whooing.com/api/entries.json?section_id=${section}&start_date=20120101&end_date=20180814`, | |
headers: { | |
'X-API-KEY': `app_id=1234,token=1234,signiture=1234,nounce=asdf,timestamp=${Date.now()}`, | |
}, | |
}); | |
return res.data.results.rows; | |
} | |
async function deleteEntries(entryIdList) { | |
await axios({ | |
method: 'delete', | |
url: `https://whooing.com/api/entries/${entryIdList.join(',')}`, | |
headers: { | |
'X-API-KEY': `app_id=1234,token=1234,signiture=1234,nounce=asdf,timestamp=${Date.now()}`, | |
}, | |
}); | |
} | |
async function main() { | |
const sectionList = await getSections(); | |
const section = sectionList[0]; | |
console.log('section', section); | |
let i = 0; | |
while (true) { | |
const entries = await getEntries(section); | |
console.log('entries', i++, entries); | |
if (entries.length === 0) { | |
break; | |
} | |
await deleteEntries(entries.map(e => e.entry_id)); | |
await delay(100); | |
} | |
} | |
main(); |
yarn init
,yarn add axios delay
명령어를 이용해 라이브러리를 설치한다.X-API-KEY
에 앞서 발급받은 키를 잘 넣어준다. 난수(nounce)의 경우 본인은 asdf를 썼는데 별 문제없이 잘 돌아갔다.getEntries()
에 있는 start_date, end_date를 잘 넣어준다.- 이후에는 100ms의 간격으로 polite하게 api를 넣어준다.
node index.js
로 실행한다.혹시 다시 복구하고 싶다면 stdout으로 뱉어준 json을 잘 줏어 담아보자…
지우는 것도 일이네
마장