Polling a web server for latest updates

Some websites change dramatically very often. For instance, Google News and Reddit are usually loaded with recent postings the moment we refresh the page. To maintain the latest data at all times, it might be best to run an HTTP request often.

In this recipe, we poll new Reddit posts every 10 seconds as summarized in the following diagram:

Polling a web server for latest updates

How to do it…

In a new file called Main.hs, perform the following steps:

  1. Import the relevant libraries:
    import Network.HTTP
    import Control.Concurrent (threadDelay)
    import qualified Data.Text as T
  2. Define the URL to poll:
    url = "http://www.reddit.com/r/pics/new.json"
  3. Define the function ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.