Skip to content

Commit

Permalink
Move Zapdos into Zeus temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rees committed Feb 28, 2017
1 parent aa3873a commit 8bf1ff8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
6 changes: 0 additions & 6 deletions apps/the_eye/lib/the_eye.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ defmodule TheEye do
children = [
worker(Task, [fn -> init_kernel_modules() end], restart: :transient, id: Nerves.Init.KernelModules),
worker(Task, [fn -> init_network() end], restart: :transient, id: Nerves.Init.Network),
worker(Task, [fn -> init_zapdos() end], restart: :transient),
worker(Nerves.Neopixel, [neopixel_cfg, nil]),
]

Expand All @@ -31,9 +30,4 @@ defmodule TheEye do
Nerves.InterimWiFi.setup(@interface, @wifi_cfg)
end

def init_zapdos() do
IO.puts "Starting Zapdos"
pid = spawn(fn -> Zapdos.get_tweets('#cmm_storm') end)
IO.puts "Zapdos started: #{pid}"
end
end
1 change: 1 addition & 0 deletions apps/zeus/lib/zeus.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Zeus do
children = [
# Start the endpoint when the application starts
supervisor(Zeus.Endpoint, []),
worker(Task, [fn -> Zapdos.get_tweets('#cmm_storm') end], restart: :transient),
# Start your own worker by calling: Zeus.Worker.start_link(arg1, arg2, arg3)
# worker(Zeus.Worker, [arg1, arg2, arg3]),
]
Expand Down
22 changes: 22 additions & 0 deletions apps/zeus/lib/zeus/zapdos.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Zapdos do
alias Lightning.ColorParsing

@moduledoc """
Documentation for Zapdos.
"""

def get_tweets(query) do
ExTwitter.stream_filter(track: query)
|> Stream.map(fn(tweet) -> tweet.text end)
|> Stream.map(&(update_color(&1)))
|> Enum.to_list
end

defp update_color(text) do
ColorParsing.get_color(text)
|> ColorParsing.parse_rgb_hex
|> Lightning.Control.change_color(150)
end

end

5 changes: 3 additions & 2 deletions apps/zeus/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Zeus.Mixfile do
# Type `mix help compile.app` for more information.
def application do
[mod: {Zeus, []},
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext]]
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, :extwitter]]
end

# Specifies which paths to compile per environment.
Expand All @@ -39,7 +39,8 @@ defmodule Zeus.Mixfile do
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:lightning, in_umbrella: true}]
{:lightning, in_umbrella: true},
{:extwitter, "~> 0.8"}]
end

def aliases do
Expand Down

0 comments on commit 8bf1ff8

Please sign in to comment.