-
Notifications
You must be signed in to change notification settings - Fork 1
/
traffic.rb
executable file
·93 lines (76 loc) · 2.46 KB
/
traffic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env ruby
require 'adefy'
def timestamp
Time.now.strftime("[%d/%m/%Y %H:%M:%S]")
end
@log = File.open("traffik.log", "a")
@log.sync = true
@admin_agent = Adefy::Agent.new host: "http://www.adefy.dev/",
apikey: "Nkv9tU54M9LLw9pSC8zIM8IB"
## admin
@admin_agent.users.login username: "admin", password: "sachercake"
@pubs = @admin_agent.publishers.all
## create a visitor agent
@agent_u = Adefy::Agent.new host: "http://www.adefy.dev/"
## Use the admin agent for requests as well, I have no idea what will happen...
#@agent_u = @admin_agent
i = 0
loader = '|/-\\'
line_clear = "\r" + (" " * 80) + "\r"
lyrics = %w[
they see me
trafficing ads
they hope that they gonna catch me as an airpush spy
trying catch me as an airpush spy
trying catch me as an airpush spy
trying catch me as an airpush spy
they trying
they trying
]
click_stack = []
impressions_stack = []
Thread.abort_on_exception = true
def stack_thread(label, arra)
Thread.new do
loop do
begin
if lnk = arra.shift
@log.puts "#{timestamp} #{label} GET link #{lnk.inspect}"
resp = Excon.get(lnk)
@log.puts "#{timestamp} #{label} GET link #{lnk.inspect} [#{resp.status}]"
end
sleep 1.0
rescue Excon::Errors::BadGateway
@log.puts "#{timestamp} #{label} [WARN] Server appears to be down, waiting a few seconds"
sleep 3.0
# catch any other exception
rescue Exception => ex
@log.puts "#{timestamp} #{label} [ERROR] #{ex.inspect}\n#{ex.backtrace.join("\n")}"
# and raise that mofo after we've logged it
raise ex
end
end
end
end
@click_thread = stack_thread("Click", click_stack)
@impressions_thread = stack_thread("Impression", impressions_stack)
@log.puts "#{timestamp} Started Traffic Generator"
loop do
print line_clear
pub = @pubs.sample
begin
hsh = @agent_u.serve.serve(apikey: pub["apikey"])
imprs = hsh["impression"]
click = hsh["click"]
impressions_stack << imprs if imprs && rand < 0.7
click_stack << click if click && rand < 0.5
rescue Excon::Errors::BadGateway
@log.puts "#{timestamp} Server appears to be down, waiting a few seconds"
sleep 3.0
rescue Excon::Errors::NotFound
sleep 0.02
end
print "CLICK[#{"%03s" % click_stack.size}] IMPRESSION[#{"%03s" % impressions_stack.size}] Generating Traffic Like a Baws #{loader[i % loader.size]} : #{lyrics[(i / 5) % lyrics.size]}"
i += 1
sleep 0.20
end