What I Built
Morning Joy lets you start each day on a good note by texting you an uplifting news story and a picture of something cute.
Following the news can be stressful or even depressing. This is one small way to remember that good things are happening too.
Category Submission
Interesting Integrations
Demo
Link to Code
dguo / morning-joy
Wake up to a happy text every day!
How I Built It
I signed up for Twilio and followed their quickstart guide for Node.js. I bought a phone number and tested sending a text to myself. This was painless. I probably spent more time picking the phone number than I did writing the code.
Next, I needed to find a source for the content that I can count on to be renewed on a daily basis and to be of high quality. I decided to use Reddit's r/aww and r/UpliftingNews subreddits. They are two of the largest subreddits, so I should never get duplicate content. I also decided to grab the first post when sorting by top for today, which means the community has heavily upvoted the post.
I looked into the best way to fetch posts from Reddit. At first I thought I would use their API, but it turns out that Reddit has a convenient feature where you can simply append .json
to the end of a subreddit URL to receive the data as JSON: https://www.reddit.com/r/aww.json
.
This worked well, but I didn't know how to sort it by top for today rather than hot. I discovered that a query parameter does the trick: https://www.reddit.com/r/aww/top.json?t=day
.
I wrote a script to grab the top posts for both subreddits and then text them using Twilio.
Lastly, I needed a way to schedule the script to run every morning. To keep it simple, I converted my script into an AWS Lambda function and set up a CloudWatch Events rule that triggers on a schedule to fire the function every day at 10 a.m. UTC. The schedule expression is: cron(0 10 * * ? *)
.
This was a relatively simple project, but I'm looking forward to seeing what I get every morning!
Top comments (0)