Skip to content

Instantly share code, notes, and snippets.

@xnuk
Created April 25, 2019 10:17
Show Gist options
  • Save xnuk/0f5c9d017d61bbcd059c00e29afa6e10 to your computer and use it in GitHub Desktop.
Save xnuk/0f5c9d017d61bbcd059c00e29afa6e10 to your computer and use it in GitHub Desktop.
const axios = require('axios')
const {stringify} = require('querystring')
const trace = v => {
console.log(v)
return v
}
const searchMethod = (from, to) => from.includes(to)
const kobis = axios.create({
baseURL: 'http://www.kobis.or.kr/kobis/business/mast/thea/',
})
const post = (url, data) => kobis.post(url, stringify(data))
const saner = xs => xs.map(({cd, cdNm}) => ({code: cd, name: cdNm}))
const getAreas = async () => console.log(
JSON.stringify(
await Promise.all(
data.map(async ([code, name]) => {
const foo = await post('findBasareaCdList.do', {sWideareaCd: num})
return { num, name, data: saner(foo.data.basareaCdList) }
}))))
const findTheater = async (city, area) => {
const {data: {theaCdList}} = await post('findTheaCdList.do', {sWideareaCd: city, sBasareaCd: area})
return saner(theaCdList)
}
const getSchedule = async (theater, yyyymmdd) => {
const {data: {schedule}} = await post('findSchedule.do', {theaCd: theater, showDt: yyyymmdd})
return schedule.map(a => ({
screen: a.scrnNm,
movie: {name: a.movieNm, code: a.movieCd},
timetable: a.showTm.split(',')
}))
}
const list = require('./area.json').flatMap(
({code, name, area}) => area.map(v => `${code} ${v.code} ${name} ${v.name}`)
)
console.log(list.join('\n'))
const areaSchedule = async (city, area, yyyymmdd) => {
const theaters = await findTheater(city, area)
console.log(theaters)
const schedules = theaters.map(async ({name, code}) => {
const schedule = await getSchedule(code, yyyymmdd)
return {name, schedule}
})
const sch = await Promise.all(schedules)
return sch
}
const search = async (area, name, yyyymmdd) => {
const res = list.find(v => searchMethod(v, area))
if (res == null) return null
const [citycode, areacode, cityname, areaname] = res.split(' ')
const schedules = await areaSchedule(citycode, areacode, yyyymmdd)
return schedules.map(
x => ({
name: x.name,
schedule: x.schedule.filter(
({movie}) => searchMethod(movie.name, name)
)})).filter(({schedule}) => schedule.length > 0)
}
;(async () => console.log( JSON.stringify(
await search('강남구', '미성년', '20190426')
)))()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment