-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweetBot.js
208 lines (183 loc) · 6.69 KB
/
TweetBot.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
var Twit = require('twit');
var T = new Twit({
consumer_key: ' '
, consumer_secret: ' '
, access_token: ' '
, access_token_secret: ' '
})
//T.get('application/rate_limit_status',function(err, data, response) {
// console.log(JSON.stringify(data, null, 2))})
//T.get('statuses/mentions_timeline', {count : 2}, function(err, data, response) {
// console.log(JSON.stringify(data, null, 2))})
//T.post('statuses/update', { status: 'hello world!' }, function(err, data, response) {
// console.log(data)
//})
var timeNYC = 0;
var timeBeijing = 0;
var timeLondon = 0;
var url = 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331766000&key=AIzaSyCI-v0iFwA1PqR6xMTKciq88IP-hM1FeO0';
//retourne un xml avec la date
//http://www.earthtools.org/timezone/40.71417/-74.00639
//var test =function getDateInLocation() {
// var time;
// var request = require("request");
// //time in NYC
// request.get("http://www.earthtools.org/timezone/40.7141667/-54.00639", function(error, response, body) {
// if (!error && response.statusCode == 200) {
// var parseString = require('xml2js').parseString;
// parseString(body, function(err, result) {
// time = result.timezone.localtime;
// time = time.toString();
// timeNYC = time;
// //console.log("timeNYC: " + timeNYC);
// });
// }
// });
//
// //time in Beijing
// request.get("http://www.earthtools.org/timezone/39.92889/116.38833", function(error, response, body) {
// if (!error && response.statusCode == 200) {
// var parseString = require('xml2js').parseString;
// parseString(body, function(err, result) {
// time = result.timezone.localtime;
// time = time.toString();
// timeBeijing = time;
// //console.log("timeBeijing: " + timeBeijing);
// });
// }
// });
//
//
// //time in London
// request.get("http://www.earthtools.org/timezone/51.5/-0.116667", function(error, response, body) {
// if (!error && response.statusCode == 200) {
// var parseString = require('xml2js').parseString;
// parseString(body, function(err, result) {
// time = result.timezone.localtime;
// time = time.toString();
// timeLondon = time;
// //console.log("timeLondon: " + timeLondon);
// });
// }
// });
// return "toto";
//}
//
//
//setTimeout(function() {
// console.log(typeof test);
// console.log("resultat final: " + timeNYC);
//}, 5000);
//var test = getDateInLocation();
//permet de voir en temps réel tous les tweets qui passent
//var stream = T.stream('statuses/filter', {track: 'mightyyDuck'})
//stream.on('tweet', function(tweet) {
// console.log('listening for tweets');
// console.log(tweet);
// console.log(tweet.text);
// if (tweet.text.indexOf('time') > -1) {
// var d = new Date();
// console.log(d);
// console.log(d.getHours() + ":" + (d.getMinutes() < 10 ? '0' : '') + d.getMinutes());
// //renvoie un tweet donnant la date exacte
//
// getDateInLocation();
// //var test = getDateInLocation();
//
// setTimeout(function() {
// console.log("timeLondonf: " + timeLondon);
// console.log("timeBeijingf: " + timeBeijing);
// console.log("timeNYCf: " + timeNYC);
// }, 5000);
//// T.post('statuses/update', {status: '@' + tweet.user.screen_name + ' \n Date a lemplacement du bot : ' + d + "\n\n\ date a new york :" + timeNYC}, function(err, data, response) {
//// console.log(getDateInLocation(40.7142700, -74.0059700));
//// })
// }
// else {
// // Si l'utilisateur fait une erreur dans ce quil a tappé, il lui renvoie un tweet d'erreur.
// console.log("erreur dans la demande");
// T.post('statuses/update', {status: '@' + tweet.user.screen_name + ' Desole erreur dans votre demande'}, function(err, data, response) {
// console.log(data);
// })
// }
//})
//fonction avec le return
var timeNYC;
function getDateInLocation(latitude, longitude) {
var time;
var request = require("request");
request.get("http://www.earthtools.org/timezone/" + latitude + "/" + longitude, function(error, response, body) {
//if (!error && response.statusCode == 200) {
var parseString = require('xml2js').parseString;
parseString(body, function(err, result) {
time = result.timezone.localtime;
time = time.toString();
timeNYC = time;
console.log("time: " + time);
});
//}
console.log("time2: " + time);
});
// setTimeout(function() {
// console.log("time3: " + time);
// return time;// on veut qu'il retourne toto ca marche pas
// }, 5000);
console.log("timetest: " + time);
// return time;
}
var test = getDateInLocation(40.7142700, -74.0059700);
setTimeout(function() {
console.log(typeof test);
console.log("resultat final: " + timeNYC);
}, 10000);
// retweet pour chaque mention
//
//function retweetRecent() {
// T.get('search/tweets', {q: "@GreatMightyDuck ", result_type: "recent"}, function (err, data,response) {
// if (!err) {
// var retweetId = data.statuses[0].id_str;
// T.post('statuses/retweet/' + retweetId, { }, function (err, response) {
// if (response) {
// console.log('Retweeted Tweet ID: ' + retweetId);
// }
// if (err) {
// console.log('Retweet Error: ', err);
// }
// });
// } else {
// console.log('Search Error: ', err);
// }
// });
//}
//
//retweetRecent();
//setInterval(retweetRecent, 60000);
//var test = getDateInLocation(40.7142700, -74.0059700);
//
//function getDateInLocation(latitude, longitude) {
// var request = require("request");
// var time;
// request.get("http://www.earthtools.org/timezone/" + latitude + "/" + longitude, function(err, res, body) {
// if (!err) {
// var parseString = require('xml2js').parseString;
// var xml = body;
// parseString(xml, function(err, result) {
// //console.log(JSON.stringify(result, null, 2));
// time = result.timezone.localtime;
// time = time.toString();
// });
// }
// console.log("time2:" + time);
// console.log(typeof time);
// });
// console.log("time3:" + time);
// console.log(typeof time);
//
//
// setTimeout(function() {
// return time;
// }, 5000);
//}
// doc npm install request
//npm install xml2js
//http://www.earthtools.org/webservices.htm#timezone