김연우

merge listing

1 +{
2 + "env": {
3 + "browser": true,
4 + "es2021": true
5 + },
6 + "extends": "eslint:recommended",
7 + "parserOptions": {
8 + "ecmaVersion": "latest",
9 + "sourceType": "module"
10 + },
11 + "rules": {
12 + }
13 +}
...@@ -5,6 +5,23 @@ ...@@ -5,6 +5,23 @@
5 "version": "0.2.0", 5 "version": "0.2.0",
6 "configurations": [ 6 "configurations": [
7 { 7 {
8 + "type": "node",
9 + "request": "launch",
10 + "name": "Mocha All",
11 + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
12 + "args": [
13 + "--timeout",
14 + "999999",
15 + "--colors",
16 + "${workspaceFolder}/test"
17 + ],
18 + "console": "integratedTerminal",
19 + "internalConsoleOptions": "neverOpen",
20 + "skipFiles": [
21 + "<node_internals>/**/*.js"
22 + ]
23 + },
24 + {
8 "type": "pwa-node", 25 "type": "pwa-node",
9 "request": "launch", 26 "request": "launch",
10 "name": "Launch Program", 27 "name": "Launch Program",
......
...@@ -40,23 +40,35 @@ ex) ...@@ -40,23 +40,35 @@ ex)
40 */ 40 */
41 41
42 export async function get_schedule(id, pw, target_date) { 42 export async function get_schedule(id, pw, target_date) {
43 - login(id, pw).then(async driver => { 43 + return await using_selenium( async (driver) => {
44 - load(driver, target_date) 44 + return await login(driver, id, pw)
45 - .then(it => { 45 + .then(async () => {
46 - console.log(it) 46 + return await load(driver, target_date)
47 - logout(driver) 47 + .then((data) => {
48 + //logout(driver)
49 + console.log(data)
50 + return data
51 + })
48 }) 52 })
49 }) 53 })
50 } 54 }
51 55
52 -export async function login(id, pw) { 56 +export async function using_selenium(next) {
53 const option = new firefox.Options() 57 const option = new firefox.Options()
54 - option.setBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe') 58 + option.addArguments("-headless");
59 +
55 const driver = new selenium.Builder() 60 const driver = new selenium.Builder()
56 .forBrowser('firefox') 61 .forBrowser('firefox')
57 .setFirefoxOptions(option) 62 .setFirefoxOptions(option)
58 .build() 63 .build()
59 64
65 + next(driver).finally(() => {
66 + driver.quit()
67 + })
68 +}
69 +
70 +export async function login(driver, id, pw) {
71 +
60 await driver.get("https://khcanvas.khu.ac.kr/") 72 await driver.get("https://khcanvas.khu.ac.kr/")
61 73
62 const idInput = await driver.findElement(selenium.By.xpath('//*[@id="login_user_id"]')); 74 const idInput = await driver.findElement(selenium.By.xpath('//*[@id="login_user_id"]'));
...@@ -87,7 +99,7 @@ export async function load(driver, until) { ...@@ -87,7 +99,7 @@ export async function load(driver, until) {
87 export async function logout(driver) { 99 export async function logout(driver) {
88 await driver.get("https://khcanvas.khu.ac.kr/") 100 await driver.get("https://khcanvas.khu.ac.kr/")
89 101
90 - const logoutPanel = await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click(); 102 + await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click();
91 await sleep(1000) 103 await sleep(1000)
92 const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button')); 104 const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button'));
93 logout.click() 105 logout.click()
......
1 import fs from 'fs/promises' 1 import fs from 'fs/promises'
2 import { login, load, logout } from './khcanvas.js'; 2 import { login, load, logout } from './khcanvas.js';
3 3
4 -fs.readFile("asdffdsa.txt").then(it => {
5 - const auth = it.toString().split('|')
6 - login(auth[0], auth[1]).then(async driver => {
7 - load(driver, new Date())
8 - .then(it => {
9 - console.log(it)
10 - logout(driver)
11 - })
12 - }).catch(err => { console.log(err) })
13 -})
...\ No newline at end of file ...\ No newline at end of file
......
This diff is collapsed. Click to expand it.
...@@ -14,13 +14,17 @@ ...@@ -14,13 +14,17 @@
14 "license": "", 14 "license": "",
15 "dependencies": { 15 "dependencies": {
16 "@types/selenium-webdriver": "^4.1.0", 16 "@types/selenium-webdriver": "^4.1.0",
17 +<<<<<<< HEAD
17 "csv-parser": "^3.0.0", 18 "csv-parser": "^3.0.0",
18 "eslint": "^8.15.0", 19 "eslint": "^8.15.0",
20 +=======
21 +>>>>>>> 6c6e356fa8269fbbdee92f54a6f2f16ffe2ba729
19 "mocha": "^10.0.0", 22 "mocha": "^10.0.0",
20 "selenium-webdriver": "^4.1.2" 23 "selenium-webdriver": "^4.1.2"
21 }, 24 },
22 "type": "module", 25 "type": "module",
23 "devDependencies": { 26 "devDependencies": {
24 - "@types/node": "^17.0.35" 27 + "@types/node": "^17.0.35",
28 + "eslint": "^8.16.0"
25 } 29 }
26 } 30 }
......
1 +//### csv 파일에서 정보를 읽어오고, 2차원 배열화
2 +
3 +const parse = require("csv-parse/lib/sync");
4 +const fs = require("fs");
5 +
6 +const csv = fs.readFileSync("todolistdata.csv");
7 +console.log(csv.toString());
8 +//parse 메서드 -> 2차원배열화
9 +const records = parse(csv.toString());
10 +const addr = []
11 +
12 +for (var i = 0; i < records.length; i++){
13 + for(var j = 0; j < records[i].length; j++){
14 + addr.push(records[i][4]);
15 + }
16 + console.log(addr);
17 +
18 +}
19 +
20 +
21 +
22 +//------------------------------------------------------------------
23 +//###주소로 장소 검색하기###
24 +
25 +
26 +
27 +var mapContainer = document.getElementById('map'), // 지도를 표시할 div
28 + mapOption = {
29 + center: new kakao.maps.LatLng(33.450701, 126.570667), // 지도의 중심좌표
30 + level: 3 // 지도의 확대 레벨
31 + };
32 +
33 +// 지도를 생성합니다
34 +var map = new kakao.maps.Map(mapContainer, mapOption);
35 +
36 +// 주소-좌표 변환 객체를 생성합니다
37 +var geocoder = new kakao.maps.services.Geocoder();
38 +
39 +// 찾을 주소
40 +var searchAddress;
41 +
42 +// 주소로 좌표를 검색합니다
43 +geocoder.addressSearch(searchAddress, function(result, status) {
44 +
45 + // 정상적으로 검색이 완료됐으면
46 + if (status === kakao.maps.services.Status.OK) {
47 +
48 + var coords = new kakao.maps.LatLng(result[0].y, result[0].x);
49 +
50 + // 결과값으로 받은 위치를 마커로 표시합니다
51 + var marker = new kakao.maps.Marker({
52 + map: map,
53 + position: coords
54 + });
55 +
56 + // 인포윈도우로 장소에 대한 설명을 표시합니다
57 + var infowindow = new kakao.maps.InfoWindow({
58 + content: '<div style="width:150px;text-align:center;padding:6px 0;">목적지</div>'
59 + });
60 + infowindow.open(map, marker);
61 +
62 + // 지도의 중심을 결과값으로 받은 위치로 이동시킵니다
63 + map.setCenter(coords);
64 + }
65 +});
...\ No newline at end of file ...\ No newline at end of file
1 +//@ts-check
2 +//https://github.com/gatoona/AWS-Selenium
3 +import * as canvas from '../khcanvas.js'
4 +import * as rd from 'readline'
5 +import * as mocha from 'mocha'
6 +import process from 'node:process';
7 +import util from 'util'
8 +import { rejects } from 'assert';
9 +
10 +
11 +mocha.describe('khcanvas', () => {
12 + mocha.it('opening selenium', async () => {
13 + await canvas.using_selenium(async (driver) => {
14 + await driver.get("http://khuhub.khu.ac.kr");
15 + await driver.getTitle().then( (title) => {
16 + console.log(title);
17 + });
18 + });
19 + })
20 +});
21 +
22 +
23 +mocha.describe('khcanvas', () => {
24 + mocha.it('get schedule', async () => {
25 + const rl = rd.createInterface({
26 + input: process.stdin,
27 + output: process.stdout
28 + })
29 +
30 + const question = util.promisify(rl.question).bind(rl);
31 +
32 + const a = await question('a');
33 + const b = await question('b');
34 +
35 + return await canvas.get_schedule(a, b, new Date())
36 + .then(it => console.log(it))
37 + .catch(it => {
38 + console.log(it)
39 + rejects(it)
40 + })
41 + })
42 +});
...\ No newline at end of file ...\ No newline at end of file
......
1 +분류,특징1,특징2,상호,주소
2 +음식점,브런치,데이트,쏘니스,경기 수원시 영통구 매영로425번길 18 1층
3 +음식점,일식,라멘,키와마루아지 경희대점,경기 수원시 영통구 영일로 8 1층 108호
4 +음식점,한식,편안한,정통집 영통점,경기 수원시 영통구 청명남로 32 월드프라자 101호
5 +주점,"소주,맥주",감성,금별맥주 수원영통점,경기 수원시 영통구 청명남로34번길 8 1층
6 +주점,막걸리,편안한,전과 부침개 맛있는 집,경기 수원시 영통구 청명남로4번길 5-2
7 +영화관,재미있는,편안한,메가박스 영통점,경기 수원시 영통구 봉영로 1579 그랜드백화점
8 +볼링장,재미있는,유쾌한,킹덤 볼링장,경기 수원시 영통구 반달로7번길 40 평익칼라스위트
...\ No newline at end of file ...\ No newline at end of file