anchor.diff:  -record(state, {
             id,
             get_url,
  -          bus_location_list=[]
  +          bus_location_list=[],
  +          created_at,
  +          updated_at,
  +          last_error
            }).
   
   -define(FIRST_INTERVAL, 1000). % TODO: random interval
  -%-define(INTERVAL, 30000). % 30 * 1000
  +%-define(INTERVAL, 30000). % 10 * 1000
   -define(INTERVAL, 60000). % 1 * 60 * 1000
  +-define(TIME_DIFF_RETIRE, 86400000). % 86400 * 1000 * 1000
   -define(URL, "http://api.pubtrans.map.naver.com/2.1/live/getBusLocation.jsonp?caller=pc_map&routeId=").
   %-define(URL, "http://localhost").
   
  
positive.code:     LBusId = binary_to_list(BusId),
      GetUrl = list_to_binary( ?URL ++ LBusId ),
      erlang:send_after(?FIRST_INTERVAL, self(), check),
      {ok, #state{id=BusId, get_url=GetUrl}}.
  
  handle_call(_Request, _From, State) ->
      {reply, ignored, State}.
  
negative.code:             {OldListUpdated, [NewData | NewList]}
          end, {OldBusLocationList, []}, BusLocationList),
  
      case Obsoletes of
          [] -> ok;
          _ ->
              lists:foreach(
                  fun({PlateNo, [{_, LastUpdateDate}|_] = History}) ->
                      % File name format: {BusId}/{Year}/{Month}{Day}.txt
                      {Year, Month, Day, _, _, _} = split_update_date(LastUpdateDate),
                      Path = ["data", binary_to_list(BusId), Year, Month],
                      mkdir_p(Path, []),
                      FileName = string:join(Path, "/") ++ "/" ++ Day ++ ".txt",
                      {ok, IoDevice} = file:open(FileName, [append, {encoding, utf8}]),
                      io:format(IoDevice, "{ \"~ts\" : [~ts]},~n", [PlateNo, io_format_history(History)]),
                      ok = file:close(IoDevice)
                  end, Obsoletes)
      end,
  
      State#state{ bus_location_list=NewBusLocationList, updated_at=os:timestamp()}.
  
  io_format_history(History) ->
      io_format_history(History, []).
  
  io_format_history([], Result) ->
      Result;
  io_format_history([{Location, UpdateDate}|Tail], Result) ->
      io_format_history(Tail, [[<<"{\"">>, integer_to_list(Location), <<"\":">> , <<"\"">>, UpdateDate, <<"\"},">> ] | Result]).
  
  % 20140818003817 -> {"2014", "08", "18", "00", "38", "17"}
  split_update_date(DateStr) ->
      Year = (binary_to_list(binary:part(DateStr, 0, 4))),
      Month = (binary_to_list(binary:part(DateStr, 4, 2))),
      Day = (binary_to_list(binary:part(DateStr, 6, 2))),
      Hour = (binary_to_list(binary:part(DateStr, 8, 2))),
      Minute = (binary_to_list(binary:part(DateStr, 10, 2))),
      Second = (binary_to_list(binary:part(DateStr, 12, 2))),
  
      {Year, Month, Day, Hour, Minute, Second}.
  
  mkdir_p([], _) -> ok;
  mkdir_p([H|T], []) ->
      file:make_dir(H),
      mkdir_p(T, H);
  mkdir_p([H|T], Parents) ->
      Path = Parents ++ "/" ++ H,
      file:make_dir(Path),
      mkdir_p(T, Path).
  
  