|
|
@ -13,32 +13,43 @@ defmodule TirInnaNoc.Meldh do |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def handle_info(:update, state) do |
|
|
|
def handle_info(:update, state) do |
|
|
|
|
|
|
|
IO.puts("upd8ing "<>state.board) |
|
|
|
{:ok, res} = TirInnaNoc.Imageboard.threads(state.board) |
|
|
|
{:ok, res} = TirInnaNoc.Imageboard.threads(state.board) |
|
|
|
res.body |
|
|
|
res.body |
|
|
|
|> Enum.each(fn page -> |
|
|
|
|> Enum.each(fn page -> |
|
|
|
Enum.each(page["threads"], fn thread -> |
|
|
|
Enum.each(page["threads"], fn thread -> |
|
|
|
DynamicSupervisor.start_child( |
|
|
|
if state.threads[thread["no"]] == nil do |
|
|
|
String.to_atom(state.board<>"Supervisor"), |
|
|
|
DynamicSupervisor.start_child( |
|
|
|
{ |
|
|
|
String.to_atom(state.board<>"Supervisor"), |
|
|
|
TirInnaNoc.Perenelle, |
|
|
|
{ |
|
|
|
%TirInnaNoc.Imageboard.Thread{ |
|
|
|
TirInnaNoc.Perenelle, |
|
|
|
board: state.board, |
|
|
|
%TirInnaNoc.Imageboard.Thread{ |
|
|
|
no: thread["no"], |
|
|
|
board: state.board, |
|
|
|
last_update: thread["last_modified"], |
|
|
|
no: thread["no"], |
|
|
|
reply_number: thread["replies"], |
|
|
|
last_update: thread["last_modified"], |
|
|
|
on_page: page["page"] |
|
|
|
reply_number: thread["replies"], |
|
|
|
|
|
|
|
on_page: page["page"] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
else |
|
|
|
|
|
|
|
send(String.to_atom(state.board<>to_string(thread["no"])<>"Perenelle"), {:update, page["page"], thread["replies"], false}) |
|
|
|
|
|
|
|
end |
|
|
|
end) |
|
|
|
end) |
|
|
|
end) |
|
|
|
end) |
|
|
|
{:noreply, state} |
|
|
|
{:noreply, state} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def go_forever(proc) do |
|
|
|
|
|
|
|
send(proc, :update) |
|
|
|
|
|
|
|
Process.sleep(60_000) |
|
|
|
|
|
|
|
go_forever(proc) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def init(state) do |
|
|
|
def init(state) do |
|
|
|
IO.puts("started meldh to archive board "<>state.board) |
|
|
|
IO.puts("started meldh to archive board "<>state.board) |
|
|
|
send(self(), :update) |
|
|
|
Task.start_link(fn -> go_forever(String.to_atom(state.board<>"Meldh")) end) |
|
|
|
{:ok, state} |
|
|
|
{:ok, state} |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|