From e2aedb1e61e38626be909b999dd0ef5094f4627c Mon Sep 17 00:00:00 2001 From: mdashlw Date: Fri, 5 Apr 2024 18:34:48 +0300 Subject: [PATCH 1/2] feat(scrapers/twitter): return received tweet text Also: use url and username from received json for the sake of consistent capitalizaton --- lib/philomena/scrapers/twitter.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/philomena/scrapers/twitter.ex b/lib/philomena/scrapers/twitter.ex index 9575c4e51..e61706931 100644 --- a/lib/philomena/scrapers/twitter.ex +++ b/lib/philomena/scrapers/twitter.ex @@ -23,8 +23,9 @@ defmodule Philomena.Scrapers.Twitter do end) %{ - source_url: "https://twitter.com/#{user}/status/#{status_id}", - author_name: user, + source_url: json["url"], + author_name: json["author"]["screen_name"], + description: json["text"], images: images } end From 0c044935c01e24f940db49e825a711eefa96bd97 Mon Sep 17 00:00:00 2001 From: mdashlw Date: Fri, 5 Apr 2024 18:42:32 +0300 Subject: [PATCH 2/2] fix: all fields are under "tweet" --- lib/philomena/scrapers/twitter.ex | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/philomena/scrapers/twitter.ex b/lib/philomena/scrapers/twitter.ex index e61706931..0ba64180e 100644 --- a/lib/philomena/scrapers/twitter.ex +++ b/lib/philomena/scrapers/twitter.ex @@ -13,9 +13,10 @@ defmodule Philomena.Scrapers.Twitter do {:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url) json = Jason.decode!(body) + tweet = json["tweet"] images = - Enum.map(json["tweet"]["media"]["photos"], fn p -> + Enum.map(tweet["media"]["photos"], fn p -> %{ url: "#{p["url"]}:orig", camo_url: Camo.Image.image_url(p["url"]) @@ -23,9 +24,9 @@ defmodule Philomena.Scrapers.Twitter do end) %{ - source_url: json["url"], - author_name: json["author"]["screen_name"], - description: json["text"], + source_url: tweet["url"], + author_name: tweet["author"]["screen_name"], + description: tweet["text"], images: images } end