-
Notifications
You must be signed in to change notification settings - Fork 2
/
craigNode.js
55 lines (42 loc) · 1.06 KB
/
craigNode.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
// you have to add your twilio account details here
var twilio = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');
var craigslist = require('node-craigslist');
client = craigslist({
city : 'phoenix'
}),
options = {
maxAsk :'12000',
minAsk : '8000',
};
client.search(options,'2007 civic', function (err, listings) {
var pids = '' ;
var pidsToText = '';
// play with listings here...
if (listings.length > 0 ) {
listings.forEach(function (listing) {
console.log(listing.pid);
pids = listing.pid + ',' + pids;
pidsToText = pids.substring(0, pids.length-1);
} )
// Add your phone numbers here
twilio.sendSms({
to:'phoneNo',
from:'TwilioNumber',
body: pidsToText }
,
// a little output of success/failure
function(error, message) {
if (!error) {
console.log('Success! The SID for this SMS message is:');
console.log(message.sid);
console.log('Message sent on:');
console.log(message.dateCreated);
}
else {
console.log('Oops! There was an error.');
console.log(error);
}
});
}
// );
});