1
0

tescort.lisp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. (in-package :cl-user)
  2. (defpackage chatikbot.plugins.tescort
  3. (:use :cl :chatikbot.common :chatikbot.scraping :eager-future2))
  4. (in-package :chatikbot.plugins.tescort)
  5. (defvar *chat-cookie-jars* (make-hash-table))
  6. (defparameter +blacklists+
  7. '((:tescort
  8. (:scrape (:request . ("http://www.tescort.com/panel/client-blacklist"
  9. :parameters (("client_criterias" . q)
  10. ("search" . "search"))))
  11. (:items . ".black_list_table tbody tr")
  12. (:info (:date . ("td:nth-of-type(1)"))
  13. (:name . ("td:nth-of-type(2)"))
  14. (:city . ("td:nth-of-type(3)"))
  15. (:phone . ("td:nth-of-type(4)"))
  16. (:comment . ("td:nth-of-type(5)"))
  17. (:photos . ("td:nth-of-type(5) a" :attr :href :multiple t))))
  18. (:init . (("http://www.tescort.com/private/signin")
  19. ".signin-box form"
  20. (("username" . tescort-login)
  21. ("password" . tescort-pass))))
  22. (:validate . "#header .sitemenu-logged"))
  23. (:annonce
  24. (:scrape (:request . ("https://www.6annonce.com/private-v2/client-blacklist"
  25. :parameters (("client_criterias" . q)
  26. ("search" . "search"))))
  27. (:items . ".black_list_table tbody tr")
  28. (:info (:date . ("td:nth-of-type(1)"))
  29. (:name . ("td:nth-of-type(2)"))
  30. (:city . ("td:nth-of-type(3)"))
  31. (:phone . ("td:nth-of-type(4)"))
  32. (:comment . ("td:nth-of-type(5)"))
  33. (:photos . ("td:nth-of-type(5) a" :attr :href :multiple t))))
  34. (:init . (("https://www.6annonce.com/private/signin")
  35. ".signin-box form"
  36. (("username" . annonce-login)
  37. ("password" . annonce-pass))))
  38. (:validate . "#header .sitemenu-logged"))
  39. (:escortnews
  40. (:scrape (:request . ("https://my.escortnews.eu/ajax.php"
  41. :method :post
  42. :content (("s" . q)
  43. ("action" . "viewBlacklistRecords")
  44. ("page" . "1") ("s1" . "date") ("s2" . "0") ("m" . "0"))))
  45. (:processor . en-request)
  46. (:items . ".blacklist .record")
  47. (:info (:date . ("ul li:nth-of-type(1)"))
  48. (:name . ("ul li:nth-of-type(2)"))
  49. (:phone . ("ul li:nth-of-type(3)"))
  50. (:city . ("ul li:nth-of-type(4)"))
  51. (:email . ("ul li:nth-of-type(5)"))
  52. (:comment . (".text" :child 6))))
  53. (:init . (("https://my.escortnews.eu/")
  54. "#form_PopUp"
  55. (("username" . escortnews-login)
  56. ("password" . escortnews-pass))))
  57. (:validate . ".countSearchBar"))
  58. ))
  59. (defun en-request (url &rest args &key method parameters content headers basic-auth cookie-jar keep-alive use-connection-pool timeout ssl-key-file ssl-cert-file ssl-key-password stream verbose proxy insecure ca-path user-agent (object-as :alist))
  60. (declare (ignore method parameters basic-auth cookie-jar keep-alive use-connection-pool timeout ssl-key-file ssl-cert-file ssl-key-password stream verbose proxy insecure ca-path user-agent))
  61. (remf args :object-as)
  62. (when content
  63. (push (cons :content-type "application/json") headers))
  64. (multiple-value-bind (body status headers uri)
  65. (apply #'http-request url args)
  66. (unless (stringp body)
  67. (setf body (babel:octets-to-string body :encoding :utf-8)))
  68. (values (plump:parse (agets (yason:parse body :object-as object-as) "html")) status headers uri)))
  69. (defvar *tescort-login*)
  70. (defvar *tescort-pass*)
  71. (defvar *annonce-login*)
  72. (defvar *annonce-pass*)
  73. (defvar *escortnews-login*)
  74. (defvar *escortnews-pass*)
  75. (defun get-common-context ()
  76. `((tescort-login . ,*tescort-login*)
  77. (tescort-pass . ,*tescort-pass*)
  78. (annonce-login . ,*annonce-login*)
  79. (annonce-pass . ,*annonce-pass*)
  80. (escortnews-login . ,*escortnews-login*)
  81. (escortnews-pass . ,*escortnews-pass*)))
  82. (defun search-blacklists (query)
  83. (let ((context (append (get-common-context)
  84. `((q . ,query)))))
  85. (labels ((f (info)
  86. (destructuring-bind (name . params) info
  87. (cons name (ignore-errors (scrape-list params context))))))
  88. (pmapcar #'f +blacklists+))))
  89. (defun merge-results (results)
  90. (loop for (name . res) in results append res))
  91. (defun format-blacklist (item)
  92. (format nil "~A, ~A: ~A *~A*~%~A~@[~%~A~]"
  93. (agets item :date) (agets item :city)
  94. (agets item :name) (agets item :phone)
  95. (agets item :comment)
  96. (when (agets item :photos)
  97. (format nil "~{[pic~A](~A)~^, ~}"
  98. (loop for i from 1 for p in (agets item :photos)
  99. append (list i p))))))
  100. (defun handle-blacklist (chat-id query)
  101. (with-chat-cookies (chat-id *chat-cookie-jars*)
  102. (telegram-send-chat-action chat-id "typing")
  103. (let ((results (merge-results (search-blacklists query))))
  104. (bot-send-message chat-id (if results
  105. (text-chunks (mapcar #'format-blacklist results)
  106. :pre-pre "" :pre-post "")
  107. "Not found")
  108. :parse-mode "markdown"))))
  109. (def-message-admin-cmd-handler handler-cmd-blacklist (:blacklist :bl)
  110. (cond
  111. ((null args) (bot-send-message chat-id "Enter query")
  112. (on-next-message chat-id
  113. (handle-blacklist chat-id text)))
  114. (:otherwise (handle-blacklist chat-id (spaced args)))))