Skip to content

Instantly share code, notes, and snippets.

@Indy9000
Created December 26, 2015 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Indy9000/5ab41349b0091d616430 to your computer and use it in GitHub Desktop.
Save Indy9000/5ab41349b0091d616430 to your computer and use it in GitHub Desktop.
Read Twitter Stream
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