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-04 21:28:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2f4b3dd3904231554bc0d961820218507c5a1a77
2f4b3dd3
1 parent
1846ccba
module exports setting ready
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
84 deletions
app.js
auction.js
coupang.js
gmarket.js
app.js
View file @
2f4b3dd
var
express
=
require
(
'express'
);
var
path
=
require
(
'path'
);
var
favicon
=
require
(
'serve-favicon'
);
//var logger = require('morgan');
var
cookieParser
=
require
(
'cookie-parser'
);
var
bodyParser
=
require
(
'body-parser'
);
var
mysql
=
require
(
'mysql'
);
var
request
=
require
(
'request'
);
//var index = require('./routes/index');
//var users = require('./routes/users');
//var mytoons = require('./routes/mytoons');
//var yourtoons=require('./routes/yourtoons');
var
passport
=
require
(
'passport'
);
//var setting = require('./routes/setting');
var
session
=
require
(
'express-session'
);
//port
/*passport.serializeUser(function(user, done) {
console.log('serialized');
done(null, user);
});
passport.deserializeUser(function(user, done) {
console.log('deserialized');
done(null, user);
});
*/
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'LFi+FvOOFOydz0EKN22WRnQyiilnEiyxe2HVV1WrI54Jnght6+Gga07m7pxqSQltBJG2AV2lYnYOAk4TqxzZFKW9R36CJcQs+NaNEiNKJtgBfT/t3tEta/J6GtXxGz/DqdHnfZqSSfLFpXzun/ITTwdB04t89/1O/w1cDnyilFU='
const
PAPAGO_URL
=
'https://openapi.naver.com/v1/papago/n2mt'
const
PAPAGO_ID
=
'r_kuebFKCqBeL3SI_dFb'
const
PAPAGO_SECRET
=
'Wdz2tudrzB'
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"www.chatbotshin.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
// target language verification
var
trans_dest
=
undefined
;
var
app
=
express
();
// view engine setup
app
.
set
(
'views'
,
path
.
join
(
__dirname
,
'views'
));
app
.
set
(
'view engine'
,
'ejs'
);
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app
.
use
(
logger
(
'dev'
));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
cookieParser
());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'public'
)));
connection
=
mysql
.
createConnection
({
host
:
'localhost'
,
user
:
'root'
,
password
:
'password'
,
port
:
3306
,
database
:
'Shoppingcart'
});
app
.
use
(
session
({
secret
:
'secrettexthere'
,
saveUninitialized
:
true
,
resave
:
true
}));
app
.
use
(
passport
.
initialize
());
app
.
use
(
passport
.
session
());
app
.
use
(
'/'
,
index
);
app
.
use
(
'/users'
,
users
);
app
.
use
(
'/mytoons'
,
mytoons
);
app
.
use
(
'/setting'
,
setting
);
app
.
use
(
'/yourtoons'
,
yourtoons
);
//app.use(express.static('views'));
// catch 404 and forward to error handler
app
.
use
(
function
(
req
,
res
,
next
)
{
var
err
=
new
Error
(
'Not Found'
);
err
.
status
=
404
;
next
(
err
);
});
// error handler
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
// set locals, only providing error in development
res
.
locals
.
message
=
err
.
message
;
res
.
locals
.
error
=
req
.
app
.
get
(
'env'
)
===
'development'
?
err
:
{};
// render the error page
res
.
status
(
err
.
status
||
500
);
res
.
render
(
'error'
);
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
// language identification & translation
if
(
eventObj
.
message
.
text
==
'영어'
||
eventObj
.
message
.
text
==
'프랑스어'
||
eventObj
.
message
.
text
==
'일본어'
){
trans_change
(
eventObj
.
message
.
text
);
console
.
log
(
'[trans_dest]'
,
trans_dest
);
}
else
if
(
trans_dest
!=
undefined
){
trans
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
}
res
.
sendStatus
(
200
);
});
var
server
=
app
.
listen
(
3000
);
module
.
exports
=
app
;
\ No newline at end of file
function
trans
(
replyToken
,
message
)
{
request
.
post
(
{
url
:
PAPAGO_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'X-Naver-Client-Id'
:
`
${
PAPAGO_ID
}
`
,
'X-Naver-Client-Secret'
:
`
${
PAPAGO_SECRET
}
`
},
body
:
'source=ko&'
+
trans_dest
+
'&text='
+
message
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
body
.
message
);
var
transMessage
=
body
.
message
.
result
.
translatedText
;
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
transMessage
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
// language index identification
function
trans_change
(
index
){
if
(
index
==
'영어'
){
trans_dest
=
'target=en'
;
}
else
if
(
index
==
'일본어'
){
trans_dest
=
'target=ja'
;
}
else
if
(
index
==
'프랑스어'
){
trans_dest
=
'target=fr'
;
}
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
\ No newline at end of file
...
...
auction.js
View file @
2f4b3dd
const
puppeteer
=
require
(
'puppeteer'
);
const
readline
=
require
(
'readline'
);
//auction_c();
//
Gmarket
Cart Crawling
(
async
()
=>
{
//
auction
Cart Crawling
async
function
auction_c
()
{
// launching headless browser
const
browser
=
await
puppeteer
.
launch
();
...
...
@@ -29,13 +29,12 @@ const readline = require('readline');
await
console
.
log
(
a_id
,
a_pw
);
// try login
// await page.keyboard.press(String.fromCharCode(13));
await
page
.
click
(
'.btn_login'
);
await
page
.
waitForNavigation
();
// goto cart page
await
page
.
goto
(
'https://cart.auction.co.kr/ko/cart'
);
await
page
.
screenshot
({
path
:
'auction.png'
,
fullPage
:
true
});
//
await page.screenshot({ path: 'auction.png', fullPage:true });
// container which will hold crawled data [{},{}...]
let
data
=
[];
...
...
@@ -51,7 +50,7 @@ const readline = require('readline');
await
browser
.
close
();
}
)();
}
...
...
coupang.js
View file @
2f4b3dd
const
puppeteer
=
require
(
'puppeteer'
);
// Gmarket Cart Crawling
(
async
()
=>
{
//coupang_c();
// coupang Cart Crawling
async
function
coupang_c
(){
// launching headless browser
const
browser
=
await
puppeteer
.
launch
();
...
...
@@ -34,7 +36,7 @@ const puppeteer = require('puppeteer');
// goto cart page
await
page
.
goto
(
'https://cart.coupang.com/cartView.pang'
);
await
page
.
screenshot
({
path
:
'coupang.png'
,
fullPage
:
true
});
//
await page.screenshot({ path: 'coupang.png', fullPage:true });
// container which will hold crawled data [{},{}...]
let
data
=
[];
...
...
@@ -50,7 +52,7 @@ const puppeteer = require('puppeteer');
await
browser
.
close
();
}
)();
}
...
...
@@ -91,4 +93,8 @@ async function getOne(page, index) {
// not yet
return
Promise
.
resolve
(
data
);
}
\ No newline at end of file
}
module
.
exports
.
coupang_c
=
coupang_c
;
module
.
exports
.
getOne
=
getOne
;
module
.
exports
.
getAll
=
getAll
;
\ No newline at end of file
...
...
gmarket.js
View file @
2f4b3dd
const
puppeteer
=
require
(
'puppeteer'
);
const
readline
=
require
(
'readline'
);
//gmarket_c();
// Gmarket Cart Crawling
(
async
()
=>
{
async
function
gmarket_c
()
{
// launching headless browser
const
browser
=
await
puppeteer
.
launch
();
...
...
@@ -34,7 +35,7 @@ const readline = require('readline');
// goto cart page
await
page
.
goto
(
'https://cart.gmarket.co.kr/ko/cart'
);
await
page
.
screenshot
({
path
:
'gmarket.png'
,
fullPage
:
true
});
//
await page.screenshot({ path: 'gmarket.png', fullPage:true });
// container which will hold crawled data [{},{}...]
let
data
=
[];
...
...
@@ -50,7 +51,7 @@ const readline = require('readline');
await
browser
.
close
();
}
)();
}
...
...
@@ -90,4 +91,8 @@ async function getOne(page, index) {
// not yet
return
Promise
.
resolve
(
data
);
}
\ No newline at end of file
}
module
.
exports
.
gmarket_c
=
gmarket_c
;
module
.
exports
.
getOne
=
getOne
;
module
.
exports
.
getAll
=
getAll
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment