Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
DataInsert
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄卓然
DataInsert
Commits
2598347c
Commit
2598347c
authored
Jul 12, 2019
by
黄卓然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:批量添加json数据的脚本
parent
43c8e2db
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
0 deletions
+99
-0
.DS_Store
.DS_Store
+0
-0
index.js
index.js
+99
-0
package.json
package.json
+0
-0
No files found.
.DS_Store
0 → 100644
View file @
2598347c
File added
index.js
0 → 100755
View file @
2598347c
var
http
=
require
(
'http'
);
var
path
=
require
(
"path"
);
var
fs
=
require
(
"fs"
);
var
pathName
=
"../"
;
fs
.
readdir
(
pathName
,
function
(
err
,
files
){
var
dirs
=
[];
for
(
var
i
=
0
;
i
<
files
.
length
;
i
++
)
{
(
function
(
j
)
{
fs
.
stat
(
path
.
join
(
pathName
,
files
[
j
]),
function
(
err
,
data
){
if
(
data
.
isFile
()
&&
files
[
j
].
includes
(
"json"
)){
fs
.
readFile
(
'../'
+
files
[
j
],
'utf-8'
,
function
(
err
,
data
){
if
(
err
){
return
console
.
error
(
err
);
}
let
index
=
files
[
j
].
indexOf
(
"."
)
let
type
=
files
[
j
].
substring
(
0
,
index
)
// dirs.push(type);
let
array
=
[]
let
options
=
{
host
:
'admin.tx.haomo-tech.com'
,
path
:
'/api/com.haomo.'
+
type
,
method
:
'POST'
,
headers
:{
'Content-Type'
:
'application/json'
,
'Accept'
:
'application/json'
}
}
array
=
JSON
.
parse
(
data
);
//将字符串转换为json对象
postFun
(
array
,
type
,
0
);
})
}
});
})(
i
);
}
});
function
postFun
(
array
,
type
,
index
){
if
(
index
>=
array
.
length
)
return
;
let
options
=
{
host
:
'admin.tx.haomo-tech.com'
,
path
:
'/api/com.haomo.'
+
type
,
method
:
'POST'
,
headers
:{
'Content-Type'
:
'application/json'
,
'Accept'
:
'application/json'
}
}
console
.
log
(
options
)
// console.log(array[index]);
let
currParam
=
array
[
index
];
// console.log(currParam)
if
(
currParam
.
transactionId
!==
undefined
){
delete
currParam
.
transactionId
}
let
currParamStr
=
JSON
.
stringify
(
currParam
);
// console.log(currParamStr);
// console.log(options)
let
req
=
http
.
request
(
options
,
function
(
res
){
console
.
log
(
'STATUS:'
+
res
.
statusCode
);
console
.
log
(
'HEADERS:'
+
JSON
.
stringify
(
res
.
headers
));
res
.
setEncoding
(
'utf-8'
);
res
.
on
(
'data'
,
function
(
body
){
console
.
log
(
'BODY:'
+
body
);
});
res
.
on
(
'end'
,
function
(){
postFun
(
array
,
type
,
index
+
1
);
})
});
req
.
on
(
'err'
,
function
(
err
){
if
(
e
){
console
.
info
(
e
);
}
});
// 参数
console
.
log
(
currParam
);
req
.
write
(
currParamStr
,
'utf-8'
);
req
.
end
();
}
// req.write(content);
// req.end;
// postFun(0);
package.json
0 → 100644
View file @
2598347c
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment