Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-05-06 03:21:26 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
74c653540454b47e94cfc8a1aac7b9825830daf5
74c65354
1 parent
e22487ba
feat. mqtt and medicine db module
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
server/src/lib/MqttModule.js
server/src/lib/UpdatingMedicineInfo.js
server/src/lib/MqttModule.js
View file @
74c6535
const
mqtt
=
require
(
'mqtt'
);
exports
.
mqttOn
=
async
(
hosting
,
topic
)
=>
{
exports
.
mqttOn
=
(
hosting
)
=>
{
const
client
=
mqtt
.
connect
(
hosting
);
client
.
on
(
'connect'
,
()
=>
{
console
.
log
(
'Connected : '
,
client
.
connected
)
});
return
client
;
}
exports
.
mqttSubscribe
=
(
client
,
topic
)
=>
{
client
.
subscribe
(
topic
);
client
.
on
(
'message'
,
(
topic
,
message
,
packet
)
=>
{
console
.
log
(
'topic : '
,
topic
);
console
.
log
(
'message : '
,
message
.
toString
());
});
}
\ No newline at end of file
...
...
server/src/lib/UpdatingMedicineInfo.js
View file @
74c6535
const
axios
=
require
(
'axios'
);
const
Medicine
=
require
(
'../models/medicine'
);
exports
.
updateMedicineInfo
=
async
()
=>
{
console
.
log
(
'starting'
)
const
itemArray
=
await
getItemsList
(
getQueryURL
);
await
exportJsonData
(
itemArray
);
console
.
log
(
'
data is saved
'
);
console
.
log
(
'
All of data is updated!
'
);
}
//queryUrl을 return하는 함수 : 한 페이지에 100개의 item씩 요청할 수 있다.
...
...
@@ -29,7 +28,7 @@ const getItemsList = async(queryUrl) => {
getItem
=
await
axios
.
get
(
queryUrl
(
i
));
items
=
getItem
.
data
.
body
.
items
;
if
(
items
===
undefined
)
if
(
items
===
undefined
)
return
result
;
result
.
push
(...
items
);
...
...
@@ -38,9 +37,23 @@ const getItemsList = async(queryUrl) => {
}
}
//itemArray에 있는 모든 data를
json으로 만들어서 json파일로 저장
//itemArray에 있는 모든 data를
MongoDB의 SMB collections에 저장함
const
exportJsonData
=
async
(
itemList
)
=>
{
itemList
.
forEach
(
item
=>
{
const
medicine
=
new
Medicine
({
medicineId
:
item
.
itemSeq
,
name
:
item
.
itemName
,
company
:
item
.
entpName
,
target
:
item
.
efcyQesitm
,
dosage
:
item
.
useMethodQesitm
,
warn
:
item
.
atpnWarnQesitm
+
'\n\n'
+
item
.
atpnQesitm
,
antiEffect
:
item
.
seQesitm
})
Medicine
.
findOneAndUpdate
({
medicineId
:
medicine
.
medicineId
},
medicine
,
{
upsert
:
true
})
})
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment