-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
106 lines (96 loc) · 2.9 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('text', '');
Template.hello.helpers({
counter: function () {
return Session.get('counter');
},
text: function () {
return Session.get('text');
}
});
Template.hello.events({
'click button': function () {
var name = $('#artist_name').val();
if(name != '') {
Meteor.call(
'parse', name,
function(error, result) {
// console.log(result);
if(result != "error") {
Session.set('text', result);
}
}
);
} else {
Session.set('text', "please enter a name");
}
}
});
}
if (Meteor.isServer) {
//Meteor.startup(function () {
Meteor.methods({
parse: function(fullname) {
if(fullname!='') {
var f = fullname.split(' ');
var name = f[0];
var surname = f[1];
if(typeof surname == 'undefined')
surname = "test";
// console.log('name', name);
var result = HTTP.call(
"POST",
"http://www.500letters.org/form_15.php",
{
params: {
'f1_gender': 'male',
'f1_firstname': name,
'f1_surname': surname,
'f1_birthyear': 1980+Math.floor(Math.random()*10),
'f1_birthCity': '',
'f1_country': '2',
'f1_workplaceCity': '',
'f3_mainMedia': random_media(),
'f4_theme': random_theme(),
'generate_bio': 'Generate artist text',
},
headers: {
'Content-type': 'application/x-www-form-urlencoded'
}
}
);
if(result) {
// console.log(result.content);
var $ = cheerio.load(result.content);
// console.log($('.text_container > .formdiv').text());
return $('.text_container > .formdiv').text();
}
}
return "error";
}
});
function random_theme() {
var themes = ["Abstraction","Aesthetics", "Alienation", "Appropriation", "Archive", "Chance", "Concept"];
// return [themes[];
var array = getRandomArrayElements(themes, Math.floor(Math.random()*themes.length-1)+1 );
console.log('array', array);
return array;
}
function random_media() {
var array = ["Painting", "Photography", "Drawing", "Sculpture", "Performance", "Media art", "Installations"];
console.log('mix', array[Math.floor(Math.random()*array.length)]);
return array[Math.floor(Math.random()*array.length)];
}
function getRandomArrayElements(arr, count) {
var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}
//});
}