Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신일섭
/
ShoppingCart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
4
Network
Create a new issue
Commits
Issue Boards
Authored by
신일섭
2020-06-13 23:16:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7f5e488eabc25c5ff881bf3ae2afc95948bcc451
7f5e488e
1 parent
d17390b3
db 업데이트중
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
18 deletions
crawling/gmarket.js
db/dbcontrol.js
dbcontrol.js
route/route.js
crawling/gmarket.js
View file @
7f5e488
...
...
@@ -15,12 +15,10 @@ const token = require('../config/key');
const
TOKEN
=
token
.
token
;
//사용자 토큰
//----------------------------------------------------------
//----------------low db-----------------------------------
const
low
=
require
(
'lowdb'
);
const
FileSync
=
require
(
'lowdb/adapters/FileSync'
)
const
adapter
=
new
FileSync
(
'db.json'
);
const
db
=
low
(
adapter
);
//---------------------------------------------------------
// ------------ db calling modules ---------
var
dbcontrol
=
require
(
'../db/dbcontrol'
);
// -----------------------------------------
// Gmarket Cart Crawling
async
function
gmarket_c
(
user_id
,
g_id
,
g_pw
){
...
...
@@ -66,6 +64,8 @@ async function gmarket_c(user_id, g_id, g_pw){
console
.
log
(
data
[
index
]);
}
//여기에 db에 추가하는 코드 넣기
await
browser
.
close
();
...
...
db/dbcontrol.js
0 → 100644
View file @
7f5e488
//----------------low db-----------------------------------
const
request
=
require
(
'request'
);
const
low
=
require
(
'lowdb'
);
const
FileSync
=
require
(
'lowdb/adapters/FileSync'
)
const
fs
=
require
(
'fs'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TARGET_URL_2
=
'https://api.line.me/v2/bot/message/push'
const
token
=
require
(
'../config/key'
);
const
TOKEN
=
token
.
token
;
// 사용자 토큰
//var USER_ID = ' '; // LINE 메세지 유저 아이디
//---------------------------------------------------------
// db 초기화
function
start_db
(
USER_ID
){
const
adapter
=
new
FileSync
(
USER_ID
+
'.json'
);
const
db
=
low
(
adapter
);
db
.
defaults
({
cart
:
[]}).
write
();
}
// 장바구니 동기화
function
synchronization
(
USER_ID
,
prd_img
,
prd_name
,
prd_price
,
prd_link
){
const
adapter
=
new
FileSync
(
USER_ID
+
'.json'
);
const
db
=
low
(
adapter
);
db
.
defaults
({
cart
:
[]}).
write
();
// 중복 있는지 검사하는 코드를 if구문에 넣기 (prd_link 기반으로)
// 입력받은 정보를 db에 저장
db
.
get
(
'cart'
)
.
push
({
PRD_IMG
:
prd_img
,
PRD_NAME
:
prd_name
,
PRD_PRICE
:
prd_price
,
PRD_LINK
:
prd_link
}).
write
();
}
// db에서 목록 검색 후 삭제
function
deleting
(
USER_ID
,
prd_link
){
const
adapter
=
new
FileSync
(
USER_ID
+
'.json'
);
const
db
=
low
(
adapter
);
db
.
defaults
({
cart
:
[]}).
write
();
db
.
get
(
'cart'
)
.
remove
({
PRD_LINK
:
prd_link
})
.
write
();
// prd_link 참조 삭제
}
// db에서 USER_ID 기반 장바구니 조회
function
viewing
(
USER_ID
){
const
adapter
=
new
FileSync
(
USER_ID
+
'.json'
);
const
db
=
low
(
adapter
);
db
.
defaults
({
cart
:
[]}).
write
();
var
datalist
=
new
Array
();
datalist
=
db
.
get
(
'cart'
).
value
();
// [ { } ] 배열속 객체형태로 리턴
//미완성 - 메세지로 내역 push하는 기능 업데이트 요망
}
//================== Just replying specific messages needed ===================================
async
function
replying
(
replyToken
,
sp_message
){
// sp_message is message(string) that depends on the situation that user selects
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
sp_message
// replying message
}
]
}
},(
error
,
response
,
body
)
=>
{
// console.log(body)
});
}
//================== Just pushing specific messages needed ===================================
async
function
pushing
(
USER_ID
,
sp_message
){
//push function
request
.
post
(
{
url
:
TARGET_URL_2
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"to"
:
`
${
USER_ID
}
`
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
sp_message
// replying message
}
]
}
},(
error
,
response
,
body
)
=>
{
//console.log(body)
});
}
//================== 장바구니 목록 전체 출력 ===================================
async
function
viewall
(
img_link
,
msg1
,
msg2
,
msg3
){
//push function
request
.
post
(
{
url
:
TARGET_URL_2
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"to"
:
`
${
USER_ID
}
`
,
"messages"
:[
{
"type"
:
"image"
,
"originalContentUrl"
:
img_link
,
"previewImageUrl"
:
img_link
},
{
"type"
:
"text"
,
"text"
:
"상품명: "
+
msg1
// replying message
},
{
"type"
:
"text"
,
"text"
:
"가격: "
+
msg2
+
" 원"
// replying message
},
{
"type"
:
"text"
,
"text"
:
"링크: "
+
msg3
// replying message
}
]
}
},(
error
,
response
,
body
)
=>
{
//console.log(body)
});
}
module
.
exports
.
start_db
=
start_db
;
module
.
exports
.
synchronization
=
synchronization
;
module
.
exports
.
deleting
=
deleting
;
module
.
exports
.
viewing
=
viewing
;
\ No newline at end of file
dbcontrol.js
deleted
100644 → 0
View file @
d17390b
//----------------low db-----------------------------------
const
low
=
require
(
'lowdb'
);
const
FileSync
=
require
(
'lowdb/adapters/FileSync'
)
const
adapter
=
new
FileSync
(
'db.json'
);
const
db
=
low
(
adapter
);
//---------------------------------------------------------
\ No newline at end of file
route/route.js
View file @
7f5e488
...
...
@@ -24,6 +24,10 @@ var method_action = 0; // typing count;
var
user_info
=
new
Array
();
// 유저 정보 저장용
//------------------------------------------
// ------------ db calling modules ---------
var
dbcontrol
=
require
(
'../db/dbcontrol'
);
// -----------------------------------------
// ========================================= 쇼핑몰 연결 중계 =========================================
async
function
shoppingroute
(
user_message
,
user_id
,
replyToken
){
...
...
@@ -66,18 +70,14 @@ async function shoppingroute(user_message, user_id, replyToken){
shopping
=
2
;
}
}
if
(
user_message
==
'/장바구니조회'
)
{
}
if
(
user_message
==
'/장바구니추가'
)
/* if(user_message == '/장바구니조회')
{
}
if(user_message == '/장바구니삭제')
{
}
}
*/
//이 기능을 마켓선택기능에 넣는것이 좋을거같음 (db를 공유하기때문에)
}
}
...
...
Please
register
or
login
to post a comment