save
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import fs from 'fs'
|
||||
import request from 'request'
|
||||
import {nanoid} from 'nanoid'
|
||||
import {users} from './user/data.js'
|
||||
|
||||
let read = './post/data/'
|
||||
let save = "./format/";
|
||||
@@ -18,7 +17,10 @@ function formatDict(dir, name) {
|
||||
let filePath = dir + name
|
||||
let saveFileStr = fs.readFileSync(filePath, "utf8");
|
||||
let inputData = JSON.parse(saveFileStr);
|
||||
map.push(inputData)
|
||||
map.push({
|
||||
userId: name,
|
||||
list: inputData
|
||||
})
|
||||
if (max < inputData.length) max = inputData.length
|
||||
}
|
||||
|
||||
@@ -26,13 +28,21 @@ let newList = []
|
||||
// max = 5
|
||||
for (let i = 0; i < max; i++) {
|
||||
map.map(v => {
|
||||
if (v.length > i) {
|
||||
newList.push(v[i])
|
||||
if (v.list.length > i) {
|
||||
let data = v.list[i]
|
||||
newList.push(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// console.log(newList)
|
||||
|
||||
fs.writeFileSync('./posts5.json', JSON.stringify(newList.slice(0, 5), null, 2));
|
||||
fs.writeFileSync('./posts.json', JSON.stringify(newList.slice(5), null, 2));
|
||||
let data = newList.slice(0, 6)
|
||||
data.map(v => {
|
||||
let u = users.find(a => a.uid == v.author_user_id)
|
||||
if (u) {
|
||||
v.author = u
|
||||
}
|
||||
})
|
||||
fs.writeFileSync('./posts6.json', JSON.stringify(data, null, 2));
|
||||
fs.writeFileSync('./posts.json', JSON.stringify(newList.slice(6), null, 2));
|
||||
|
||||
Reference in New Issue
Block a user