Skip to content

Commit

Permalink
길찾기 연결 진행 중
Browse files Browse the repository at this point in the history
  • Loading branch information
kkyh12180 committed Nov 12, 2023
1 parent 44ed424 commit d8c9367
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
21 changes: 12 additions & 9 deletions api/findroad/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = async function (context, req) {
console.log(JSON.stringify(json_response, null, 2));

let itineraryText = '';
var text_counter = 0;

for (const itinerary of json_response['metaData']["plan"]["itineraries"]) {
const legs = itinerary.legs || [];
Expand All @@ -44,29 +45,31 @@ module.exports = async function (context, req) {

for (let i = 0; i < lanes.length; i++) {
const route = lanes[i].route || `No route information for Lane ${i}`;
if (route.startsWith('SRT') || route.startsWith('KTX') || route.startsWith('ITX') || route.startsWith('무궁화')) {
if (route.startsWith('KTX')) {
const departure_station = leg["start"]["name"];
const arrival_station = leg["end"]["name"];

console.log(`야삐 Departure Station: ${departure_station}`);
console.log(`야삐 Arrival Station: ${arrival_station}`);
console.log(`야삐 Route: ${route}`);

itineraryText += `Departure Station: ${departure_station}\n`;
itineraryText += `Arrival Station: ${arrival_station}\n`;
itineraryText += `Route: ${route}\n\n`;

if (text_counter == 0) {
itineraryText += `{"dep": "${departure_station}",`;
itineraryText += `"arr": "${arrival_station}",`;
itineraryText += `"Route": "${route}",}`;

text_counter += 1;
}
}
}
}
}
}

context.res.body = { itineraryText };
console.log(itineraryText)
context.res.body = JSON.parse(itineraryText);

context.res = {
status: 200,
body: { itineraryText }, // 직접 context.res.body에 itineraryText를 넣어줌
body: JSON.parse(itineraryText), // 직접 context.res.body에 itineraryText를 넣어줌
headers: {
'Content-Type': 'application/json'
}
Expand Down
18 changes: 9 additions & 9 deletions api/ktx_schedule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ const axios = require('axios');

module.exports = async function (context, req) {

const dep = "동대구";
const arr = "서울";
const date = "20231112";
const time = "120000";
const {dep, arr, date, time} = req.body;

const call_command = `python3 ./ktx_schedule/ktx_api.py ${dep} ${arr} ${date} ${time}`;
const call_command = `python ./ktx_schedule/ktx_api.py ${dep} ${arr} ${date} ${time}`;
// console.log(call_command);

const execSync = require('child_process').execSync;
Expand All @@ -24,8 +21,11 @@ module.exports = async function (context, req) {
console.error('JSON 파싱 오류:', error.message);
}

context.res.json({
// status: 200, /* Defaults to 200 */
res: jsonData
});
context.res = {
status: 200,
body: jsonData,
headers: {
'Content-Type': 'application/json'
}
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"node-fetch": "^2.7.0",
"swa": "^0.0.1"
},
"type":"module"
"type": "module"
}
5 changes: 4 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ <h1>Vanilla JavaScript App</h1>


<script>
/*
(async function () {
const { res } = await (await fetch(`/api/ktx_schedule`)).json();
Expand All @@ -222,6 +223,7 @@ <h1>Vanilla JavaScript App</h1>
document.querySelector('#ktx_result').textContent = res_text;
}());
*/
</script>


Expand Down Expand Up @@ -256,8 +258,9 @@ <h1>Vanilla JavaScript App</h1>
}),
})
).json();

console.log(text.body);
document.querySelector('#findroad').textContent = text;

} catch (error) {
console.error('주소 변환 및 API 호출에 실패하였습니다:', error);
}
Expand Down

0 comments on commit d8c9367

Please sign in to comment.