Skip to content

Commit 8bf1ff8

Browse files
author
Chris Rees
committed
Move Zapdos into Zeus temporarily
1 parent aa3873a commit 8bf1ff8

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

apps/the_eye/lib/the_eye.ex

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ defmodule TheEye do
1313
children = [
1414
worker(Task, [fn -> init_kernel_modules() end], restart: :transient, id: Nerves.Init.KernelModules),
1515
worker(Task, [fn -> init_network() end], restart: :transient, id: Nerves.Init.Network),
16-
worker(Task, [fn -> init_zapdos() end], restart: :transient),
1716
worker(Nerves.Neopixel, [neopixel_cfg, nil]),
1817
]
1918

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

34-
def init_zapdos() do
35-
IO.puts "Starting Zapdos"
36-
pid = spawn(fn -> Zapdos.get_tweets('#cmm_storm') end)
37-
IO.puts "Zapdos started: #{pid}"
38-
end
3933
end

apps/zeus/lib/zeus.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule Zeus do
1010
children = [
1111
# Start the endpoint when the application starts
1212
supervisor(Zeus.Endpoint, []),
13+
worker(Task, [fn -> Zapdos.get_tweets('#cmm_storm') end], restart: :transient),
1314
# Start your own worker by calling: Zeus.Worker.start_link(arg1, arg2, arg3)
1415
# worker(Zeus.Worker, [arg1, arg2, arg3]),
1516
]

apps/zeus/lib/zeus/zapdos.ex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule Zapdos do
2+
alias Lightning.ColorParsing
3+
4+
@moduledoc """
5+
Documentation for Zapdos.
6+
"""
7+
8+
def get_tweets(query) do
9+
ExTwitter.stream_filter(track: query)
10+
|> Stream.map(fn(tweet) -> tweet.text end)
11+
|> Stream.map(&(update_color(&1)))
12+
|> Enum.to_list
13+
end
14+
15+
defp update_color(text) do
16+
ColorParsing.get_color(text)
17+
|> ColorParsing.parse_rgb_hex
18+
|> Lightning.Control.change_color(150)
19+
end
20+
21+
end
22+

apps/zeus/mix.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule Zeus.Mixfile do
2222
# Type `mix help compile.app` for more information.
2323
def application do
2424
[mod: {Zeus, []},
25-
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext]]
25+
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, :extwitter]]
2626
end
2727

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

4546
def aliases do

0 commit comments

Comments
 (0)