diff --git a/api-analysis.py b/api-analysis.py
new file mode 100644
index 0000000..8ce5997
--- /dev/null
+++ b/api-analysis.py
@@ -0,0 +1,17 @@
+from flask import Flask, request, jsonify
+from app import performm_analyses
+
+app = Flask(__name__)
+
+# #Developing an api end point that will trigger the analysis script
+@app.route('/api/analyze', methods=['POST'])
+def analyze_data():
+ # Get the data from the request
+ data = request.get_data(as_text=True)
+ # Perform analyses
+ results = perform_analyses(data)
+ # Return the analysis results as JSON
+ return jsonify(results)
+
+if __name__ == '__main__':
+ app.run(debug=True)
diff --git a/templates/test.html b/templates/test.html
index 92604ae..e69de29 100644
--- a/templates/test.html
+++ b/templates/test.html
@@ -1,11 +0,0 @@
-{% extends 'base.html' %}
-
-{% set active_page = "results" %}
-
-{% block content %}
-
Get your analysis here!
-{% endblock %}
-
-{% block title %}
- Results
-{% endblock %}
diff --git a/test.ipynb b/test.ipynb
new file mode 100644
index 0000000..31569c6
--- /dev/null
+++ b/test.ipynb
@@ -0,0 +1,85 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from flask import Flask, request, jsonify\n",
+ "import json\n",
+ "import pandas as pd\n",
+ "import matplotlib.pyplot as plt\n",
+ "from io import StringIO\n",
+ "import csv"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "app = Flask(__name__)\n",
+ "\n",
+ "def perform_analyses(data):\n",
+ " try:\n",
+ " is_json = False\n",
+ " is_csv = False\n",
+ " # Try to parse as JSON\n",
+ " try:\n",
+ " data = json.loads(data)\n",
+ " is_json = True\n",
+ " except json.JSONDecodeError:\n",
+ " pass\n",
+ " # If JSON parsing failed, try parsing as CSV\n",
+ " if not is_json:\n",
+ " try:\n",
+ " # If the data has headers\n",
+ " data = list(csv.DictReader(StringIO(data)))\n",
+ " is_csv = True\n",
+ " except csv.Error:\n",
+ " pass\n",
+ " if not is_json and not is_csv:\n",
+ " raise ValueError(\"The data format is not supported.\")\n",
+ " if is_json and not isinstance(data, list):\n",
+ " raise ValueError(\"The data should be formatted as a list of objects.\")\n",
+ " df = pd.DataFrame(data)\n",
+ " # Perform analyses\n",
+ " total_websites = df.shape[0]\n",
+ " average_char_count = df['char_count'].mean()\n",
+ " average_image_count = df['image_count'].mean()\n",
+ " # Generate histograms\n",
+ " char_count_hist = df['char_count'].hist(bins=50).get_figure()\n",
+ " image_count_hist = df['image_count'].hist(bins=50).get_figure()\n",
+ " # Save histograms as images\n",
+ " char_count_hist.savefig('char_count_hist.png')\n",
+ " image_count_hist.savefig('image_count_hist.png')\n",
+ " # Return analysis results\n",
+ " return {\n",
+ " 'total_websites': total_websites,\n",
+ " 'average_char_count': average_char_count,\n",
+ " 'average_image_count': average_image_count\n",
+ " }\n",
+ " except ValueError as e:\n",
+ " return str(e)\n",
+ "\n",
+ "@app.route('/api/analyze', methods=['POST'])\n",
+ "def analyze_data():\n",
+ " # Get the data from the request\n",
+ " data = request.get_data(as_text=True)\n",
+ " # Perform analyses\n",
+ " results = perform_analyses(data)\n",
+ " # Return the analysis results as JSON\n",
+ " return jsonify(results)\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/test/test_analysis.py b/test/test_analysis.py
deleted file mode 100644
index 5ebb1ef..0000000
--- a/test/test_analysis.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import unittest
-from selenium import webdriver
-from selenium.webdriver.common.by import By
-from selenium.webdriver.support.ui import WebDriverWait
-from selenium.webdriver.support import expected_conditions as EC
-from selenium.common.exceptions import TimeoutException
-
-class FlaskJSTest(unittest.TestCase):
- def setUp(self):
- self.driver = webdriver.Chrome()
- self.driver.get("http://localhost:5000/results")
-
- def test_javascript_function(self):
- wait = WebDriverWait(self.driver, 5)
-
- try:
- output_element = wait.until(EC.visibility_of_element_located((By.ID, 'output-element')))
- self.assertEqual(output_element.text, 'START ANALYSIS')
-
- except TimeoutException:
- print("Timeout occurred while waiting for the element to be visible.")
-
- except Exception as e:
- print(str(e))
-
- def tearDown(self):
- self.driver.quit()
-
-if __name__ == '__main__':
- unittest.main()
\ No newline at end of file