Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (49 sloc) 2.26 KB
{-# LANGUAGE OverloadedStrings #-}
module Y2016.M11.D08.Solution where
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Maybe (fromJust)
-- below import available from cabal (aeson)
import Data.Aeson
So, last week we looked at a graph of twitter-users. NOICE! If you look at the
source code that generated the graph, it's a python script that makes a
request to the twitter API to get a list of the followers of the graphed
Well. I happen to have a twitter API account and twitter application. Why don't
I just access these data myself and then we can work on the raw twitter (JSON)
data themselves.
So, today's Haskell exercise. In this directory, or at the URL:
is a gzipped list of twitter ids that follow 1HaskellADay as JSON.
I was able to get this JSON data with the following REST GET query:
via my (o)authenticated twitter application.
Read in the JSON (after gunzipping it) and answer the below questions
type TwitterId = Integer
data Tweeps = TIds { tweeps :: [TwitterId] } deriving Show
instance FromJSON Tweeps where
parseJSON (Object o) = TIds <$> o .: "ids"
followers :: FilePath -> IO Tweeps
followers = fmap (fromJust . decode) . BL.readFile
1. How many followers does 1HaskellADay have?
*Y2016.M11.D08.Solution> let had = it
*Y2016.M11.D08.Solution> length (tweeps had) ~> 2118
2. What is the max TwitterID? Is it an Int-value? (ooh, tricky)
*Y2016.M11.D08.Solution> maximum (tweeps had) ~> 794184637249626112
3. What is the min TwitterID?
*Y2016.M11.D08.Solution> minimum (tweeps had) ~> 150
Don't answer this:
4. Trick question: what is 1HaskellADay's twitter ID?
We'll be looking at how to get screen_name from twitter id and twitter id from
screen_name throughout this week, as well as looking at social networks of
followers who follow follwers who ...
How shall we do that? The Twitter API allows summary queries, as the JSON
examined here, as well as in-depth queries, given a screen_name (from which you
can obtain the twitter ID) or a twitter id (from which you can obtain the
screen_name) and followers, as you saw in today's query.
You can’t perform that action at this time.