generated from ohyecloudy/template-elixir
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- twitter account 정보로 TwitterProcess 프로세스를 만드는 사전 작업 - 필요한 정보를 읽을 뿐 프로세스를 생성하지는 않는다 - runtime.exs - 환경 변수에서 설정을 읽어서 :tbot800, :tbot_accounts 설정 - dev.secret.exs - 개발 중에는 바로 :tbot800, :tbot_accounts 설정 - 버전 컨트롤에서 파일 제외
- Loading branch information
1 parent
f28b925
commit 0aaac28
Showing
10 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ tbot_800-*.tar | |
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
dev.secret.exs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Tbot800.Application do | ||
use Application | ||
|
||
def start(_type, _args) do | ||
children = [ | ||
Tbot800.DefaultImpl | ||
] | ||
|
||
opts = [strategy: :one_for_one, name: Tbot800.Supervisor] | ||
Supervisor.start_link(children, opts) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Tbot800.DefaultImpl.Supervisor do | ||
use Supervisor | ||
require Logger | ||
|
||
def start_link(init_args) do | ||
Supervisor.start_link(__MODULE__, init_args, name: __MODULE__) | ||
end | ||
|
||
def init(_init_args) do | ||
tbot_accounts = | ||
case Application.fetch_env(:tbot800, :tbot_accounts) do | ||
{:ok, value} -> value | ||
:error -> raise "twitter account settings do not exist. see config/runtime.exs" | ||
end | ||
|
||
Logger.info("########################################") | ||
|
||
tbot_accounts | ||
|> Enum.each(fn account -> Logger.info("tweet items path: #{account[:tweet_items_path]}") end) | ||
|
||
Logger.info("########################################") | ||
|
||
children = [] | ||
Supervisor.init(children, strategy: :one_for_one) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Config | ||
|
||
if File.exists?("config/dev.secret.exs") do | ||
import_config "dev.secret.exs" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Config | ||
|
||
# 환경 변수로 설정한 계정 정보를 elixir config로 변환한다. | ||
# 설정해야 할 환경 변수가 비어있으면 그 후 읽기를 중단한다. | ||
# 예를 들어 ACCOUNT1_ 설정이 다 되어 있어야지 ACCOUNT2_ 설정 읽기를 시도한다. | ||
|
||
accounts = | ||
Stream.iterate(1, &(&1 + 1)) | ||
|> Stream.map(fn index -> | ||
[ | ||
consumer_key: System.get_env("ACCOUNT#{index}_KEY"), | ||
consumer_secret: System.get_env("ACCOUNT#{index}_SECRET"), | ||
access_token: System.get_env("ACCOUNT#{index}_TOKEN"), | ||
access_token_secret: System.get_env("ACCOUNT#{index}_TOKEN_SECRET"), | ||
interval: | ||
String.to_integer(System.get_env("ACCOUNT#{index}_INTERVAL_MINUTE", "60")) * 1000 * 60, | ||
tweet_items_path: System.get_env("ACCOUNT#{index}_TWEET_ITEMS_PATH") | ||
] | ||
end) | ||
|> Enum.take_while(fn account -> | ||
Enum.all?(Keyword.values(account), &(!is_nil(&1))) | ||
end) | ||
|
||
if accounts != [] do | ||
config :tbot800, tbot_accounts: accounts | ||
end | ||
|
||
# 개발 편의가 필요할 때는 dev.secret.exs 같은 파일에 아래와 같은 설정을 넣어서 실행한다 | ||
# config :tbot800, | ||
# tbot_accounts: [ | ||
# [ | ||
# consumer_key: "consumer_key", | ||
# consumer_secret: "consumer_secret", | ||
# access_token: "access_token", | ||
# access_token_secret: "access_token_secret", | ||
# interval: 1000 * 60 * 60, | ||
# tweet_items_path: "pqoutes.exs" | ||
# ], | ||
# [ | ||
# consumer_key: "consumer_key", | ||
# consumer_secret: "consumer_secret", | ||
# access_token: "access_token", | ||
# access_token_secret: "access_token_secret", | ||
# interval: 1000 * 60 * 60, | ||
# tweet_items_path: "book_quotes.exs" | ||
# ] | ||
# ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import Config |