make it more elxir-y #5
parent
224851ad39
commit
28c6c12a32
|
@ -1,19 +1,29 @@
|
||||||
defmodule Mix.Tasks.SystemBooster.Cron do
|
defmodule Mix.Tasks.SystemBooster.Cron do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
|
||||||
def run(args) do
|
def run(args) do
|
||||||
Application.ensure_all_started(:hackney)
|
Application.ensure_all_started(:hackney)
|
||||||
app = Application.get_env(:systembooster, :app)
|
app = Application.get_env(:systembooster, :app)
|
||||||
oauth = Application.get_env(:systembooster, :oauth)
|
oauth = Application.get_env(:systembooster, :oauth)
|
||||||
conn = Hunter.new([base_url: app[:base_url], bearer_token: oauth[:token]])
|
conn = Hunter.new(base_url: app[:base_url], bearer_token: oauth[:token])
|
||||||
Hunter.Api.HTTPClient.list_timeline(conn, Application.get_env(:systembooster, :list)[:list_id], [])
|
|
||||||
|> Enum.filter(fn (x) -> x.reblogged == false and (x.visibility == "public" or x.visibility == "unlisted") end)
|
conn
|
||||||
|> Enum.reverse
|
|> Hunter.Api.HTTPClient.list_timeline(
|
||||||
|
Application.get_env(:systembooster, :list)[:list_id],
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|> Enum.filter(fn x ->
|
||||||
|
x.reblogged == false and x.visibility in ["public", "unlisted"]
|
||||||
|
end)
|
||||||
|
|> Enum.reverse()
|
||||||
|> Enum.map(fn x -> Hunter.reblog(conn, x.id) end)
|
|> Enum.map(fn x -> Hunter.reblog(conn, x.id) end)
|
||||||
|> IO.inspect
|
|> case do
|
||||||
|
[] -> "Up to date"
|
||||||
|
x -> x |> Enum.count() |> (fn x -> "updated #{x} statuses" end).()
|
||||||
|
end
|
||||||
|
|> IO.puts()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# realapp = %Hunter.Application{client_id: app[:client_id], client_secret: app[:client_secret], id: app[:app_id]}
|
# realapp = %Hunter.Application{client_id: app[:client_id], client_secret: app[:client_secret], id: app[:app_id]}
|
||||||
#Enum.map(Enum.reverse(Enum.sort_by(Enum.filter(list, fn (x) -> x.reblogged == false and (x.visibility == "public" or x.visibility == "unlisted") end),fn x -> x.id end)), fn x -> Hunter.reblog(conn, x.id) end)
|
# Enum.map(Enum.reverse(Enum.sort_by(Enum.filter(list, fn (x) -> x.reblogged == false and (x.visibility == "public" or x.visibility == "unlisted") end),fn x -> x.id end)), fn x -> Hunter.reblog(conn, x.id) end)
|
||||||
|
|
Loading…
Reference in New Issue