page counter - thx for everyones help
Wes James
comptekki@REDACTED
Fri Apr 30 21:17:51 CEST 2010
Here is the code so far:
-module('gpc').
-export([start/0, start/1, getc/0]).
start() ->
ibrowse:start(),
timer:apply_interval(3000, gpc, getc, []).
start(Interval) ->
ibrowse:start(),
timer:apply_interval(Interval*1000, gpc, getc, []).
getc() ->
S = string:substr(
binary_to_list(
lists:nth(
424,
re:replace(
erlang:element(
4,
ibrowse:send_req("http://192.168.1.1/printer/configu.html?autoref=0&weblang=0",
[], get)
),
"\\n",
"",
[global]
)
)
),
34),
S2=list_to_integer(string:substr(S, 1, string:len(S)-10)),
io:format("~w~n", [S2]).
So this by default gives me a page count every 3 seconds or I can put
in gpc:start(10) for 10 second intervals.
What I would like to do is take daily page counts and stick them some
where. I could make a file on the system with the date as the name
(20100430.txt) and just write the value there or I could write the
value to mnesia and keep track via the data base. I would be doing a
current count - yesterday count to get a total count for just each
day. I'm doing this so I can keep track of what the students in a
university computer lab are printing each day.
If you have any suggestions, please drop them in this list :)
I'll be experimenting anyway since I've yet to read or write to a file
with erlang on a disc or gone beyond just reading what mnesia can do
via web page info.
thx,
-wes
More information about the erlang-questions
mailing list