Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionando busca automática de termos no Google Trends e generalizando a função de user input #21

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ typings/
# next.js build output
.next

# credentials
Pacheco95 marked this conversation as resolved.
Show resolved Hide resolved
credentials/*.json
# webstorm ide files
.idea
47 changes: 28 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
const readline = require('readline-sync')
const robots = {
text: require('./robots/text.js')
}

async function start() {
const content = {}
const readline = require('readline-sync');
const trends = require('./searchHotTrends');

content.searchTerm = askAndReturnSearchTerm()
content.prefix = askAndReturnPrefix()
function start() {
const searchFields = {};

await robots.text(content)
askAndReturnSearchTerm()
.then(term => {
searchFields.searchTerm = term;
searchFields.prefix = askAndReturnPrefix();
console.log(searchFields);
});

function askAndReturnSearchTerm() {
return readline.question('Type a Wikipedia search term: ')
let typedTerm = readline.question('Type a search term or press <Enter> to get a list of hot terms: ');
if (typedTerm)
return new Promise(resolve => resolve(typedTerm));
Pacheco95 marked this conversation as resolved.
Show resolved Hide resolved
else {
console.log('Auto searching for hot terms online...');
return trends.searchHotTrends()
.then(function (hotTerms) {
return getUserOptionInput(hotTerms, 'Choose on term: ');
});
}
}

function askAndReturnPrefix() {
const prefixes = ['Who is', 'What is', 'The history of']
const selectedPrefixIndex = readline.keyInSelect(prefixes, 'Choose one option: ')
const selectedPrefixText = prefixes[selectedPrefixIndex]

return selectedPrefixText
function getUserOptionInput(options, message) {
const selectedOption = readline.keyInSelect(options, message);
return options[selectedOption];
}

console.log(content)
function askAndReturnPrefix() {
const prefixes = ['Who is', 'What is', 'The history of'];
return getUserOptionInput(prefixes, 'Choose one option: ');
}
}

start()
start();
235 changes: 0 additions & 235 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
},
"homepage": "https://github.com/filipedeschamps/video-maker#readme",
"dependencies": {
"algorithmia": "^0.3.10",
"readline-sync": "^1.4.9",
"sbd": "^1.0.14"
"google-trends-api": "^4.9.0",
"readline-sync": "^1.4.9"
}
}
23 changes: 23 additions & 0 deletions searchHotTrends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const googleTrends = require('google-trends-api');

module.exports = {
searchHotTrends: function () {
let trendsSettings = {
Pacheco95 marked this conversation as resolved.
Show resolved Hide resolved
trendDate: new Date(),
geo: 'BR',
hl: "pt-BR"
};

return googleTrends.realTimeTrends(trendsSettings)
Pacheco95 marked this conversation as resolved.
Show resolved Hide resolved
.then(results => {
let hotTrendStories = JSON.parse(results)['storySummaries']['trendingStories'];
let hotTrends = [];
hotTrendStories.forEach((story) => hotTrends = hotTrends.concat(story['entityNames']));
return hotTrends.slice(0, 9);
})
.catch(error => {
console.error('An error occurs: ', error);
return [];
});
}
};