Skip to content

Commit

Permalink
Add editorconfig and change indent size from 4 spaces to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoNelsi committed Feb 20, 2020
1 parent 22a13ca commit d9ca9ce
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 304 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
17 changes: 8 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ const imageRobot = require('./robots/image-robot.js')
const export_robot = require('./robots/export.js')

async function start() {

const content = {}

content.searchTerm = userInput.askAndReturnSearchTerm()
content.language = userInput.askAndReturnLanguage()
const content = {}

await textRobot(content)
content.searchTerm = userInput.askAndReturnSearchTerm()
content.language = userInput.askAndReturnLanguage()

export_robot.createFolder(content)
await imageRobot(content)
await textRobot(content)

export_robot.exportDocx(content)
export_robot.exportJSON(content)
export_robot.createFolder(content)
await imageRobot(content)

export_robot.exportDocx(content)
export_robot.exportJSON(content)

}

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wikipedia-content-getter",
"version": "1.0.0",
"description": "Projeto para pegar conteudo do wikipedia e formatá-lo em .docx",
"description": "Project to get content from wikipedia and format to .docx file",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -26,13 +26,13 @@
"sbd": "^1.0.16",
"watson-developer-cloud": "^4.0.1"
},
"bin":"index.js",
"pkg":{
"assets":[
"bin": "index.js",
"pkg": {
"assets": [
"robots/**/*",
"credentials/**/*"
],
"targets":[
"targets": [
"node10-win-x86"
]
}
Expand Down
199 changes: 99 additions & 100 deletions robots/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,136 +2,135 @@ const docx = require('docx')
const fs = require('fs')

exports.exportDocx = content => {

const doc = new docx.Document()

addTitleAndAbstract()
addMainText()
saveDocument()

function addTitleAndAbstract() {
const doc = new docx.Document()

const title = new docx.Paragraph({
addTitleAndAbstract()
addMainText()
saveDocument()

text: content.searchTerm.toUpperCase(),
heading: docx.HeadingLevel.TITLE,
spacing: {
after: 500
}
function addTitleAndAbstract() {

})
const title = new docx.Paragraph({

const abstractText = new docx.TextRun({
text: content.searchTerm.toUpperCase(),
heading: docx.HeadingLevel.TITLE,
spacing: {
after: 500
}

text: content.summarizedSourceContent,
bold: true,
italics: true,
font: 'Calibri',
size: 20
})

})

const abstractParagraph = new docx.Paragraph({
children: [abstractText]
})
const abstractText = new docx.TextRun({

text: content.summarizedSourceContent,
bold: true,
italics: true,
font: 'Calibri',
size: 20

doc.addSection({
children: [title, abstractParagraph]
})
})

}
const abstractParagraph = new docx.Paragraph({
children: [abstractText]
})


function addMainText() {

let finallText = []
let mainText = []

content.sessions.forEach((session) => {
const sessionTitle = new docx.TextRun({
text: session.title,
bold:true,
italics: false,
size: 36,
font: 'Arial'
})
addParagraph(sessionTitle)


if(session.text.length != 0) {
const image = docx.Media.addImage(doc, fs.readFileSync(process.cwd() + `\\${content.searchTerm}\\images\\${session.title}.png`), 550, 300)
mainText.push(new docx.Paragraph({
children:[image]
}))
}


const text = new docx.TextRun({
text: session.text,
bold: false,
italics: false,
size: 24,
font: 'Arial'
})
addParagraph(text)
})


function addParagraph(text) {
mainText.push(new docx.Paragraph({
children:[text],
alignment: docx.AlignmentType.JUSTIFIED,
spacing: {
line: 360
}
}))
}


doc.addSection({
children:mainText
})
doc.addSection({
children: [title, abstractParagraph]
})

}

}

function saveDocument() {
function addMainText() {

let mainText = []

content.sessions.forEach((session) => {
const sessionTitle = new docx.TextRun({
text: session.title,
bold: true,
italics: false,
size: 36,
font: 'Arial'
})
addParagraph(sessionTitle)


if (session.text.length != 0) {
const image = docx.Media.addImage(doc, fs.readFileSync(process.cwd() + `\\${content.searchTerm}\\images\\${session.title}.png`), 550, 300)
mainText.push(new docx.Paragraph({
children: [image]
}))
}


const text = new docx.TextRun({
text: session.text,
bold: false,
italics: false,
size: 24,
font: 'Arial'
})
addParagraph(text)
})

docx.Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync(`${content.searchTerm}/${content.searchTerm}.docx`, buffer, (err) => {
console.log('-------------------');
console.error(err);
console.log('-------------------');
})
})

function addParagraph(text) {
mainText.push(new docx.Paragraph({
children: [text],
alignment: docx.AlignmentType.JUSTIFIED,
spacing: {
line: 360
}
}))
}



doc.addSection({
children: mainText
})

}

function saveDocument() {

docx.Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync(`${content.searchTerm}/${content.searchTerm}.docx`, buffer, (err) => {
console.log('-------------------');
console.error(err);
console.log('-------------------');
})
})

}


}


exports.exportJSON = content => {

const file = JSON.stringify(content)
const file = JSON.stringify(content)

return fs.writeFileSync(`${content.searchTerm}/${content.searchTerm}.json`, file)
return fs.writeFileSync(`${content.searchTerm}/${content.searchTerm}.json`, file)

}

exports.createFolder = content => {

fs.mkdirSync(process.cwd() + `..\\${content.searchTerm}`, {recursive:true}, (err) => {
if(err) {
console.error(err);
}
})
fs.mkdirSync(process.cwd() + `..\\${content.searchTerm}`, { recursive: true }, (err) => {
if (err) {
console.error(err);
}
})

fs.mkdirSync(process.cwd() + `\\${content.searchTerm}\\images`, {recursive:true}, (err) => {
if(err) {
console.error(err);
}
})
fs.mkdirSync(process.cwd() + `\\${content.searchTerm}\\images`, { recursive: true }, (err) => {
if (err) {
console.error(err);
}
})

}

Expand Down
Loading

0 comments on commit d9ca9ce

Please sign in to comment.