Commit db544529 authored by Alexandra Rogova's avatar Alexandra Rogova

random rss generator

parent 331f3176
......@@ -8,7 +8,7 @@ const args = require("yargs")
.demandOption(['paragraphs'])
.alias("p", "paragraphs")
.describe("paragraphs", "Number of random paragraphs to generate")
.nargs("prom", 1)
.nargs("p", 1)
.argv;
var start, browser;
......
const randomstring = require("randomstring");
const fs = require('fs');
const args = require("yargs")
.usage("Usage : gen_random_rss.js -n number of items to generate")
.demandOption(['number'])
.alias("n", "number")
.describe("number", "Number of random items to generate")
.nargs("number", 1)
.argv;
function gen_rdm_string (length){
return randomstring.generate({
length: length,
charset: 'alphabetic'
});
}
function gen_rdm_sentence (word_count, word_length){
var tmp_word_array = [];
for (var i = 0; i<word_count; i+=1){
tmp_word_array[i] = gen_rdm_string(word_length);
}
return tmp_word_array.join(" ");
}
function gen_rdm_paragraph (sentence_count, words_per_sentence, word_length){
var tmp_sentence_array = [];
for (var i=0; i<sentence_count; i+=1){
tmp_sentence_array[i] = gen_rdm_sentence(words_per_sentence, word_length);
}
return tmp_sentence_array.join(". ");
}
function gen_random_content (){
var to_write = "<rss version=\"0.91\"><channel><title>RSS TEST FILE</title><link>http://example.com/</link><description>A randomly generated RSS File</description>\n";
for (var i = 0; i<args.n; i+=1){
to_write += "<item>\n<title>\n";
to_write += gen_rdm_sentence(5, 10);
to_write += "\n</title>\n<description>\n";
to_write += gen_rdm_paragraph(15, 10, 6);
to_write += "\n</description>\n</item> \n";
}
to_write += "</channel> </rss>";
return to_write;
}
var to_write = gen_random_content();
fs.writeFile("./test_files/RSS/rss_"+args.n+".xml", to_write, function(err){
if(err) return console.log(err);
console.log("The file was saved!");
});
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment