Created
December 26, 2015 00:00
-
-
Save Indy9000/5ab41349b0091d616430 to your computer and use it in GitHub Desktop.
Read Twitter Stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ReadStreamingResponse (w:WebRequest) = | |
try | |
let resp = w.GetResponse() :?> HttpWebResponse | |
use responseStream = resp.GetResponseStream() | |
use responseReader = new StreamReader(responseStream, true) | |
let atEnd = responseReader.EndOfStream | |
while(not atEnd) do | |
let line_size = responseReader.ReadLine() | |
if not (String.IsNullOrEmpty line_size) then | |
let size = int line_size | |
let buffer = Array.zeroCreate size | |
let numread = responseReader.ReadBlock(buffer,0,size) | |
let tweet = new System.String(buffer) |> System.Net.WebUtility.HtmlDecode |> TweetJSONType.Parse | |
let place = tweet.Place.ToString() |> PlaceJSONType.Parse | |
if not (tweet.Text.StartsWith("@")) then | |
printfn "%s(%s) - At %s-%s\n%s" | |
tweet.User.Name tweet.User.ScreenName | |
place.Name place.FullName tweet.Text | |
try | |
if tweet.Text.Contains("http://") || tweet.Text.Contains("https://") then | |
let shortUrl = ExtractUrl(tweet.Text) | |
ExtractImage shortUrl | |
else | |
printfn "..................................................................\n" | |
with | |
//| :? System.Net.WebException as ex1-> printfn "*****Error: %s\n\n" ex1.Message | |
| :? System.Net.WebException -> printfn "" | |
with | |
| :? WebException as ex -> printfn "Error %O" ex; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment