PageRenderTime 61ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/app/models/sor_search_log.rb

https://github.com/mobileAgent/gsports
Ruby | 1193 lines | 886 code | 58 blank | 249 comment | 130 complexity | 8f6cff375b19fad4928f5a5b4b25f74b MD5 | raw file
Possible License(s): MIT
  1. #require 'rubygems'
  2. require 'mechanize'
  3. require 'logger'
  4. class SorSearchLog < ActiveRecord::Base
  5. def self.do_search
  6. users1 = User.find(:all, :conditions => "enabled = true and created_at > '#{1.days.ago}'")
  7. users2 = self.find_memberships_to_bill_next_day
  8. users =(users1 +users2).uniq
  9. SorSearchLog.delete_all
  10. if users.size >0
  11. agent = WWW::Mechanize.new
  12. for user in users
  13. self.search_user_with_sor(user, agent)
  14. end
  15. end
  16. end
  17. def self.search_user_with_sor(user,agent)
  18. if user.state_id
  19. SorSearchLog.send("search_user_state_#{user.state_id}".to_sym, user, agent)
  20. end
  21. end
  22. # id = 1 state AL (Alabama)
  23. # Search field: (LastName) ctl00$BodyArea1$UcSexOffender1$txtLastName --> used http://www.familywatchdog.us/search.asp
  24. def self.search_user_state_1(user,agent)
  25. self.search_user_in_family_watchdog(user,agent)
  26. end
  27. # id =2 state = AK (Alaska)
  28. # search field: LastName, FirstName
  29. # more field: SearchForm$City , SearchForm$ZipCodes
  30. # accept : N/A
  31. # link result : yes
  32. def self.search_user_state_2(user,agent)
  33. page = agent.get("http://www.dps.state.ak.us/Sorweb/Search.aspx")
  34. search_form = page.forms.with.name("SearchFormControl").first
  35. search_form.FirstName =user.firstname
  36. search_form.LastName =user.lastname
  37. if user.city?
  38. search_form.field("SearchForm$City").value =user.city
  39. end
  40. if user.zip?
  41. search_form.field("SearchForm$ZipCodes").value =user.zip
  42. end
  43. search_result = agent.submit(search_form)
  44. if search_result.links.size >16
  45. result = SorSearchLog.new
  46. result.lastname = user.lastname
  47. result.firstname = user.firstname
  48. result.user_id =user.id
  49. result.state_name = 'AK'
  50. result.link ="http://www.dps.state.ak.us/Sorweb/list.aspx?Preview=FALSE&PgNum=1&SEARCH_TYPE=search&FirstName=#{user.firstname}&LastName=#{user.lastname}&AddressType=&StreetName=&SearchForm%24ZipCodes=#{user.zip}&SearchForm%24City=#{user.city}&ExecuteQry=Submit+Query"
  51. result.html_content =search_result.body
  52. result.save
  53. end
  54. end
  55. # id = 3 state = AZ (Arizona)
  56. # Search field: lastName
  57. # more field: multi form
  58. # accept : N/A
  59. # link result : N/A
  60. # soundex --> used http://www.familywatchdog.us/search.asp
  61. def self.search_user_state_3(user,agent)
  62. self.search_user_in_family_watchdog(user,agent)
  63. end
  64. # id = 4 state = AR (arkansas)
  65. # Search field: name
  66. # more field: city, county, state
  67. #http://www.acic.org/soff/index.php
  68. # search use Soundex
  69. def self.search_user_state_4(user,agent)
  70. self.search_user_in_family_watchdog(user,agent)
  71. page = agent.get("http://www.acic.org/soff/index.php")
  72. accept_form = page.forms.first
  73. unless accept_form.buttons.with.value("I Agree").nil?
  74. button=accept_form.buttons.with.value("I Agree")
  75. page = accept_form.click_button(button)
  76. end
  77. search_form = page.forms.first
  78. search_form.field("name").value =user.firstname + ', ' + user.lastname
  79. if user.zip?
  80. search_form.zip =user.zip
  81. end
  82. if user.city?
  83. search_form.city =user.city
  84. end
  85. # if user.county?
  86. # search_form.county =user.county
  87. # end
  88. button=search_form.buttons.with.value("Search")
  89. search_result = search_form.click_button(button)
  90. if search_result.links.size >13
  91. result = SorSearchLog.new
  92. result.lastname = user.lastname
  93. result.firstname = user.firstname
  94. result.user_id =user.id
  95. result.state_name = 'AR'
  96. result.link =""
  97. result.html_content =search_result.body
  98. result.save
  99. end
  100. end
  101. # id = 5 state = CA (California)
  102. # Search field: LastName, FirstName
  103. # more form: multi form
  104. # accept : yes
  105. # link result : yes
  106. #http://meganslaw.ca.gov/disclaimer.htm
  107. def self.search_user_state_5(user,agent)
  108. page = agent.get("http://meganslaw.ca.gov/disclaimer.htm")
  109. accept_form = page.forms.first
  110. unless accept_form.buttons.with.value("Continue").nil?
  111. accept_form.checkboxes.first.checked =true
  112. button=accept_form.buttons.with.value("Continue")
  113. page = accept_form.click_button(button)
  114. link = page.links.text('Name Search')
  115. page = agent.click(link)
  116. end
  117. search_form = page.forms.first
  118. search_form.lastName =user.lastname
  119. search_form.firstName =user.firstname
  120. search_result = agent.submit(search_form)
  121. if search_result.links.size >9
  122. result = SorSearchLog.new
  123. result.lastname = user.lastname
  124. result.firstname = user.firstname
  125. result.user_id =user.id
  126. result.state_name = 'CA'
  127. result.link ="http://meganslaw.ca.gov/cgi/prosoma.dll?lastName=#{user.lastname}&firstName=#{user.firstname}&Address=&City=&zipcode=&City2=&zipcode2=&ParkName=&City3=&zipcode3=&schoolName=&City4=&zipcode4=&pan=&distacross=107211&centerlat=38409907&centerlon=-121514242&starlat=&starlon=&startext=&x1=&y1=&x2=&y2=&mapwidth=525&mapheight=400&zoom=&searchBy=name&id=&docountycitylist=0&OFDTYPE=&searchDistance=.75&countyLocation=&SelectCounty=&searchDistance2=.75&countyLocation3=&searchDistance3=.75&countyLocation4=&refineID=---------------------------&zoomAction=Box"
  128. result.html_content =search_result.body
  129. result.save
  130. end
  131. end
  132. # id = 6 state = CO (Colorado)
  133. # can't use auto browser --> used http://www.familywatchdog.us/search.asp
  134. def self.search_user_state_6(user,agent)
  135. self.search_user_in_family_watchdog(user,agent)
  136. end
  137. # id = 7 state = CT (Connecticut)
  138. # network timeout --> used http://www.familywatchdog.us/search.asp
  139. def self.search_user_state_7(user,agent)
  140. self.search_user_in_family_watchdog(user,agent)
  141. end
  142. # id = 8 state = DE (Delaware)
  143. # http://sexoffender.dsp.delaware.gov/sor_search.htm
  144. # search field: lname, fname
  145. # multi form
  146. # linkresult :N/A
  147. # Acceptment :N/A
  148. def self.search_user_state_8(user,agent)
  149. page = agent.get("http://sexoffender.dsp.delaware.gov/sor_search.htm")
  150. search_form = page.forms.with.name("nsearch").first
  151. if search_form == nil
  152. logger.info "The page site is not available at the moment!!!"
  153. else
  154. search_form.field("lname").value =user.lastname
  155. search_form.field("fname").value =user.firstname
  156. search_result = agent.submit(search_form)
  157. if search_result.links.size >36
  158. result = SorSearchLog.new
  159. result.lastname = user.lastname
  160. result.firstname = user.firstname
  161. result.user_id =user.id
  162. result.state_name = 'DE'
  163. result.link =""
  164. result.html_content =search_result.body
  165. result.save
  166. end
  167. end
  168. end
  169. # id = 9 state = DC (District Of Columbia )
  170. # Search field: txtLast (lastname), txtFirst (firstname)
  171. # more field: txtDictric1 (District), drpQuad (City Quadrant)
  172. def self.search_user_state_9(user,agent)
  173. page = agent.get("http://sor.csosa.net/sor/public/publicSearch.asp")
  174. search_form = page.forms.with.name("form").first
  175. if search_form == nil
  176. logger.info "The page site is not available at the moment!!!"
  177. else
  178. search_form.txtLast =user.lastname
  179. search_form.txtFirst =user.firstname
  180. if user.city?
  181. search_form.drpQuad = user.city
  182. end
  183. search_result = agent.submit(search_form)
  184. if search_result.links.size >1
  185. result = SorSearchLog.new
  186. result.lastname = user.lastname
  187. result.firstname = user.firstname
  188. result.user_id =user.id
  189. result.state_name = 'DC'
  190. result.link =""
  191. result.html_content =search_result.body
  192. result.save
  193. end
  194. end
  195. end
  196. # id = 10 state = FL (Florida)
  197. # http://offender.fdle.state.fl.us/offender/offenderSearchNav.do?link=advanced
  198. # search field: firstName, LastName, city, county
  199. def self.search_user_state_10(user,agent)
  200. self.search_user_in_family_watchdog(user,agent)
  201. end
  202. # id = 11 state = GA (Georgia)
  203. # http://services.georgia.gov/gbi/gbisor/SORSearch.jsp
  204. # search field = fname, lastname
  205. # more field = city , county
  206. def self.search_user_state_11(user,agent)
  207. page = agent.get("http://services.georgia.gov/gbi/gbisor/SORSearch.jsp")
  208. search_form = page.forms.with.name("SearchOffender").first
  209. if search_form == nil
  210. logger.info "The page site is not available at the moment!!!"
  211. else
  212. search_form.lname =user.lastname
  213. search_form.fname =user.firstname
  214. if user.city?
  215. search_form.city =user.city
  216. end
  217. # if user.county?
  218. # search_form.county =user.county
  219. # end
  220. search_result = agent.submit(search_form)
  221. if search_result.links.size >0
  222. result = SorSearchLog.new
  223. result.lastname = user.lastname
  224. result.firstname = user.firstname
  225. result.user_id =user.id
  226. result.state_name = 'GA'
  227. result.link =""
  228. result.html_content =search_result.body
  229. result.save
  230. end
  231. end
  232. end
  233. # id = 12 state = HI (Hawaii)
  234. #http://sexoffenders.ehawaii.gov/sexoff/search.jsp
  235. # search field: LNAME, FNAME
  236. # more field :ZIP
  237. def self.search_user_state_12(user,agent)
  238. page = agent.get("http://sexoffenders.ehawaii.gov/sexoff/search.jsp")
  239. search_form = page.forms.first
  240. if search_form == nil
  241. logger.info "The page site is not available at the moment!!!"
  242. else
  243. search_form.LNAME =user.lastname
  244. search_form.FNAME =user.firstname
  245. if user.zip?
  246. search_form.ZIP =user.zip
  247. end
  248. search_result = agent.submit(search_form)
  249. if search_result.links.size >12
  250. result = SorSearchLog.new
  251. result.lastname = user.lastname
  252. result.firstname = user.firstname
  253. result.user_id =user.id
  254. result.state_name = 'HI'
  255. result.link =""
  256. result.html_content =search_result.body
  257. result.save
  258. end
  259. end
  260. end
  261. # id = 13 state = ID (Idaho)
  262. # Search field :fnm (firstname), lnm (lastname)
  263. # More field :cty (City),cnt (County)
  264. #http://www.isp.state.id.us/sor_id/search_regnam.htm
  265. def self.search_user_state_13(user,agent)
  266. page = agent.get("http://www.isp.state.id.us/sor_id/search_regnam.htm")
  267. search_form = page.forms.with.name("searchform").first
  268. if search_form == nil
  269. logger.info "The page site is not available at the moment!!!"
  270. else
  271. search_form.lnm =user.lastname
  272. search_form.fnm =user.firstname
  273. if user.city?
  274. search_form.cty =user.city
  275. end
  276. # if user.county?
  277. # search_form.cnt =user.county
  278. # end
  279. search_result = agent.submit(search_form)
  280. if search_result.links.size >17
  281. result = SorSearchLog.new
  282. result.lastname = user.lastname
  283. result.firstname = user.firstname
  284. result.user_id =user.id
  285. result.state_name = 'ID'
  286. result.link =""
  287. result.html_content =search_result.body
  288. result.save
  289. end
  290. end
  291. end
  292. # id = 14 state = IL (Illinois)
  293. # search field: lastname, city
  294. # more field: county, zipcode
  295. # http://www.isp.state.il.us/sor/
  296. def self.search_user_state_14(user,agent)
  297. page = agent.get("http://www.isp.state.il.us/sor/")
  298. accept_form = page.forms.with.name("disc").first
  299. unless accept_form.buttons.with.value("I Agree").nil?
  300. button=accept_form.buttons.with.value("I Agree")
  301. page = accept_form.click_button(button)
  302. end
  303. search_form = page.forms.with.name("SSOR").first
  304. if search_form == nil
  305. logger.info "The page site is not available at the moment!!!"
  306. else
  307. search_form.lastname =user.lastname
  308. if user.city?
  309. search_form.city =user.city
  310. end
  311. if user.zip?
  312. search_form.zipcode=user.zip
  313. end
  314. # if user.county?
  315. # search_form.county =user.county
  316. # end
  317. search_result = agent.submit(search_form)
  318. if search_result.links.size >28
  319. result = SorSearchLog.new
  320. result.lastname = user.lastname
  321. result.firstname = user.firstname
  322. result.user_id =user.id
  323. result.state_name = 'IL'
  324. result.link =""
  325. result.html_content =search_result.body
  326. result.save
  327. end
  328. end
  329. end
  330. # id = 15 state = IN (Indiana)
  331. # http://www.insor.org/insasoweb/
  332. # multi form
  333. def self.search_user_state_15(user,agent)
  334. page = agent.get("http://www.insor.org/insasoweb/")
  335. accept_form = page.forms.with.name("agreementForm").first
  336. unless accept_form ==nil
  337. radio_button = accept_form.radiobuttons.first
  338. radio_button.checked =true
  339. page =agent.submit(accept_form)
  340. end
  341. search_form = page.forms.with.name("advancedSearchForm").first
  342. search_form.lastName =user.lastname
  343. search_form.firstName =user.firstname
  344. # if user.county?
  345. # search_form.countyList =user.county
  346. # end
  347. search_result = search_form.submit
  348. if search_result.links.size >9
  349. result = SorSearchLog.new
  350. result.lastname = user.lastname
  351. result.firstname = user.firstname
  352. result.user_id =user.id
  353. result.state_name = 'IN'
  354. result.link =""
  355. result.html_content =search_result.body
  356. result.save
  357. end
  358. end
  359. # id = 16 state = IA (Iowa)
  360. # http://www.iowasexoffender.com/search.php
  361. # search field: lname, fname
  362. # more field: city , rzip, countysearch
  363. def self.search_user_state_16(user,agent)
  364. page = agent.get("http://www.iowasexoffender.com/search.php")
  365. link = page.links.href("http://www.iowasexoffender.com/proc01.php")
  366. unless link.nil?
  367. page = agent.click(link)
  368. page = agent.get("http://www.iowasexoffender.com/search.php")
  369. end
  370. search_form = page.forms.first
  371. if search_form == nil
  372. logger.info "The page site is not available at the moment!!!"
  373. else
  374. search_form.lname =user.lastname
  375. search_form.fname = user.firstname
  376. if user.zip?
  377. search_form.rzip = user.zip
  378. end
  379. if user.city?
  380. search_form.city = user.city
  381. end
  382. # if user.county?
  383. # search_form.countysearch =user.county
  384. # end
  385. search_result =search_form.submit
  386. if search_result.links.size >19
  387. result = SorSearchLog.new
  388. result.lastname = user.lastname
  389. result.firstname = user.firstname
  390. result.user_id =user.id
  391. result.state_name = 'IA'
  392. result.link ="http://www.iowasexoffender.com/searchENG.php?lname=#{user.lastname}&fname=#{user.firstname}&city=#{user.city}&rzip=#{user.zip}&weight=&aage=&countysearch=ALL&ogender=0&bgender=0&race=0&feet=0&inches=0&hcolor=0&ecolor=0&consearch=ALL"
  393. result.html_content =search_result.body
  394. result.save
  395. end
  396. end
  397. end
  398. # id = 17 state = KS (Kansas)
  399. #https://www.accesskansas.org/ssrv-registered-offender/index.do
  400. def self.search_user_state_17(user,agent)
  401. page = agent.get("https://www.accesskansas.org/ssrv-registered-offender/index.do")
  402. search_form = page.forms.with.name("nameForm").first
  403. if search_form == nil
  404. logger.info "The page site is not available at the moment!!!"
  405. else
  406. search_form.lastName =user.lastname
  407. search_form.firstName =user.firstname
  408. search_result =search_form.submit
  409. if search_result.links.size >21
  410. result = SorSearchLog.new
  411. result.lastname = user.lastname
  412. result.firstname = user.firstname
  413. result.user_id =user.id
  414. result.state_name = 'KS'
  415. result.link =""
  416. result.html_content =search_result.body
  417. result.save
  418. end
  419. end
  420. end
  421. # id = 18 state = KY (Kentucky)
  422. # http://kspsor.state.ky.us/
  423. # page = agent.get("http://kspsor.state.ky.us/html/SORSearch.htm")
  424. def self.search_user_state_18(user,agent)
  425. self.search_user_in_family_watchdog(user,agent)
  426. end
  427. # id = 19 state = LA (Louisiana)
  428. # "http://www.lsp.org/socpr/disclaimer.html"
  429. # Search field: OfndrLast, OfndrFirst
  430. # More field : OfndrCity
  431. # Trang nay su dung frame cua page http://www.icrimewatch.net
  432. def self.search_user_state_19(user,agent)
  433. page = agent.get("http://www.lsp.org/socpr/disclaimer.html")
  434. accept_form = page.forms.with.action("http://www.icrimewatch.net/louisiana.php").first
  435. page =accept_form.submit
  436. page = agent.get("http://www.icrimewatch.net/search2.php?AgencyID=54450")
  437. search_form = page.forms.first
  438. if search_form == nil
  439. logger.info "The page site is not available at the moment!!!"
  440. else
  441. search_form.OfndrLast = user.lastname
  442. search_form.OfndrFirst = user.firstname
  443. if user.city?
  444. search_form.OfndrCity =user.city
  445. end
  446. search_result =search_form.submit(search_form.buttons.first)
  447. if search_result.links.size >17
  448. result = SorSearchLog.new
  449. result.lastname = user.lastname
  450. result.firstname = user.firstname
  451. result.user_id =user.id
  452. result.state_name = 'LA'
  453. result.link ="http://www.icrimewatch.net/results.php?AgencyID=54450&SubmitNameSearch=1&OfndrCity=#{user.city}&OfndrLast=#{user.lastname}&OfndrFirst=#{user.firstname}"
  454. result.html_content =search_result.body
  455. result.save
  456. end
  457. end
  458. end
  459. # id = 20 state = ME (Maine)
  460. # http://sor.informe.org/sor/
  461. # search field: first_name, last_name
  462. # more field: zip, city
  463. def self.search_user_state_20(user,agent)
  464. page = agent.get("http://sor.informe.org/sor/")
  465. accept_form = page.forms.with.action("/cgi-bin/sor/step1.pl").first
  466. page =accept_form.submit
  467. search_form = page.forms.with.name("formtown").first
  468. if search_form == nil
  469. logger.info "The page site is not available at the moment!!!"
  470. else
  471. search_form.last_name = user.lastname
  472. search_form.first_name = user.firstname
  473. if user.city?
  474. search_form.city =user.city
  475. end
  476. if user.zip?
  477. search_form.zip =user.zip
  478. end
  479. search_result = search_form.submit
  480. if search_result.links.size >13
  481. result = SorSearchLog.new
  482. result.lastname = user.lastname
  483. result.firstname = user.firstname
  484. result.user_id =user.id
  485. result.state_name = 'ME'
  486. result.link ="http://sor.informe.org/cgi-bin/sor/step2.pl?city=#{user.city}&search=3&zip=#{user.zip}&first_name=#{user.firstname}&last_name=#{user.lastname}&area=0&limiter="
  487. result.html_content =search_result.body
  488. result.save
  489. end
  490. end
  491. end
  492. # id = 21 state = MD (Maryland)
  493. # http://dpscs.md.gov/onlineservs/socem/portal.shtml
  494. # multi form
  495. def self.search_user_state_21(user,agent)
  496. page = agent.get("http://dpscs.md.gov/onlineservs/socem/portal.shtml")
  497. accept_form = page.forms.with.action("http://www.dpscs.state.md.us/sorSearch/").first
  498. unless accept_form == nil
  499. checkbox =accept_form.checkboxes.with.name("CHECKBOX_1").first
  500. checkbox.checked =true
  501. page = accept_form.submit
  502. end
  503. search_form = page.forms.with.name("lookUpForm").first
  504. if search_form == nil
  505. logger.info "The page site is not available at the moment!!!"
  506. else
  507. search_form.lastnm =user.lastname
  508. search_form.firstnm =user.firstname
  509. search_result = search_form.submit
  510. if search_result.links.size >24
  511. result = SorSearchLog.new
  512. result.lastname = user.lastname
  513. result.firstname = user.firstname
  514. result.user_id =user.id
  515. result.state_name = 'MD'
  516. result.link ="http://www.dpscs.state.md.us/sorSearch/search.do?searchType=byName&anchor=offlist&firstnm=#{user.firstname}&lastnm=#{user.lastname}&category=ALL"
  517. result.html_content =search_result.body
  518. result.save
  519. end
  520. end
  521. end
  522. # id =22 state = MA (Massachusetts)
  523. # LastName, County , CityName
  524. def self.search_user_state_22(user,agent)
  525. self.search_user_in_family_watchdog(user,agent)
  526. end
  527. # id = 23 state = MI (Michigan)
  528. # http://www.mipsor.state.mi.us/
  529. # Nhan dang anh --> used http://www.familywatchdog.us/search.asp
  530. def self.search_user_state_23(user,agent)
  531. self.search_user_in_family_watchdog(user,agent)
  532. end
  533. # id = 24 state = MN (Minnesota)
  534. # https://por.state.mn.us/OffenderSearch.aspx
  535. # time out --> used http://www.familywatchdog.us/search.asp
  536. def self.search_user_state_24(user,agent)
  537. self.search_user_in_family_watchdog(user,agent)
  538. end
  539. # id = 25 state = MS (Missisippi)
  540. # http://www.sor.mdps.state.ms.us/sorpublic/hpsor_search.aspx
  541. # search field: txtFirstName, txtLastName
  542. # more field: txtZipCode,txtCity ddlCounty
  543. def self.search_user_state_25(user,agent)
  544. page = agent.get("http://www.sor.mdps.state.ms.us/sorpublic/hpsor_search.aspx")
  545. search_form = page.forms.with.name("Form1").first
  546. if search_form == nil
  547. logger.info "The page site is not available at the moment!!!"
  548. else
  549. search_form.txtLastName =user.lastname
  550. search_form.txtFirstName =user.firstname
  551. if user.city?
  552. search_form.txtCity =user.city
  553. end
  554. if user.zip?
  555. search_form.txtZipCode =user.zip
  556. end
  557. # if user.county?
  558. # search_form.ddlCounty = user.county
  559. # end
  560. search_result = search_form.submit(search_form.buttons.first)
  561. if search_result.links.size >1
  562. result = SorSearchLog.new
  563. result.lastname = user.lastname
  564. result.firstname = user.firstname
  565. result.user_id =user.id
  566. result.state_name = 'MS'
  567. result.link =""
  568. result.html_content =search_result.body
  569. result.save
  570. end
  571. end
  572. end
  573. # id = 26 state = M0 (Missouri)
  574. #http://www.mshp.dps.missouri.gov/MSHPWeb/PatrolDivisions/CRID/SOR/SORPage.html
  575. #http://www.mshp.dps.mo.gov/CJ38/search.jsp
  576. # search field: searchLast, searchFirst
  577. # More field: searchCity, searchZip, searchCounty
  578. def self.search_user_state_26(user,agent)
  579. # page = agent.get("http://www.mshp.dps.missouri.gov/MSHPWeb/PatrolDivisions/CRID/SOR/SORPage.html")
  580. page = agent.get("http://www.mshp.dps.mo.gov/CJ38/search.jsp")
  581. search_form = page.forms.with.name("searchForm").first
  582. if search_form == nil
  583. logger.info "The page site is not available at the moment!!!"
  584. else
  585. search_form.searchLast =user.lastname
  586. search_form.searchFirst =user.firstname
  587. if user.city?
  588. search_form.searchCity =user.city
  589. end
  590. if user.zip?
  591. search_form.searchZip =user.zip
  592. end
  593. # if user.county?
  594. # search_form.searchCounty = user.county
  595. # end
  596. search_result = agent.submit(search_form)
  597. if search_result.links.size >12
  598. result = SorSearchLog.new
  599. result.lastname = user.lastname
  600. result.firstname = user.firstname
  601. result.user_id =user.id
  602. result.state_name = 'MO'
  603. result.link =""
  604. result.html_content =search_result.body
  605. result.save
  606. end
  607. end
  608. end
  609. # id = 27 state = MT (Montana)
  610. # http://doj.mt.gov/svor/search.asp
  611. # Search field: NameLast
  612. # more field: County, City, Zip
  613. def self.search_user_state_27(user,agent)
  614. page = agent.get("http://doj.mt.gov/svor/search.asp")
  615. search_form = page.forms.with.name("frmSearch").first
  616. if search_form == nil
  617. logger.info "The page site is not available at the moment!!!"
  618. else
  619. search_form.NameLast =user.lastname
  620. if user.city?
  621. search_form.City =user.city
  622. end
  623. if user.zip?
  624. search_form.Zip =user.zip
  625. end
  626. # if user.county?
  627. # search_form.County =user.county
  628. # end
  629. search_result = agent.submit(search_form)
  630. if search_result.links.size >92
  631. result = SorSearchLog.new
  632. result.lastname = user.lastname
  633. result.firstname = user.firstname
  634. result.user_id =user.id
  635. result.state_name = 'MT'
  636. result.link ="http://doj.mt.gov/svor/searchlist.asp?County=&City=#{user.city}&Zip=#{user.zip}&NameLast=#{user.lastname}&OffenderType="
  637. result.html_content =search_result.body
  638. result.save
  639. end
  640. end
  641. end
  642. # id = 28 state = NE (Nebraska)
  643. # http://www.nsp.state.ne.us/sor/find.cfm
  644. # Search field: LNAME, FNAME
  645. # More field: COUNTY, ZIP, CITY
  646. def self.search_user_state_28(user,agent)
  647. page = agent.get("http://www.nsp.state.ne.us/sor/find.cfm")
  648. search_form = page.forms.with.name("search").first
  649. if search_form == nil
  650. logger.info "The page site is not available at the moment!!!"
  651. else
  652. search_form.LNAME =user.lastname
  653. search_form.FNAME =user.firstname
  654. if user.city?
  655. search_form.CITY =user.city
  656. end
  657. if user.zip?
  658. search_form.ZIP =user.zip
  659. end
  660. # if user.county?
  661. # search_form.COUNTY =user.county
  662. # end
  663. search_result = search_form.submit(search_form.buttons.first)
  664. if search_result.links.size >17
  665. result = SorSearchLog.new
  666. result.lastname = user.lastname
  667. result.firstname = user.firstname
  668. result.user_id =user.id
  669. result.state_name = 'NE'
  670. result.link ="http://www.nsp.state.ne.us/sor/SearchAction.cfm?LNAME=#{user.lastname}&CITY=#{user.city}&FNAME=#{user.firstname}&COUNTY=&SORT=Name&ZIP=#{user.zip}&PICS=on"
  671. result.html_content =search_result.body
  672. result.save
  673. end
  674. end
  675. end
  676. # id = 29 state = NV (Nevada)
  677. # http://www.nvsexoffenders.gov/Search.aspx
  678. # Search field: TextBoxFirstName, TextBoxLastName
  679. # More field: TextBoxCity,TextBoxZipCode
  680. def self.search_user_state_29(user,agent)
  681. page = agent.get("http://www.nvsexoffenders.gov/Search.aspx")
  682. search_form = page.forms.with.name("SearchForm").first
  683. if search_form == nil
  684. logger.info "The page site is not available at the moment!!!"
  685. else
  686. search_form.TextBoxLastName =user.lastname
  687. search_form.TextBoxFirstName =user.firstname
  688. if user.city?
  689. search_form.TextBoxCity =user.city
  690. end
  691. if user.zip?
  692. search_form.TextBoxZipCode =user.zip
  693. end
  694. # if user.county?
  695. # search_form.COUNTY = user.county
  696. # end
  697. search_result = search_form.submit(search_form.buttons.first)
  698. if search_result.title == "State of Nevada Sexual Offenders Search Result Page"
  699. result = SorSearchLog.new
  700. result.lastname = user.lastname
  701. result.firstname = user.firstname
  702. result.user_id =user.id
  703. result.state_name = 'NV'
  704. result.link =""
  705. result.html_content =search_result.body
  706. result.save
  707. end
  708. end
  709. end
  710. # id = 30 state = NH (New Hampshire)
  711. # http://www.oit.nh.gov/nsor/search.asp
  712. # page load error: network timeout --> used http://www.familywatchdog.us/search.asp
  713. def self.search_user_state_30(user,agent)
  714. self.search_user_in_family_watchdog(user,agent)
  715. end
  716. # id =31 , state NJ (New Jersey)
  717. # search field: lnme, fnme
  718. # multi form
  719. def self.search_user_state_31(user,agent)
  720. page = agent.get("https://www6.state.nj.us/LPS_spoff/individualsearch.jsp")
  721. accept_form =page.forms.with.name("OK").first
  722. unless accept_form == nil
  723. page =agent.submit(accept_form)
  724. page = agent.get("https://www6.state.nj.us/LPS_spoff/individualsearch.jsp")
  725. end
  726. search_form = page.forms.with.name("IS").first
  727. if search_form == nil
  728. logger.info "The page site is not available at the moment!!!"
  729. else
  730. search_form.lnme =user.lastname
  731. search_form.fnme =user.firstname
  732. search_result = agent.submit(search_form)
  733. if search_result.links.size >49
  734. result = SorSearchLog.new
  735. result.lastname = user.lastname
  736. result.firstname = user.firstname
  737. result.user_id =user.id
  738. result.state_name = 'NJ'
  739. result.link ="N/A"
  740. result.html_content =search_result.body
  741. result.save
  742. end
  743. end
  744. end
  745. # id = 32 state = NM (New Mexico)
  746. # http://www.nmsexoffender.dps.state.nm.us/fname.html
  747. # Search field: lname_txt
  748. # multi form
  749. def self.search_user_state_32(user,agent)
  750. page = agent.get("http://www.nmsexoffender.dps.state.nm.us/fname.html")
  751. search_form = page.forms.with.name("form3").first
  752. if search_form == nil
  753. logger.info "The page site is not available at the moment!!!"
  754. else
  755. search_form.lname_txt =user.lastname.upcase
  756. search_result = search_form.submit(search_form.buttons.first)
  757. if search_result.links.size >0
  758. result = SorSearchLog.new
  759. result.lastname = user.lastname
  760. result.firstname = user.firstname
  761. result.user_id =user.id
  762. result.state_name = 'NV'
  763. result.link ="http://www.nmsexoffender.dps.state.nm.us/servlet/fname_serv.class?lname_txt=#{user.lastname.upcase}"
  764. result.html_content =search_result.body
  765. result.save
  766. end
  767. end
  768. end
  769. # id =33 , state NY (New York)
  770. # Search field: LastName
  771. # More field: County, Zip
  772. def self.search_user_state_33(user,agent)
  773. page = agent.get("http://www.criminaljustice.state.ny.us/nsor/search_index.htm")
  774. search_form = page.forms.with.action("/cgi/internet/nsor/fortecgi").first
  775. if search_form == nil
  776. logger.info "The page site is not available at the moment!!!"
  777. else
  778. search_form.LastName =user.lastname
  779. if user.zip?
  780. search_form.County =user.zip
  781. end
  782. # if user.county?
  783. # search_form.County =user.county
  784. # end
  785. search_result = agent.submit(search_form)
  786. if search_result.links.size >1
  787. result = SorSearchLog.new
  788. result.lastname = user.lastname
  789. result.firstname = user.firstname
  790. result.user_id =user.id
  791. result.state_name = 'NY'
  792. result.link ="http://www.criminaljustice.state.ny.us/cgi/internet/nsor/fortecgi?ServiceName=WebNSOR&TemplateName=results.htm&RequestingHandler=WebNSORSearchResultsHandler&LastName=#{user.lastname}&Zip=#{user.zip}&reset=Clear&County=+"
  793. result.html_content =search_result.body
  794. result.save
  795. end
  796. end
  797. end
  798. # id = 34 state = NC (North Carolina)
  799. # http://ncfindoffender.com/disclaimer.aspx
  800. # search field: fname, lname
  801. # more field zip,city, county
  802. def self.search_user_state_34(user,agent)
  803. page = agent.get("http://ncfindoffender.com/disclaimer.aspx")
  804. accept_form = page.forms.with.name("Form2").first
  805. unless accept_form == nil
  806. page =accept_form.submit(accept_form.buttons.first)
  807. end
  808. search_form = page.forms.with.name("Form1").first
  809. if search_form == nil
  810. logger.info "The page site is not available at the moment!!!"
  811. else
  812. search_form.lname =user.lastname
  813. search_form.fname =user.firstname
  814. if user.city?
  815. search_form.city =user.city
  816. end
  817. if user.zip?
  818. search_form.zip =user.zip
  819. end
  820. # if user.county?
  821. # search_form.county=user.county
  822. # end
  823. search_result = search_form.submit(search_form.buttons.with.name("searchbutton1").first)
  824. if search_result.links.size >20
  825. result = SorSearchLog.new
  826. result.lastname = user.lastname
  827. result.firstname = user.firstname
  828. result.user_id =user.id
  829. result.state_name = 'NC'
  830. result.link =""
  831. result.html_content =search_result.body
  832. result.save
  833. end
  834. end
  835. end
  836. # id = 35 state = ND (North Dakota)
  837. # http://www.sexoffender.nd.gov/
  838. # http://www.sexoffender.nd.gov/offdisclaimer.aspx
  839. def self.search_user_state_35(user,agent)
  840. self.search_user_in_family_watchdog(user,agent)
  841. end
  842. # id = 36 state = OH (Ohio)
  843. # http://www.esorn.ag.state.oh.us/Secured/p21_2.aspx
  844. # Search field: txtLastName,txtFirstName
  845. # More field: txtZip, cboCounty
  846. def self.search_user_state_36(user,agent)
  847. page = agent.get("http://www.esorn.ag.state.oh.us/Secured/p21_2.aspx")
  848. search_form = page.forms.with.name("frmOffenderSearch").first
  849. if search_form == nil
  850. logger.info "The page site is not available at the moment!!!"
  851. else
  852. search_form.txtLastName =user.lastname
  853. search_form.txtFirstName =user.firstname
  854. if user.zip?
  855. search_form.txtZip =user.zip
  856. end
  857. # if user.county?
  858. # search_form.cboCounty =user.county
  859. # end
  860. search_result = search_form.submit(search_form.buttons.first)
  861. if search_result.links.size >38
  862. result = SorSearchLog.new
  863. result.lastname = user.lastname
  864. result.firstname = user.firstname
  865. result.user_id =user.id
  866. result.state_name = 'OH'
  867. result.link =""
  868. result.html_content =search_result.body
  869. result.save
  870. end
  871. end
  872. end
  873. # id = 37 state = OK (Oklahoma)
  874. # http://docapp8.doc.state.ok.us/servlet/page?_pageid=190&_dad=portal30&_schema=PORTAL30
  875. # Search field: first_name, last_name
  876. # More field: county, zip, city
  877. # Khong submit duoc ket qua search, chua ro ly do"WWW::Mechanize::ResponseCodeError: 404 => Net::HTTPNotFound" nhung lam ngoai web ra
  878. def self.search_user_state_37(user,agent)
  879. self.search_user_in_family_watchdog(user,agent)
  880. end
  881. # id = 38 state = OR (Oregon)
  882. # http://sexoffenders.oregon.gov/
  883. # Search field: LAST, FIRST
  884. # More field: COUNTY, CITY, ZIP
  885. def self.search_user_state_38(user,agent)
  886. page = agent.get("http://sexoffenders.oregon.gov/")
  887. accept_form = page.forms.with.name("myform").first
  888. unless accept_form == nil
  889. page =accept_form.submit(accept_form.buttons.first)
  890. end
  891. search_form = page.forms.with.action("/SorPublic/Web.dll/main").first
  892. if search_form == nil
  893. logger.info "The page site is not available at the moment!!!"
  894. else
  895. search_form.LAST =user.lastname
  896. search_form.FIRST =user.firstname
  897. if user.city?
  898. search_form.CITY =user.city
  899. end
  900. if user.zip?
  901. search_form.ZIP =user.zip
  902. end
  903. # if user.county?
  904. # search_form.COUNTY=user.county
  905. # end
  906. search_result = search_form.submit(search_form.buttons.with.name("SEND").first)
  907. if search_result.links.size >12
  908. result = SorSearchLog.new
  909. result.lastname = user.lastname
  910. result.firstname = user.firstname
  911. result.user_id =user.id
  912. result.state_name = 'OR'
  913. result.link =""
  914. result.html_content =search_result.body
  915. result.save
  916. end
  917. end
  918. end
  919. # id = 39 state = PA (Pennsylvania)
  920. # http://www.pameganslaw.state.pa.us/
  921. # Search field: txtFirstName, txtLastName
  922. # multiform
  923. # Khong submit vao trang trong duoc, chua ro ly do
  924. def self.search_user_state_39(user,agent)
  925. self.search_user_in_family_watchdog(user,agent)
  926. end
  927. # id = 40 state = RI (Rhode Island)
  928. # http://www.paroleboard.ri.gov/sexoffender/agree.php
  929. # trang nay chi search theo location khong co search theo name
  930. def self.search_user_state_40(user,agent)
  931. self.search_user_in_family_watchdog(user,agent)
  932. end
  933. # id = 41 state = SC (South Carolina)
  934. # http://services.sled.sc.gov/sor/search.aspx?Type=Name
  935. # Note: Name search is a SOUNDEx ("sounds like") search on both name and alias. --> khong dung duoc
  936. # txt_name
  937. # multi form
  938. def self.search_user_state_41(user,agent)
  939. self.search_user_in_family_watchdog(user,agent)
  940. end
  941. # id = 42 state = SD (South Dakota)
  942. # http://sor.sd.gov/disclaimer.asp?page=search&nav=2
  943. # seach field: lname, fname
  944. # More field: county, city, zipcode
  945. def self.search_user_state_42(user,agent)
  946. self.search_user_in_family_watchdog(user,agent)
  947. end
  948. # id = 43 state = TN (Tennessee)
  949. # http://www.ticic.state.tn.us/sorinternet/sosearch.aspx
  950. # Search field: txtLastName, txtFirstName
  951. # More field: txtcity, txtZip, ddlCounty
  952. def self.search_user_state_43(user,agent)
  953. page = agent.get("http://www.ticic.state.tn.us/sorinternet/sosearch.aspx")
  954. search_form = page.forms.with.name("Form2").first
  955. if search_form == nil
  956. logger.info "The page site is not available at the moment!!!"
  957. else
  958. search_form.txtLastName =user.lastname
  959. search_form.txtFirstName =user.firstname
  960. if user.city?
  961. search_form.txtcity =user.city
  962. end
  963. if user.zip?
  964. search_form.txtZip =user.zip
  965. end
  966. # if user.county?
  967. # search_form.ddlCounty =user.county
  968. # end
  969. button=search_form.buttons.with.name("btnFind").first
  970. search_result =search_form.submit(button)
  971. if search_result.links.size >4
  972. result = SorSearchLog.new
  973. result.lastname = user.lastname
  974. result.firstname = user.firstname
  975. result.user_id =user.id
  976. result.state_name = 'TN'
  977. result.link =""
  978. result.html_content =search_result.body
  979. result.save
  980. end
  981. end
  982. end
  983. # id = 44 state = TX (Texas)
  984. # https://records.txdps.state.tx.us/DPS_WEB/SorNew/PublicSite/index.aspx?SearchType=Name
  985. # Search field: CurrentDPStemplateBase$ctl06$ctl00$txtLNA_TXT,CurrentDPStemplateBase$ctl06$ctl00$txtFNA_TXT
  986. # More filed: CurrentDPStemplateBase$ctl06$ctl00$ddlCounty (county)
  987. # multi form
  988. def self.search_user_state_44(user,agent)
  989. page = agent.get("https://records.txdps.state.tx.us/DPS_WEB/SorNew/PublicSite/index.aspx?SearchType=Name")
  990. accept_link = page.links.text("I have read the Web Site Caveats and agree to the terms ")
  991. unless accept_link.nil?
  992. page = agent.click(accept_link)
  993. end
  994. search_form = page.forms.with.name("aspnetForm").first
  995. if search_form == nil
  996. logger.info "The page site is not available at the moment!!!"
  997. else
  998. search_form.field("CurrentDPStemplateBase$ctl06$ctl00$txtLNA_TXT").value =user.lastname
  999. search_form.field("CurrentDPStemplateBase$ctl06$ctl00$txtFNA_TXT").value =user.firstname
  1000. # if user.county?
  1001. # search_form.field("CurrentDPStemplateBase$ctl06$ctl00$ddlCounty").value=user.county
  1002. # end
  1003. button = search_form.buttons.first
  1004. search_result = search_form.click_button(button)
  1005. if search_result.links.size >15
  1006. result = SorSearchLog.new
  1007. result.lastname = user.lastname
  1008. result.firstname = user.firstname
  1009. result.user_id =user.id
  1010. result.state_name = 'TX'
  1011. result.link =""
  1012. result.html_content=search_result.body
  1013. result.save
  1014. end
  1015. end
  1016. end
  1017. # id = 45 state = UT (Utah)
  1018. # http://corrections.utah.gov/asp-bin/sonar.asp
  1019. # http://www.communitynotification.com/cap_office_disclaimer.php?office=54438
  1020. # multi form
  1021. #Trang nay su dung frame cua page http://www.icrimewatch.net
  1022. def self.search_user_state_45(user,agent)
  1023. self.search_user_in_family_watchdog(user,agent)
  1024. end
  1025. # id = 46 state = VT (Vermont)
  1026. # http://170.222.137.2:8080/sor/
  1027. # lastname or county
  1028. def self.search_user_state_46(user,agent)
  1029. self.search_user_in_family_watchdog(user,agent)
  1030. end
  1031. # id = 47 state = VA (Virginia)
  1032. # http://sex-offender.vsp.virginia.gov/sor/policy.html?original_requestUrl=http%3A%2F%2Fsex-offender.vsp.virginia.gov%3A80%2Fsor%2FzipSearch.html&original_request_method=GET&original_request_parameters=
  1033. # Nhan dang hinh
  1034. def self.search_user_state_47(user,agent)
  1035. self.search_user_in_family_watchdog(user,agent)
  1036. end
  1037. # id = 48 state = WA (Washington)
  1038. # http://ml.waspc.org/Accept.aspx?ReturnUrl=/index.aspx
  1039. # The page cannot be displayed
  1040. def self.search_user_state_48(user,agent)
  1041. self.search_user_in_family_watchdog(user,agent)
  1042. end
  1043. # id = 49 state = WV (West Virginia)
  1044. # http://www.wvstatepolice.com/sexoff/mainsearch_r07.cfm
  1045. # Khong ro nguyen nhan nhung submit accpet thi nhay sang index chu khong phai search form
  1046. def self.search_user_state_49(user,agent)
  1047. self.search_user_in_family_watchdog(user,agent)
  1048. end
  1049. # id = 50 state = WI (Wisconsin)
  1050. # http://offender.doc.state.wi.us/public/search/searchbyname.jsp
  1051. # multi form
  1052. # last_name, first_name
  1053. def self.search_user_state_50(user,agent)
  1054. page = agent.get("http://offender.doc.state.wi.us/public/search/searchbyname.jsp")
  1055. search_form = page.forms.with.action("sor").first
  1056. if search_form == nil
  1057. logger.info "The page site is not available at the moment!!!"
  1058. else
  1059. search_form.last_name =user.lastname
  1060. search_form.first_name =user.firstname
  1061. accept_page =search_form.submit
  1062. accept_form = accept_page.forms.first
  1063. search_result =accept_form.submit
  1064. if search_result.links.size >21
  1065. result = SorSearchLog.create(:lastname => user.lastname, :firstname => user.firstname, :user_id =>user.id,
  1066. :state_name => 'WI', :link => "" , :html_content =>search_result.body)
  1067. end
  1068. end
  1069. end
  1070. # id = 51 state = WY (Wyoming)
  1071. # http://wysors.dci.wyo.gov/
  1072. # Search field: lnm
  1073. # more field: cty, cnt
  1074. def self.search_user_state_51(user,agent)
  1075. page = agent.get("http://wysors.dci.wyo.gov/")
  1076. accept_form = page.forms.with.name("df").first
  1077. unless accept_form == nil
  1078. checkbox =accept_form.checkboxes.with.name("acknowledge").first
  1079. checkbox.checked =true
  1080. page = accept_form.submit
  1081. page = agent.get("http://wysors.dci.wyo.gov/sor/search_regnam.htm")
  1082. end
  1083. search_form = page.forms.with.name("searchform").first
  1084. if search_form == nil
  1085. logger.info "The page site is not available at the moment!!!"
  1086. else
  1087. search_form.lnm =user.lastname
  1088. if user.city?
  1089. search_form.cty =user.city
  1090. end
  1091. # if user.county?
  1092. # search_form.cnt=user.county
  1093. # end
  1094. search_result = search_form.submit
  1095. if search_result.links.size >26
  1096. result = SorSearchLog.new
  1097. result.lastname = user.lastname
  1098. result.firstname = user.firstname
  1099. result.user_id =user.id
  1100. result.state_name = 'WY'
  1101. result.link =""
  1102. result.html_content =search_result.body
  1103. result.save
  1104. end
  1105. end
  1106. end
  1107. def self.search_user_in_family_watchdog(user,agent)
  1108. page = agent.get("http://www.familywatchdog.us/search.asp")
  1109. search_form = page.forms.with.name("form2").first
  1110. if search_form == nil
  1111. logger.info "The page site is not available at the moment!!!"
  1112. else
  1113. search_form.txtLastName =user.lastname
  1114. search_form.txtFirstName =user.firstname
  1115. state =State.find(user.state_id).name
  1116. search_form.txtState = state
  1117. search_result =search_form.submit
  1118. if search_result.links.size >20
  1119. result = SorSearchLog.create(:lastname => user.lastname, :firstname => user.firstname, :user_id =>user.id,
  1120. :state_name => state, :link => "", :html_content =>search_result.body)
  1121. end
  1122. end
  1123. end
  1124. def self.time_diff_in_days(time = Time.now)
  1125. ((Time.now - time).round)/SECONDS_PER_DAY
  1126. end
  1127. def self.find_memberships_to_bill_next_day
  1128. users = []
  1129. mships = Membership.active.find(:all, :conditions => ['billing_method = ? and cost > 0', Membership::CREDIT_CARD_BILLING_METHOD])
  1130. mships.each {|m|
  1131. users << m.user if (m.last_billed.nil? || (time_diff_in_days(m.last_billed) >= PAYMENT_DUE_CYCLE - 1))
  1132. }
  1133. users
  1134. end
  1135. end