Permalink
Browse files

Fix meme search via scrape

  • Loading branch information...
devth committed Sep 7, 2017
1 parent 14ff818 commit 4c1ab632a38172792bb5eb802cabe42390a20e5d
Showing with 11 additions and 4 deletions.
  1. +2 βˆ’0 doc/CHANGELOG.md
  2. +1 βˆ’1 src/yetibot/commands/meme.clj
  3. +6 βˆ’3 src/yetibot/models/imgflip.clj
  4. +2 βˆ’0 test/yetibot/test/models/imgflip.clj
View
@@ -3,6 +3,8 @@
## 0.4.11 (Unreleased)
- Upgrade to `yetibot.core 0.4.11`
- Fix meme search scraper on imgflip -
[#684](https://github.com/yetibot/yetibot/issues/684)
## 0.4.10
@@ -6,7 +6,7 @@
[yetibot.models.imgflip :as model]))
(defn- urlify
"Imgflip likes to return urls missing the http: prefix for some reason."
"Imgflip likes to return urls missing the `http:` prefix"
[weird-url]
(if-not (re-find #"^http" weird-url)
(str "http:" weird-url)
@@ -31,13 +31,16 @@
(re-find p (:name meme))
(re-find p (s/replace (:name meme) #"\s" ""))))
; todo: append results of search-via-scrape to cached (memes)
(def res (client/get "https://imgflip.com/memesearch"
{:query-params {:q "icahn" :page 1}}))
;; TODO: append results of search-via-scrape to cached (memes) or use a memo/ttl
(defn search-via-scrape [q n]
(info "search via scraping" q)
(info "search via scraping" q n)
(let [res (client/get "https://imgflip.com/memesearch" {:query-params {:q q :page n}})]
(->> res
:body
(re-seq #"alt\=\"([^\"]+)\"\s+src\=\'.+imgflip\.com\/([\w\d]+).jpg\'")
(re-seq #"alt\=\"([^\"]+)\"\s+src\=.+imgflip\.com\/([\w\d]+).jpg")
(map (fn [[_ alt id]]
{:name (s/replace alt #"\sMeme Template( Thumbnail)*" "")
:url (str "http://i.imgflip.com/" id ".jpg")
@@ -18,6 +18,8 @@
(fact search-memes-test
(:name (first (search-memes "alien"))) => "Ancient Aliens")
(fact (scrape-all-memes "icahn" 2) => not-empty)
(fact generate-meme-test
(let [m (generate-meme "61579" "foo" "bar")]
(:success m) => true

0 comments on commit 4c1ab63

Please sign in to comment.