Extract key events on a certain date from Wikipedia


Get Started

Not the template you're looking for? Browse more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnGenericSyncHttpEvent
Sync HTTP Event

README


📋 Overview

Pull a list of key events documented on Wikipedia that occured on a specific date.

🖊️ Setup

  • Setup the API connection with our Generic Connector.
    • In your generic connector add https://en.wikipedia.org/api/rest_v1 as a Base URL and save.
  • Change the values in the Parameters to a meaningful date for you. If you don't add Parameters, the script will use the current date.

🚀 Using the template

Simply press on the play button by the OnThisDay script to run it manually.

Viewing the events

  • You can view a list of all the events in the console
  • You can view the events in a summary page: Access the summary page by copying/pasting the link from the Sync HTTP event listener into your browser. The summary includes:
    • Year
    • Link to Wikipedia Page
    • Summary of the event

API Connections


TypeScriptOnGenericSyncHttpEvent

import { HttpEventRequest, HttpEventResponse, buildHTMLResponse } from '@sr-connect/generic-app/events/http';
import { Event, fetchEvents, getCurrentDayAndMonth } from './OnThisDay';


/**
 * Entry point to Sync HTTP Event event
 *
 * @param event Object that holds Sync HTTP Event event data
 * @param context Object that holds function invocation context data
 */
export default async function (event: HttpEventRequest, context: Context<EV>): Promise<HttpEventResponse> {
    // Extract parameters
    const { DAY, MONTH } = context.environment.vars;

    // Use function to get the current day and month if not provided
    const { day, month } = getCurrentDayAndMonth(DAY, MONTH);

    try {
        // Fetch events based on the provided day and month
        const events = await fetchEvents(day, month);

        // Build and return the HTML response
        return buildHTMLResponse(getHtml(events, day, month));
    } catch (error) {
        // Log the error if something goes wrong
        console.error("Error occurred while fetching events or generating HTML:", error);

        // Return an error message response
        return buildHTMLResponse(`
            <h1>Error</h1>
            <p>Sorry, something went wrong while fetching historical events.</p>
        `);
    }
}

/**
 * Generates the HTML markup for displaying events on the specified date
 */
function getHtml(events: Event[], day: string, month: string) {
    return `
        <meta charset="UTF-8">
        <h1 style="padding: 25px; padding-bottom: 10px; font-family: helvetica;">Historical Events on ${day}.${month}</h1>
        <p style="padding: 10px 20px; font-family: helvetica;">
            Here are some notable events that happened on this day in history:
        </p>
        <ul style="font-family: helvetica; padding-left: 50px;">
            ${events.length > 0
            ? events.map(event => `
                    <li>
                        <b>${event.year}:</b> 
                        ${event.link ? `<a href="${event.link}" target="_blank">${event.title}</a>` : event.title} - ${event.text}
                    </li>`).join("")
            : "<li>No events found for today.</li>"
        }
        </ul>
    `;
}

TypeScriptOnThisDay

import Generic from './api/generic';
import dayjs from "dayjs";

export default async function (event: any, context: Context<EV>): Promise<void> {
    // Extract parameters
    const { DAY, MONTH } = context.environment.vars;

    // Use function to get the current day and month if not provided
    const { day, month } = getCurrentDayAndMonth(DAY, MONTH);

    try {
        // Fetch events based on the provided day and month
        const events = await fetchEvents(day, month);

        // Log out the total number of events and the events themselves
        console.log(`Total number of events: ${events.length}.`, events);
    } catch (error) {
        // Log the error if something goes wrong
        console.error("Error fetching events:", error);
    }
}


/**
 * Function that fetches events from the Wikipedia API based on the date provided
 */
export async function fetchEvents(day: string, month: string): Promise<Event[]> {
    
    // Fetch events using Wikipedia API
    const result = await Generic.fetch(`/feed/onthisday/events/${month}/${day}`);

    const response: WikipediaResponse = await result.json();

    // Check if the response has events
    if (!response.events) {
        // If not then throw an error
        throw new Error(`Unexpected response: Status: ${result.statusText}. ${response.detail ?? response.title}.`);
    }

    // Extract year, title, event text and first Wikipedia link
    return response.events.map((item: any) => ({
        year: item.year,
        title: item.pages[0]?.titles.normalized ?? 'N/A',
        text: item.text,
        link: item.pages[0]?.content_urls.desktop.page ?? ''
    }));
}

/**
 * Function to get day and month, using current date if not provided
 */
export function getCurrentDayAndMonth(day?: string, month?: string) {
    const today = dayjs();
    return {
        day: day || today.format('D'),
        month: month || today.format('M'),
    };
}


export interface Event {
    year: number;
    title: string;
    text: string;
    link?: string;
}


interface WikipediaResponse extends ErrorResponse {
    events: {
        year: number;
        text: string;
        pages: {
            titles: {
                normalized: string;
            };
            content_urls: {
                desktop: {
                    page: string;
                };
            };
        }[];
    }[];
}

interface ErrorResponse {
    detail?: string;
    title: string
}

© 2025 ScriptRunner · Terms and Conditions · Privacy Policy · Legal Notice