public static async void UserStream() { string requestUri = "https://stream.twitter.com/1.1/statuses/filter.json?track=trump"; using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(requestUri); TestHeader = TwitterConfig.GetAuthHeader(requestUri); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", TestHeader); httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); var stream = await httpClient.GetStreamAsync(requestUri).ConfigureAwait(false); using (var reader = new StreamReader(stream)) { while (!reader.EndOfStream) { //We are ready to read the stream var currentLine = reader.ReadLine(); SparkBot.PostMessage(currentLine); Thread.Sleep(500); } } } }
public static void StreamTwitter(string search) { TwitterConfig.setCredentials(); var stream = Tweetinvi.Stream.CreateFilteredStream(); stream.AddTweetLanguageFilter(LanguageFilter.English); stream.AddTrack(search); stream.MatchingTweetReceived += (sender, args) => { SparkBot.PostMessage(args.Tweet.Text); }; stream.StartStreamMatchingAllConditionsAsync(); }
public void PostSensor([FromBody] Sensor sensor) { string status = "Normal"; if (Convert.ToDecimal(sensor.temperature) > CRIT_TEMP || Convert.ToDecimal(sensor.pressure) > CRIT_PRESSURE) { string message = "Critical readings LSD " + sensor.LSD + "\n" + "Temperature: " + sensor.temperature + "\n" + "Pressure: " + sensor.pressure; SparkBot.NotifyText(message); SparkBot.PostMessage(message); status = "Alert"; } sensor.status = status; DBAccess.InsertSensor(sensor); }
private static void CheckSensor() { HttpClient getClient = new HttpClient(); string getAddress = "https://api.relayr.io/devices/e84e2eb1-80bf-48e8-a5c1-c710c5310281/readings"; getClient.BaseAddress = new Uri(getAddress); getClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); getClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "RNClQ25HqmxEtFquKuGRAv4b8OAnFbzvh5MpFgNtyqpJOOcngIQEGwf0Xw0vgF4n"); HttpResponseMessage response = getClient.GetAsync("").Result; var readingWrapper = response.Content.ReadAsAsync <ReadingWrapper>().Result; decimal temperature = Convert.ToDecimal(readingWrapper.readings[0].value); Sensor sensor = new Sensor(); string status = "Normal"; string message = ""; if (temperature > 30) { message = "Critical readings at: " + "\n" + "LSD: 66-27-75-05W4 \n" + "Temperature: " + temperature; SparkBot.NotifyText(message); status = "Alert"; } else { message = "LSD: 66-27-75-05W4 \n" + "Temperature: " + temperature; } SparkBot.PostMessage(message); sensor.LSD = "66-27-75-05W4"; sensor.temperature = temperature.ToString(); sensor.status = status; DBAccess.InsertSensor(sensor); }
public void PostTropo([FromBody] Emergency emergency) { string message = emergency.result.transcription; string identifier = emergency.result.identifier; string[] result = identifier.Split(','); EmergencyCall call = new EmergencyCall(); call.transcription = message; call.identifier = result[0]; call.latitude = Convert.ToDecimal(result[1]); call.longitude = Convert.ToDecimal(result[2]); string mapsLink = "https://www.google.ca/maps?q=" + call.latitude + "," + call.longitude; SparkBot.NotifyText(message + "\n" + mapsLink); SparkBot.PostMessage("Emergency notification: " + message + "\n" + "Emergency location: " + mapsLink); DBAccess.InsertEmergencyCall(call); }