Class: BlackStack::MyBotProcess
- Inherits:
-
MyRemoteProcess
- Object
- MyProcess
- MyChildProcess
- MyRemoteProcess
- BlackStack::MyBotProcess
- Defined in:
- lib/mybotprocess.rb
Overview
clase de base para todos los bots ejecuten acciones con una cuenta de LinkedIn, Facebook, Twitter, etc.
Constant Summary
Constants inherited from MyProcess
BlackStack::MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS
Instance Attribute Summary collapse
-
#cookies_robot ⇒ Object
Returns the value of attribute cookies_robot.
-
#login_verifications ⇒ Object
Returns the value of attribute login_verifications.
-
#run_once ⇒ Object
Returns the value of attribute run_once.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from MyRemoteProcess
Attributes inherited from MyProcess
#assigned_division_changed, #assigned_process, #assigned_process_changed, #division_name, #email, #id, #id_client, #id_division, #logger, #minimum_enlapsed_seconds, #password, #verify_configuration, #worker_name, #ws_port, #ws_url
Instance Method Summary collapse
-
#getLnUser(workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
returns a hash with the parameters of a lnuser raises an exception if it could not get a lnuser, or if ocurrs any other problem.
-
#getLnUserByUsername(username) ⇒ Object
returns a hash with the parameters of a lnuser raises an exception if it could not get a lnuser, or if ocurrs any other problem.
-
#initialize(the_worker_name, the_division_name, the_minimum_enlapsed_seconds = MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS, the_verify_configuration = true, the_email = nil, the_password = nil) ⇒ MyBotProcess
constructor
constructor.
- #isLnUserAvailable(id_lnuser, need_sales_navigator = false, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
-
#notifyError(uid, description, oid = nil) ⇒ Object
Toma una captura del browser.
- #notifyInbox(lnuser, conv) ⇒ Object
- #notifyLnUserActivity(id_lnuser, code, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
- #notifyLnUserStatus(id_lnuser, status, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
- #notifyLnUserUrl(id_lnuser, profile_url) ⇒ Object
-
#releaseLnUser(id_lnuser, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
TODO: deprecated.
Methods inherited from MyRemoteProcess
Methods inherited from MyProcess
#canRun?, #division, #doSleep, fullWorkerName, #fullWorkerName, #get, #hello, kill, #list, macaddress, #notify, #pid, #ping, #process, #run, #set, #updateWorker, #whyCantRun, #worker
Constructor Details
#initialize(the_worker_name, the_division_name, the_minimum_enlapsed_seconds = MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS, the_verify_configuration = true, the_email = nil, the_password = nil) ⇒ MyBotProcess
constructor
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 |
# File 'lib/mybotprocess.rb', line 8 def initialize( the_worker_name, the_division_name, the_minimum_enlapsed_seconds=MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS, the_verify_configuration=true, the_email=nil, the_password=nil ) super(the_worker_name, the_division_name, the_minimum_enlapsed_seconds, the_verify_configuration, the_email, the_password) self.assigned_process = File.($0) self.worker_name = "#{the_worker_name}" self.division_name = the_division_name self.minimum_enlapsed_seconds = the_minimum_enlapsed_seconds # algunas clases como CreateLnUserProcess o RepairLnUserProcess, trabajan unicamente con el username especificado en este atributo, llamando al access point get_lnuser_by_username. # si este atributo es nil, entonces la clase pide un lnuser a la division, llamando al access point get_lnuser. self.username = nil # al correr un proceso sin supervision, el login require verificaciones automaticas que demoran tiempo (account blocingcaptcha, sms pin, bloqueo) # las verificaciones consument tiempo. # si este proceso se corre de forma supevisada, las verificaciones se pueden deshabilitar self.login_verifications = true # al correr sin supervision, el proceso de terminar un un paquete de procesamiento y comenzar con otro, funcionando en un loop infinito. # si este proceso se corre de forma supevisada, se desa correr el procesamiento una unica vez. # cuando se activa este flag, generalmente se setea el atributo self.username tambien. self.run_once = false # preguntar al servidor si el lnuser debe calentar el browser visitando sitios al azar para recolectar cookies self. = true end |
Instance Attribute Details
#cookies_robot ⇒ Object
Returns the value of attribute cookies_robot.
5 6 7 |
# File 'lib/mybotprocess.rb', line 5 def @cookies_robot end |
#login_verifications ⇒ Object
Returns the value of attribute login_verifications.
5 6 7 |
# File 'lib/mybotprocess.rb', line 5 def login_verifications @login_verifications end |
#run_once ⇒ Object
Returns the value of attribute run_once.
5 6 7 |
# File 'lib/mybotprocess.rb', line 5 def run_once @run_once end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/mybotprocess.rb', line 5 def username @username end |
Instance Method Details
#getLnUser(workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
returns a hash with the parameters of a lnuser raises an exception if it could not get a lnuser, or if ocurrs any other problem
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mybotprocess.rb', line 76 def getLnUser(workflow_name='incrawl.lnsearchvariation') nTries = 0 parsed = nil lnuser = nil # hash bSuccess = false sError = "" while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/get_lnuser.json" res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'name' => self.fullWorkerName}) parsed = JSON.parse(res.body) if (parsed['status']=='success') lnuser = parsed bSuccess = true else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception:" + e2.to_console end end # while if (bSuccess==false) raise BlackStack::Netting::ApiCallException.new(sError) end return lnuser end |
#getLnUserByUsername(username) ⇒ Object
returns a hash with the parameters of a lnuser raises an exception if it could not get a lnuser, or if ocurrs any other problem
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 |
# File 'lib/mybotprocess.rb', line 42 def getLnUserByUsername(username) nTries = 0 parsed = nil lnuser = nil # hash bSuccess = false sError = "" while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/login.lnuser/get_lnuser.json" res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'username' => username.encode("UTF-8")}) parsed = JSON.parse(res.body) if (parsed['status']=='success') lnuser = parsed bSuccess = true else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception: " + e2.to_console end end # while if (bSuccess==false) raise BlackStack::Netting::ApiCallException.new(sError) end return lnuser end |
#isLnUserAvailable(id_lnuser, need_sales_navigator = false, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/mybotprocess.rb', line 304 def isLnUserAvailable(id_lnuser, need_sales_navigator=false, workflow_name='incrawl.lnsearchvariation') nTries = 0 parsed = nil bSuccess = false sError = "" ret = false while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/is_lnuser_available.json" res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'id_lnuser' => id_lnuser, 'need_sales_navigator' => need_sales_navigator,} ) parsed = JSON.parse(res.body) if (parsed['status']=='success') bSuccess = true ret = parsed['value'] else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_s rescue => e2 sError = "Alghoritm Exception" + e2.to_s + '\r\n' + e2.backtrace.join("\r\n").to_s end end # while if (bSuccess==false) raise "#{sError}" end return ret end |
#notifyError(uid, description, oid = nil) ⇒ Object
Toma una captura del browser. Sube un registro a la tabla boterrorlog, con el id del worker, el proceso asinado, y el screenshot.
uid: id de un registro en la tabla lnuser. description: backtrace de la excepcion.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/mybotprocess.rb', line 249 def notifyError(uid, description, oid=nil) # tomo captura de pantalla file = nil =begin # TODO: habilitar esto cuando se migre a RestClient en vez de CallPost begin screenshot_filename = "./error.png" # TODO: colocar un nombre unico formado por por el fullname del worker, y la fecha-hora. BrowserFactory.screenshot screenshot_filename file = File.new(screenshot_filename, "rb") rescue => e puts "Screenshot Error: #{e.to_s}" file = nil end =end #puts "" #puts "id_worker:#{PROCESS.worker.id}" #puts "worker_name:#{PROCESS.fullWorkerName}" #puts "process:#{PROCESS.worker.assigned_process}" #puts "" # subo el error nTries = 0 bSuccess = false parsed = nil sError = "" while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/boterror.json" res = BlackStack::Netting::call_post(url, # TODO: migrar a RestClient para poder hacer file upload 'api_key' => BlackStack::Pampa::api_key, 'id_lnuser' => uid, 'id_object' => oid, 'worker_name' => PROCESS.fullWorkerName, 'process' => PROCESS.worker.assigned_process, 'description' => description, 'screenshot' => file, ) parsed = JSON.parse(res.body) if (parsed['status']=='success') bSuccess = true else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception:" + e2.to_console end end # while if (bSuccess==false) raise "#{sError}" end end |
#notifyInbox(lnuser, conv) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/mybotprocess.rb', line 109 def notifyInbox(lnuser, conv) conv[:chats].each { |chat| # armo URL de notificacion # se usa URI.encode para codificar caracteres no-ascii en los mensajes url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/scrape.inbox/notify_lnchat.json?" + "api_key=#{BlackStack::Pampa::api_key}&" + "profile_code=#{CGI.escape(conv[:profile_code])}&" + "profile_name=#{CGI.escape(conv[:profile_name])}&" + "profile_headline=#{CGI.escape(conv[:profile_headline])}&" + "first=#{CGI.escape(conv[:first])}&" + "position=#{chat[:position].to_s}&" + "uid=#{lnuser['id']}&" + "sender_name=#{CGI.escape(chat[:sender_name])}&" + "body=#{CGI.escape(chat[:body])}&" puts "" puts "url:#{url}:." puts "" # HELP: File.open('./output3.txt', 'a') { |file| file.write(url + "\r\n") } # push the chat uri = URI.parse(url.to_s) req = Net::HTTP::Get.new(uri.to_s) res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http| http.request(req) } parsed = JSON.parse(res.body) raise "error uploading chat: #{parsed['status']}" if parsed['status'] != 'success' } # conv[:chats].each end |
#notifyLnUserActivity(id_lnuser, code, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/mybotprocess.rb', line 210 def notifyLnUserActivity(id_lnuser, code, workflow_name='incrawl.lnsearchvariation') nTries = 0 parsed = nil bSuccess = false sError = "" while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/notify_lnuser_activity.json" res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'id_lnuser' => id_lnuser, 'code' => code,} ) parsed = JSON.parse(res.body) if (parsed['status']=='success') bSuccess = true else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception:" + e2.to_console end end # while if (bSuccess==false) raise "#{sError}" end end |
#notifyLnUserStatus(id_lnuser, status, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/mybotprocess.rb', line 175 def notifyLnUserStatus(id_lnuser, status, workflow_name='incrawl.lnsearchvariation') nTries = 0 parsed = nil bSuccess = false sError = "" while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/notify_lnuser_status.json" res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'id_lnuser' => id_lnuser, 'status' => status,} ) parsed = JSON.parse(res.body) if (parsed['status']=='success') bSuccess = true else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception:" + e2.to_console end end # while if (bSuccess==false) raise "#{sError}" end end |
#notifyLnUserUrl(id_lnuser, profile_url) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/mybotprocess.rb', line 141 def notifyLnUserUrl(id_lnuser, profile_url) nTries = 0 parsed = nil bSuccess = false sError = "" while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/login.lnuser/notify_url.json" res = BlackStack::Netting::call_post(url, {:api_key => BlackStack::Pampa::api_key, 'id_lnuser' => id_lnuser, 'url' => profile_url,} ) parsed = JSON.parse(res.body) if (parsed['status']=='success') bSuccess = true else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception:" + e2.to_console end end # while if (bSuccess==false) raise "#{sError}" end end |
#releaseLnUser(id_lnuser, workflow_name = 'incrawl.lnsearchvariation') ⇒ Object
TODO: deprecated
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/mybotprocess.rb', line 343 def releaseLnUser(id_lnuser, workflow_name='incrawl.lnsearchvariation') =begin nTries = 0 parsed = nil bSuccess = false sError = "" ret = false while (nTries < 5 && bSuccess == false) begin nTries = nTries + 1 url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/release_lnuser.json" res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'id_lnuser' => id_lnuser,} ) parsed = JSON.parse(res.body) if (parsed['status']=='success') bSuccess = true ret = parsed['value'] else sError = parsed['status'] end rescue Errno::ECONNREFUSED => e sError = "Errno::ECONNREFUSED:" + e.to_console rescue => e2 sError = "Exception:" + e2.to_console end end # while if (bSuccess==false) raise "#{sError}" end return ret =end end |