Skip to content

Commit 98c8ce9

Browse files
committed
Add loop proxy
1 parent 023c8f7 commit 98c8ce9

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

.env_sample

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export INS_SESSION_ID_GAME="11658585665%3AiJeECzOuOucZmy%3A6"
55
export INS_SESSION_ID_FOOD="11470214398%3AmnKVpyIylVSm3E%3A23"
66
export INS_SESSION_ID_HOT="11658769798%3AKI5EpFWvayXPOP%3A12"
77
export INS_SESSION_ID_OTHER=11658769798%3AKI5EpFWvayXPOP%3A12,11470214398%3AmnKVpyIylVSm3E%3A23
8-
export INS_NOT_LOGIN=0
9-
export INS_GOOGLE_QPS=1
8+
export INS_NOT_LOGIN=1
9+
export INS_GOOGLE_QPS=3
10+
export PROXYS=143.191.230.202:3199,181.214.193.243:3199,168.80.71.40:3199,168.81.103.84:3199,45.43.128.22:3199,196.18.178.96:3199,108.59.14.203:13010,168.80.228.90:3199,168.80.183.191:3199,168.81.230.87:3199,104.233.48.27:3199,108.59.14.203:13010,168.81.246.228:3199,168.80.38.95:3199,196.19.191.80:3199,168.81.38.77:3199,168.81.53.38:3199,108.59.14.203:13010,168.81.100.127:3199,168.80.70.119:3199,196.18.178.13:3199,196.16.95.164:3199,104.239.119.248:3199,168.80.149.204:3199,168.81.151.22:3199,108.59.14.203:13010,181.177.75.245:3199,168.81.71.41:3199,143.191.229.6:3199,168.81.215.148:3199,196.17.123.237:3199,143.191.233.76:3199,108.59.14.203:13010,168.81.20.102:3199,154.16.129.229:3199,168.81.5.181:3199,196.16.249.224:3199,181.215.62.114:3199,196.18.150.79:3199,168.80.37.135:3199,108.59.14.203:13010,196.16.222.77:3199,168.81.20.153:3199,196.18.252.131:3199,108.59.14.203:13010,191.96.198.229:3199,168.81.133.180:3199,181.214.194.129:3199,108.59.14.203:13010,186.179.25.143:3199,168.81.166.221:3199,181.214.197.230:3199,168.81.53.146:3199,67.227.120.64:3199,108.59.14.203:13010,168.80.36.92:3199,168.80.7.28:3199,168.81.198.177:3199,168.80.23.74:3199,108.59.14.203:13010

lib/instaghub/application.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ defmodule Instaghub.Application do
3535
Instaghub.Bucket.Schedule,
3636
:poolboy.child_spec(:ins_api_pool, poolboy_config_ins()),
3737
:poolboy.child_spec(:redis_pool, poolboy_config_redis()),
38-
Instaghub.INS.Schedule
38+
Instaghub.INS.Schedule,
39+
Instaghub.Proxy
3940
]
4041

4142
# See https://hexdocs.pm/elixir/Supervisor.html

lib/instaghub/kv.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Instaghub.Bucket do
3535

3636
def reset_req(key) do
3737
req = get(key)
38-
Logger.debug "reset #{key} with 0, before is #{req}"
38+
# Logger.debug "reset #{key} with 0, before is #{req}"
3939
put(key, 0)
4040
end
4141

lib/instaghub/proxy.ex

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
defmodule Instaghub.Proxy do
2+
use GenServer
3+
require Logger
4+
5+
@name :proxy
6+
7+
def start_link(_opts) do
8+
GenServer.start_link(__MODULE__, 0, name: @name)
9+
end
10+
11+
def get() do
12+
GenServer.call(@name, :get)
13+
end
14+
15+
def init(args) do
16+
{:ok, args}
17+
end
18+
19+
def handle_call(:get, _from, index) do
20+
proxies = if System.get_env("PROXYS") != nil do
21+
System.get_env("PROXYS") |> String.split(",")
22+
else
23+
nil
24+
end
25+
if proxies != nil do
26+
len = length(proxies)
27+
index = rem(index, len)
28+
{:reply, proxies |> Enum.at(index), index+1}
29+
else
30+
{:reply, nil, 0}
31+
end
32+
end
33+
34+
end

lib/instagram/ins_web_api.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule Ins.Web.API do
22
require Logger
33
alias Instaghub.RedisUtil
4+
alias Instaghub.Proxy
45

56
@base_url "https://www.instagram.com"
67
@graphql_url_part "/graphql/query/"
@@ -166,7 +167,7 @@ defmodule Ins.Web.API do
166167

167168
defp get(url_part, params) do
168169
headers = generate_header(params)
169-
proxy_option = get_random_proxy()
170+
proxy_option = get_loop_proxy()
170171
proxy = if proxy_option != nil do
171172
Logger.info "use proxy #{proxy_option}"
172173
# disable hackney connect pool for using rotate proxy IP
@@ -189,6 +190,10 @@ defmodule Ins.Web.API do
189190
|> handle_response
190191
end
191192

193+
defp get_loop_proxy() do
194+
Proxy.get()
195+
end
196+
192197
defp get_random_proxy() do
193198
proxys = System.get_env("PROXYS")
194199
if proxys != nil do

0 commit comments

Comments
 (0)