Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunji committed Nov 12, 2023
2 parents 1f50742 + 2c9cf92 commit 066a2c6
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ jobs:
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/src" # App source code path
api_location: "" # Api source code path - optional
api_location: "/api" # Api source code path - optional
output_location: "/src" # Built app content directory - optional
###### End of Repository/Build Configurations ######
- name: Install Python dependencies
run: python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install node-fetch
run: npm install node-fetch
npm run build --if-present


close_pull_request_job:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/main_quatergirit-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js project to Azure Function App - quatergirit-api

on:
push:
branches:
- main
workflow_dispatch:

env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.x' # set this to the node version to use (supports 8.x, 10.x, 12.x)

jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: 'Resolve Project Dependencies Using Npm'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: 'quatergirit-api'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_9970B2D7920C44409B733A2F378F0148 }}
49 changes: 40 additions & 9 deletions api/findroad/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fetch = require("node-fetch");


module.exports = async function (context, req) {
try {
const { startX, startY, endX, endY } = req.body; // 매개변수로부터 위도, 경도 정보를 받음
Expand Down Expand Up @@ -30,19 +29,51 @@ module.exports = async function (context, req) {

if (response.ok) {
const json_response = await response.json();
console.log(JSON.stringify(json_response, null, 2));
// console.log(JSON.stringify(json_response, null, 2));

const totalFare = json_response.metaData.plan.itineraries[0].fare.regular.totalFare;
let itineraryText = '';
var text_counter = 0;

//코드 추가

for (const itinerary of json_response['metaData']["plan"]["itineraries"]) {
const legs = itinerary.legs || [];

for (const leg of legs) {
if ("Lane" in leg) {
const lanes = leg["Lane"];

// console.log("Lanes:", lanes);

for (let i = 0; i < lanes.length; i++) {
const route = lanes[i].route || `No route information for Lane ${i}`;
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}`);
if (text_counter == 0) {
itineraryText += `{"dep": "${departure_station}",`;
itineraryText += `"arr": "${arrival_station}"}`;
// itineraryText += `"Route": '${route}',}`;

text_counter += 1;
}
}
}
}
}
}
console.log(itineraryText)
// context.res.body = JSON.parse(itineraryText);

context.res = {
status: 200,
body: { text: `Total Fare: ${totalFare} 원` },
body: JSON.parse(itineraryText), // 직접 context.res.body에 itineraryText를 넣어줌
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json'
}
};
};
} else {
console.error(`API request failed with status code ${response.status}`);
console.error(await response.text());
Expand All @@ -66,4 +97,4 @@ module.exports = async function (context, req) {
}
};
}
};
};
20 changes: 11 additions & 9 deletions api/ktx_schedule/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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 @@ -22,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'
}
};
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"axios": "^1.6.1",
"node-fetch": "^2.7.0",
"swa": "^0.0.1"
}
},
"type": "module"
}
Loading

0 comments on commit 066a2c6

Please sign in to comment.