Showing
3 changed files
with
27 additions
and
14 deletions
... | @@ -21,16 +21,8 @@ app.post('/hook', function (req, res) { | ... | @@ -21,16 +21,8 @@ app.post('/hook', function (req, res) { |
21 | 21 | ||
22 | // request log | 22 | // request log |
23 | console.log('======================', new Date(), '======================'); | 23 | console.log('======================', new Date(), '======================'); |
24 | - console.log('[request]', req.body); | ||
25 | - console.log('[request source] ', eventObj.source); | ||
26 | - console.log('[request message]', eventObj.message); | ||
27 | - | ||
28 | - var incredients_list = message.text.split(" "); | ||
29 | - | ||
30 | - function findingredients(item) { return item === "김치"; } | ||
31 | 24 | ||
32 | // mwsql | 25 | // mwsql |
33 | - // mysql -u chatbot -p -h chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com | ||
34 | var mysql = require('mysql'); | 26 | var mysql = require('mysql'); |
35 | var db = mysql.createConnection({ | 27 | var db = mysql.createConnection({ |
36 | host: 'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com', | 28 | host: 'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com', |
... | @@ -60,11 +52,11 @@ app.post('/hook', function (req, res) { | ... | @@ -60,11 +52,11 @@ app.post('/hook', function (req, res) { |
60 | "messages": [ | 52 | "messages": [ |
61 | { | 53 | { |
62 | "type": "text", | 54 | "type": "text", |
63 | - "text": `${results[i].menu}` | 55 | + "text": `메뉴는 "${results[i].menu}" 입니다.` |
64 | }, | 56 | }, |
65 | { | 57 | { |
66 | "type": "text", | 58 | "type": "text", |
67 | - "text": `${results[i].recipe}` | 59 | + "text": `레시피\n${results[i].recipe}` |
68 | } | 60 | } |
69 | ] | 61 | ] |
70 | } | 62 | } |
... | @@ -92,4 +84,3 @@ try { | ... | @@ -92,4 +84,3 @@ try { |
92 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | 84 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); |
93 | console.log(error); | 85 | console.log(error); |
94 | } | 86 | } |
... | \ No newline at end of file | ... | \ No newline at end of file |
95 | - | ... | ... |
1 | +// var xhr = new XMLHttpRequest(); | ||
2 | +// var url = 'http://apis.data.go.kr/1390802/AgriFood/FdCkry/getKoreanFoodFdCkryList'; /*URL*/ | ||
3 | +// var queryParams = '?' + encodeURIComponent('serviceKey') + '='+'R7bFhjvvAMmxJxzcrL8NWkYHVa227zfpwvpwgXxcixNdMY0EbdbsbCboj3zXEsXniKNHyqu2dEllJCRk1LsdxA%3D%3D'; /*Service Key*/ | ||
4 | +// queryParams += '&' + encodeURIComponent('service_Type') + '=' + encodeURIComponent('xml'); /**/ | ||
5 | +// queryParams += '&' + encodeURIComponent('Page_No') + '=' + encodeURIComponent('1'); /**/ | ||
6 | +// queryParams += '&' + encodeURIComponent('Page_Size') + '=' + encodeURIComponent('20'); /**/ | ||
7 | +// queryParams += '&' + encodeURIComponent('food_Name') + '=' + encodeURIComponent('밥'); /**/ | ||
8 | +// queryParams += '&' + encodeURIComponent('ckry_Name') + '=' + encodeURIComponent('조리'); /**/ | ||
9 | +// xhr.open('GET', url + queryParams); | ||
10 | +// xhr.onreadystatechange = function () { | ||
11 | +// if (this.readyState == 4) { | ||
12 | +// alert('Status: '+this.status+'nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'nBody: '+this.responseText); | ||
13 | +// } | ||
14 | +// }; | ||
15 | + | ||
16 | +// xhr.send(''); | ||
17 | + | ||
18 | +var XMLHttpRequest = require('xhr2'); | ||
1 | var xhr = new XMLHttpRequest(); | 19 | var xhr = new XMLHttpRequest(); |
2 | var url = 'http://apis.data.go.kr/1390802/AgriFood/FdCkry/getKoreanFoodFdCkryList'; /*URL*/ | 20 | var url = 'http://apis.data.go.kr/1390802/AgriFood/FdCkry/getKoreanFoodFdCkryList'; /*URL*/ |
3 | var queryParams = '?' + encodeURIComponent('serviceKey') + '='+'R7bFhjvvAMmxJxzcrL8NWkYHVa227zfpwvpwgXxcixNdMY0EbdbsbCboj3zXEsXniKNHyqu2dEllJCRk1LsdxA%3D%3D'; /*Service Key*/ | 21 | var queryParams = '?' + encodeURIComponent('serviceKey') + '='+'R7bFhjvvAMmxJxzcrL8NWkYHVa227zfpwvpwgXxcixNdMY0EbdbsbCboj3zXEsXniKNHyqu2dEllJCRk1LsdxA%3D%3D'; /*Service Key*/ |
... | @@ -9,7 +27,11 @@ queryParams += '&' + encodeURIComponent('ckry_Name') + '=' + encodeURIComponent( | ... | @@ -9,7 +27,11 @@ queryParams += '&' + encodeURIComponent('ckry_Name') + '=' + encodeURIComponent( |
9 | xhr.open('GET', url + queryParams); | 27 | xhr.open('GET', url + queryParams); |
10 | xhr.onreadystatechange = function () { | 28 | xhr.onreadystatechange = function () { |
11 | if (this.readyState == 4) { | 29 | if (this.readyState == 4) { |
12 | - alert('Status: '+this.status+'nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'nBody: '+this.responseText); | 30 | + //console.log('Status: '+this.status+'nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'nBody: '+this.responseText); |
31 | + //console.log(this.responseText); | ||
32 | + console.log(this.responseText); | ||
33 | + console.log("hehe\n"); | ||
34 | + console.log(queryParams); | ||
13 | } | 35 | } |
14 | }; | 36 | }; |
15 | 37 | ... | ... |
... | @@ -3,14 +3,14 @@ import requests | ... | @@ -3,14 +3,14 @@ import requests |
3 | from bs4 import BeautifulSoup | 3 | from bs4 import BeautifulSoup |
4 | import pymysql | 4 | import pymysql |
5 | 5 | ||
6 | -#pip3 install requests, pip3 install pymyaql, pip3 install beautifulsoup4를 하고 진행, pip3대신 pip 사용가능 | 6 | +#pip3 install requests, pip3 install pymysql, pip3 install beautifulsoup4를 하고 진행, pip3대신 pip 사용가능 |
7 | #사이트가 크롤링을 공격으로 인식하는 것을 방지하기 위해 중간중간에 sleep함수를 사용 | 7 | #사이트가 크롤링을 공격으로 인식하는 것을 방지하기 위해 중간중간에 sleep함수를 사용 |
8 | 8 | ||
9 | 9 | ||
10 | conn = pymysql.connect(host="localhost", user="root",password='abcde12345abcde',db='db_recipe', charset='utf8') | 10 | conn = pymysql.connect(host="localhost", user="root",password='abcde12345abcde',db='db_recipe', charset='utf8') |
11 | curs = conn.cursor(pymysql.cursors.DictCursor) | 11 | curs = conn.cursor(pymysql.cursors.DictCursor) |
12 | 12 | ||
13 | -for pagenum in range(1,35): #크롤링 할 상위 페이지 개수. 약 40개정도의 레시피 링크가 한 페이지에 이어져 있음 | 13 | +for pagenum in range(1,2): #크롤링 할 상위 페이지 개수. 약 40개정도의 레시피 링크가 한 페이지에 이어져 있음 |
14 | print(pagenum) | 14 | print(pagenum) |
15 | page = requests.get('https://www.10000recipe.com/recipe/list.html?order=reco&page='+str(pagenum)) | 15 | page = requests.get('https://www.10000recipe.com/recipe/list.html?order=reco&page='+str(pagenum)) |
16 | 16 | ... | ... |
-
Please register or login to post a comment