From 34285ca4690819e66f8d0c5ef373092d2bd3e799 Mon Sep 17 00:00:00 2001 From: Laurence Warne Date: Thu, 25 Aug 2022 08:37:36 +0100 Subject: [PATCH] Specify reddit user agent --- lambda/updateLambda/src/updateLambda/Handler.scala | 7 ++++--- src/Lib.hs | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lambda/updateLambda/src/updateLambda/Handler.scala b/lambda/updateLambda/src/updateLambda/Handler.scala index f7a19e4..24f0bb0 100644 --- a/lambda/updateLambda/src/updateLambda/Handler.scala +++ b/lambda/updateLambda/src/updateLambda/Handler.scala @@ -11,9 +11,10 @@ object Handler extends ZLambda[KinesisEvent, String] { override def apply(event: KinesisEvent, context: Context): Task[String] = { for { - _ <- printLine(event) - proc <- Command("git", "status").run - _ <- printLine(proc) + _ <- printLine(event) + proc <- Command("git", "status").run + stdout <- proc.stdout.string + _ <- printLine(stdout) } yield "Handler ran successfully" } } diff --git a/src/Lib.hs b/src/Lib.hs index 948907b..62d2531 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -23,6 +23,9 @@ data CommentInfo = CommentInfo { user :: T.Text , commentInfoID :: T.Text , parentID :: T.Text} deriving (Eq, Show) +runWithAgent :: MonadIO m => RedditT m a -> m (Either (APIError RedditError) a) +runWithAgent r = runRedditWith (RedditOptions True Nothing Anonymous (Just "reddit-tips-n-tricks")) r + fromComment :: Comment -> CommentInfo fromComment c = CommentInfo auth votes (body c) cID parentPostID where @@ -35,7 +38,7 @@ commentFilter :: Comment -> Bool commentFilter c = any (>= 8) (score c) && not (isDeleted c) getRelevantPosts :: MonadIO m => T.Text -> Maybe PostID -> m (Either (APIError RedditError) [Post]) -getRelevantPosts s maybePostID = runRedditAnon $ do +getRelevantPosts s maybePostID = runWithAgent $ do let options = Options (After <$> maybePostID) (Just searchLimit) Listing _ maybeAfter posts <- search (Just $ R "emacs") options Top s nextPage <- case (maybeAfter, posts) of @@ -44,7 +47,7 @@ getRelevantPosts s maybePostID = runRedditAnon $ do return (posts ++ fromRight [] nextPage) getTopWeeklyComments :: MonadIO m => [Post] -> m (Either (APIError RedditError) [CommentInfo]) -getTopWeeklyComments posts = runRedditAnon $ do +getTopWeeklyComments posts = runWithAgent $ do comments <- traverse (getComments . postID) posts let allComments = mapMaybe (\case Actual c -> if commentFilter c then Just $ fromComment c