1
0

tescort.lisp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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-init . "button.signout")
  58. (:validate . ".countSearchBar"))
  59. ))
  60. (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))
  61. (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))
  62. (remf args :object-as)
  63. (when content
  64. (push (cons :content-type "application/json") headers))
  65. (multiple-value-bind (body status headers uri)
  66. (apply #'http-request url args)
  67. (unless (stringp body)
  68. (setf body (babel:octets-to-string body :encoding :utf-8)))
  69. (values (plump:parse
  70. (agets
  71. (or (ignore-errors (yason:parse body :object-as object-as))
  72. `(("html" . ,body)))
  73. "html"))
  74. status headers uri)))
  75. (defvar *tescort-login*)
  76. (defvar *tescort-pass*)
  77. (defvar *annonce-login*)
  78. (defvar *annonce-pass*)
  79. (defvar *escortnews-login*)
  80. (defvar *escortnews-pass*)
  81. (defun get-common-context ()
  82. `((tescort-login . ,*tescort-login*)
  83. (tescort-pass . ,*tescort-pass*)
  84. (annonce-login . ,*annonce-login*)
  85. (annonce-pass . ,*annonce-pass*)
  86. (escortnews-login . ,*escortnews-login*)
  87. (escortnews-pass . ,*escortnews-pass*)))
  88. (defun search-blacklists (query)
  89. (let ((context (append (get-common-context)
  90. `((q . ,query)))))
  91. (labels ((f (info)
  92. (destructuring-bind (name . params) info
  93. (cons name (ignore-errors (scrape-list params context))))))
  94. (pmapcar #'f +blacklists+))))
  95. (defun merge-results (results)
  96. (loop for (name . res) in results append res))
  97. (defun format-blacklist (item)
  98. (format nil "~A, ~A: ~A *~A*~%~A~@[~%~A~]"
  99. (agets item :date) (agets item :city)
  100. (agets item :name) (agets item :phone)
  101. (agets item :comment)
  102. (when (agets item :photos)
  103. (format nil "~{[pic~A](~A)~^, ~}"
  104. (loop for i from 1 for p in (agets item :photos)
  105. append (list i p))))))
  106. (defun handle-blacklist (query)
  107. (with-chat-cookies (*chat-id* *chat-cookie-jars*)
  108. (telegram-send-chat-action *chat-id* "typing")
  109. (let ((results (merge-results (search-blacklists query))))
  110. (bot-send-message (if results
  111. (text-chunks (mapcar #'format-blacklist results)
  112. :pre-pre "" :pre-post "")
  113. "Not found")
  114. :parse-mode "markdown"))))
  115. (def-message-admin-cmd-handler handler-cmd-blacklist (:blacklist :bl)
  116. (cond
  117. ((null *args*) (bot-send-message "Enter query")
  118. (on-next-message (handle-blacklist *text*)))
  119. (:otherwise (handle-blacklist (spaced *args*)))))