This project is a serverless application designed to scrape football news from Reddit, filter relevant posts, generate engaging headlines using OpenAI, and post updates on Twitter.
root
├── index.js
├── auth
│ └── reddit
│ └── getAccessToken.js
├── handlers
│ ├── checkDb.js
│ ├── filterPosts.js
│ ├── getHeadlines.js
│ ├── getPosts.js
│ └── tweetUpdates.js
└── .env
- index.js: Main entry point of the application.
- auth/reddit/getAccessToken.js: Handles authentication to Reddit API.
- handlers/checkDb.js: Checks the database for existing entries and saves new ones.
- handlers/filterPosts.js: Filters Reddit posts by specific flairs and excludes unwanted domains.
- handlers/getHeadlines.js: Uses OpenAI to generate Bloomberg-style headlines.
- handlers/getPosts.js: Retrieves recent posts from Reddit.
- handlers/tweetUpdates.js: Tweets the generated headlines using Twitter API.
- .env: Environment variables configuration file.
-
Clone the repository:
git clone https://github.com/yourusername/football-news-bot.git cd football-news-bot
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add the necessary environment variables:REDDIT_CLIENT_ID=your_reddit_client_id REDDIT_CLIENT_SECRET=your_reddit_client_secret MONGO_DB_PASS=your_mongodb_password OPEN_AI_KEY=your_openai_key TWITTER_CONSUMER_KEY=your_twitter_consumer_key TWITTER_CONSUMER_SECRET=your_twitter_consumer_secret TWITTER_ACCESS_TOKEN=your_twitter_access_token TWITTER_TOKEN_SECRET=your_twitter_token_secret
To run the project, use the following command:
serverless deploy
-
Reddit Authentication:
const getAccessToken = require("./auth/reddit/getAccessToken");
-
Get Posts from Reddit:
const getPosts = require("./handlers/getPosts");
-
Filter Posts:
const filterPosts = require("./handlers/filterPosts");
-
Check Database:
const checkDb = require("./handlers/checkDb");
-
Generate Headlines:
const getHeadlines = require("./handlers/getHeadlines");
-
Tweet Updates:
const tweetUpdates = require("./handlers/tweetUpdates");
- Main Function: The
main
function inindex.js
orchestrates the workflow:- Retrieve Reddit access token.
- Fetch posts from Reddit.
- Filter posts based on predefined criteria.
- Check the database for new entries.
- Generate headlines using OpenAI.
- Post updates to Twitter.
async function main() {
const accessToken = await getAccessToken();
const posts = await getPosts(accessToken);
const filteredPosts = filterPosts(posts);
if (filteredPosts.length === 0) return console.log("No relevant posts.");
const titles = filteredPosts.map((post) => ({
title: post.data.title,
url: post.data.url,
}));
const updates = await checkDb(titles);
if (updates.length === 0) return console.log("No new updates.");
const headlines = await getHeadlines(updates);
console.log(headlines);
await tweetUpdates(headlines);
}
module.exports.handler = main;
Feel free to open issues or submit pull requests if you find any bugs or have suggestions for improvements.
This project is licensed under the MIT License.
For further information or assistance, please contact Emiliano Bonezzi.
Happy coding!