How to Automate Mergers and Acquisitions Reports: A Guide for Developers

How to Automate Mergers and Acquisitions Reports: A Guide for Developers

If you’re a developer, especially for an automated platform company, this guide is for you. It walks you through a script we created to generate mergers and acquisitions reports automatically. Creating these reports manually takes a lot of time and energy — something few developers have. However, you can automate the report generation process with AI and some scripting. You can find links to download the script file and related materials at the bottom of this guide.

What you’ll need to run the script

News Data — You should obtain news data from a reliable source. For this guide, we’re getting the data from the Webz.io News API. It provides structured news data feeds in 170+ languages from millions of news sites. 

You need an API key to use the Webz.io News API, and you can get one by contacting Webz.io.

  • OpenAI API — You’ll use OpenAI’s API to leverage the GPT-4 and DALL·E models. GPT-4 analyzes and summarizes the text from customer reviews, while DALL·E generates a main image for the report. 
  • You also need an API key for the OpenAI API. Create an account or sign in at OpenAI to get a key. OpenAI uses pay-per-use pricing for its language and image models. You can see the price points on the OpenAI website.
  • Python — We’re using Python to automate the report creation process. You’ll need to ensure you can run Python code on your machine.  
How Webz.io and ChatGPT automate your report

Automating mergers and acquisitions reports: script breakdown

The script fetches news articles from the Webz.io News API. Next, the script calls the OpenAI API, using its text model to analyze the articles for content related to mergers and acquisitions. It then creates a structured report for each article, outputting its findings into a Word document. The script uses the OpenAI image model to generate a main image for the report. The script combines all these elements into a completed report contained in the Word document.

Here is the detailed breakdown of the script:

Import packages and modules

First, the script imports the Python packages and modules, the OpenAI Python API library, and other necessary components.

Set global variable and access API keys

Next the script accesses the API keys (Webz.io and OpenAI) through the development environment. It also includes a global variable where you can set the number of articles the script will generate a report on.

Orchestrate entire process (main)

Towards the end of the script, you’ll see the “main” function. It orchestrates the entire process — from reading the news articles and generating reports for each one to creating a main report image to finalizing the Word document.

Define functions

Now we define the different functions of our script:

Fetch news articles from Webz.io (def fetch_articles)

Makes a call to the Webz.io News API to get articles with content related to mergers and acquisitions.

Remove duplicate posts (get_unique_posts_from_webz)

Removes duplicate posts in case they exist.

Look for similar strings (are_similar)

Checks if two strings are similar based on the Levenshtein ratio.

Remove similar articles (remove_similar_strings)

Eliminates duplicate content by removing articles based on similar strings.

Trim string (trim_string)

Makes sure a string isn’t longer than max_length .

Trim article title (trim_title)

Removes irrelevant text from the title. For example, if the real title includes “- CNN News” the script will remove this phrase.

Send prompt (call_gpt_completion)

Sends a prompt to the GPT-4 model and receives a response.

Review articles and generate reports (generate_reports)

Goes through articles pulled from the Webz.io News API to determine if any contain content related to mergers and acquisitions. If an article does mention a merger or acquisition, the script generates a report for it.

Generate title (generate_title)

Creates a title for the mergers and acquisitions report.

Generate introduction (generate_intro)

Generates an introductory paragraph for the report.

HTML to formatted text (html_to_word)

Converts HTML content to formatted text in a Word document. It handles bold text and bullet lists.

Add hyperlink (add_hyperlink)

Inserts a hyperlink into a Word document paragraph.

Add title placeholder (insert_titles_in_text)

Adds a placeholder for inserting the titles.

Generate image (generate_article_image)

Generates a main image for the report using OpenAI’s DALL-E model with a specific prompt.

Download image (add_image_from_base64)

Downloads an image from a URL and adds it to a Word document.

Create Word doc (create_word_doc)

Assembles the various components into a formatted Word document.

AI + Python = a powerful automation tool

This script demonstrates an advanced use case of integrating AI-powered analysis and content generation with document automation in Python. It’s a comprehensive example of how combining various Python libraries with AI models can produce a powerful automation tool.

Download the example code and report:

  • The full Python script.

Ready to automate M&A reports for your organization? Talk to one of our experts today.

Spread the News

Not subscribed to our Dark Web Pulse updates?

By submitting you agree to Webz.io's Privacy Policy and further marketing communications.

Feed Your Machines the Data They Need

Feed Your Machines the Data They Need

GET STARTED
Has Your Data Been Breached?

Find breaches, stolen credentials and malware risks on the deep and dark web.

Subscribe to our newsletter for more news and updates!

Ready to Explore Web Data at Scale?

Speak with a data expert to learn more about Webz.io’s solutions
Create your API account and get instant access to millions of web sources