{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# CNA MAP\n", "---" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2023-04-06T00:19:15.200839Z", "iopub.status.busy": "2023-04-06T00:19:15.200264Z", "iopub.status.idle": "2023-04-06T00:19:15.773602Z", "shell.execute_reply": "2023-04-06T00:19:15.773034Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "from IPython.core.magic import register_cell_magic\n", "from IPython.display import Markdown\n", "import datetime\n", "from datetime import date\n", "import folium\n", "from folium.plugins import MarkerCluster\n", "from geopy.geocoders import Nominatim\n", "import json\n", "import pandas as pd\n", "import time" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2023-04-06T00:19:15.776446Z", "iopub.status.busy": "2023-04-06T00:19:15.776046Z", "iopub.status.idle": "2023-04-06T00:21:37.439355Z", "shell.execute_reply": "2023-04-06T00:21:37.438831Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "\n", "\n", "with open('CNAsList.json') as f:\n", " data = json.load(f)\n", "\n", "CNA = pd.json_normalize(data)\n", "\n", "geolocator = Nominatim(user_agent=\"CNALookup\")\n", "latitude = []\n", "long = []\n", "for i in CNA[\"country\"]:\n", " if i != None:\n", " location = geolocator.geocode(i, timeout=None)\n", " if location!=None:\n", " latitude.append(location.latitude)#, location.longitude)\n", " long.append(location.longitude)\n", " else:\n", " latitude.append(float(\"Nan\"))#, location.longitude)\n", " long.append(float(\"Nan\"))\n", " else:\n", " latitude.append(float(\"Nan\"))#, location.longitude)\n", " long.append(float(\"Nan\"))\n", "\n", "CNA[\"Latitude\"] = latitude\n", "CNA[\"Longitude\"] = long" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2023-04-06T00:21:37.442406Z", "iopub.status.busy": "2023-04-06T00:21:37.441954Z", "iopub.status.idle": "2023-04-06T00:21:37.449249Z", "shell.execute_reply": "2023-04-06T00:21:37.448695Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "pattern = r'(https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}[-a-zA-Z0-9()@:%_+.~#?&/=]*)' \n", "CNA['securityAdvisories.advisories'] = CNA['securityAdvisories.advisories'].astype(str)\n", "CNA['URL'] = CNA['securityAdvisories.advisories'].str.extract(pattern, expand=False).str.strip()\n", "CNA['URL'] = CNA['URL'].astype(str)\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2023-04-06T00:21:37.451423Z", "iopub.status.busy": "2023-04-06T00:21:37.451126Z", "iopub.status.idle": "2023-04-06T00:21:37.860482Z", "shell.execute_reply": "2023-04-06T00:21:37.859982Z" }, "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "