Skip to content

Commit

Permalink
Specify reddit user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceWarne committed Aug 25, 2022
1 parent 676bf39 commit 34285ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lambda/updateLambda/src/updateLambda/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 5 additions & 2 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 34285ca

Please sign in to comment.