This project provides an API endpoint to fetch and summarize game patch notes. It utilizes cheerio
for HTML parsing and the Google Gemini API for generating concise summaries.
- Fetches raw HTML patch notes from a specified endpoint.
- Extracts and cleans relevant patch information from the HTML.
- Summarizes important changes into a single, clear paragraph using the Google Gemini API.
- Provides a simple RESTful API endpoint for easy access.
- Express.js: Fast, unopinionated, minimalist web framework for Node.js.
- dotenv: Loads environment variables from a
.env
file. - @google/generative-ai: Google Gemini API client library.
- cors: Middleware to enable Cross-Origin Resource Sharing.
- cheerio: Fast, flexible, and lean implementation of core jQuery specifically designed for the server.
Follow these steps to set up and run the project locally.
Make sure you have the following installed:
- Node.js (LTS recommended)
- npm or Yarn
-
Clone the repository:
git clone https://github.com/AmarMuric04/dbd-patch-summarizer cd dbd-patch-summarizer
-
Install dependencies:
npm install # or yarn install
-
Create a
.env
file:Create a file named
.env
in the root directory of the project and add the following environment variables:GEMINI_API_KEY=${geminiApiKeyPlaceholder} ENDPOINT=${endpointPlaceholder} PORT=${portPlaceholder} # Or any port you prefer
GEMINI_API_KEY
: Obtain your API key from the Google AI Studio.ENDPOINT
: This should be the base URL for your patch notes, where appending the patch number will fetch the specific patch notes (e.g.,https://example.com/patches/
).PORT
: The port on which the API server will listen.
To start the development server, run:
npm start
# or
yarn start
The API will be accessible at http://localhost:PORT
.
Retrieves a summarized version of the patch notes for a given patch number.
patch
(optional): The patch number to retrieve. Defaults to510
if not provided.
curl "http://localhost:${portPlaceholder}/patches?patch=510"
Patch 510 introduces significant balance adjustments across various game elements. Several items have undergone statistical modifications, impacting their effectiveness in combat and utility. Character abilities have been refined, with specific skills receiving numerical tweaks to damage, cooldowns, or resource costs. Furthermore, the update includes general system optimizations aimed at improving overall game performance and stability.
{
"message": "Patch notes not found for the specified patch."
}
Or
Failed to fetch or parse HTML
This is the main entry point of the application, setting up the Express server and defining the /patches
route.
extractPatchNotes(html: string)
: This function usescheerio
to parse the input HTML, remove unwanted elements (like embeds, links, images), convert<strong>
tags to Markdown bold, and extracth2
,h3
,p
, andli
tags into a clean Markdown-like string./patches
Endpoint:- Fetches the HTML content from the
ENDPOINT
based on thepatch
query parameter. - Calls
extractPatchNotes
to clean the raw HTML. - Sends the cleaned text to the Google Gemini API (model
gemini-2.0-flash-exp
) with a prompt to summarize the content into a single, clear paragraph, starting with "Patch [patch-id]". - Returns the summarized text as the API response.
- Includes error handling for network issues or parsing failures.
- Fetches the HTML content from the
Feel free to open issues or submit pull requests if you have suggestions or improvements.