{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4e2a9393-7767-488e-a8bf-27c12dca35bd", "metadata": {}, "outputs": [], "source": [ "# imports\n", "\n", "import os\n", "import requests\n", "from dotenv import load_dotenv\n", "from bs4 import BeautifulSoup\n", "from IPython.display import Markdown, display\n", "from openai import OpenAI\n", "\n", "# If you get an error running this cell, then please head over to the troubleshooting notebook!" ] }, { "cell_type": "code", "execution_count": 2, "id": "7b87cadb-d513-4303-baee-a37b6f938e4d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "API key found and looks good so far!\n" ] } ], "source": [ "# Load environment variables in a file called .env\n", "\n", "load_dotenv(override=True)\n", "api_key = os.getenv('OPENAI_API_KEY')\n", "\n", "# Check the key\n", "\n", "if not api_key:\n", " print(\"No API key was found - please head over to the troubleshooting notebook in this folder to identify & fix!\")\n", "elif not api_key.startswith(\"sk-proj-\"):\n", " print(\"An API key was found, but it doesn't start sk-proj-; please check you're using the right key - see troubleshooting notebook\")\n", "elif api_key.strip() != api_key:\n", " print(\"An API key was found, but it looks like it might have space or tab characters at the start or end - please remove them - see troubleshooting notebook\")\n", "else:\n", " print(\"API key found and looks good so far!\")\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "c5e793b2-6775-426a-a139-4848291d0463", "metadata": {}, "outputs": [], "source": [ "# A class to represent a Webpage\n", "# If you're not familiar with Classes, check out the \"Intermediate Python\" notebook\n", "\n", "# Some websites need you to use proper headers when fetching them:\n", "headers = {\n", " \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36\"\n", "}\n", "\n", "class Website:\n", "\n", " def __init__(self, url):\n", " \"\"\"\n", " Create this Website object from the given url using the BeautifulSoup library\n", " \"\"\"\n", " self.url = url\n", " response = requests.get(url, headers=headers)\n", " soup = BeautifulSoup(response.content, 'html.parser')\n", " self.title = soup.title.string if soup.title else \"No title found\"\n", " for irrelevant in soup.body([\"script\", \"style\", \"img\", \"input\"]):\n", " irrelevant.decompose()\n", " self.text = soup.body.get_text(separator=\"\\n\", strip=True)" ] }, { "cell_type": "code", "execution_count": 4, "id": "7c7e0988-8f2d-4844-a847-eebec76b114a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Give short summary of the business Home\n", "Screens\n", "Tools\n", "Login\n", "Home\n", "Screens\n", "Tools\n", "Create a stock screen\n", "Run queries on 10 years of financial data\n", "Premium features\n", "Commodity Prices\n", "See prices and trends of over 10,000 commodities\n", "Search shareholders\n", "See companies where a person holds over 1% of the shares\n", "Latest Announcements\n", "Browse, filter and set alerts for announcements.\n", "Upgrade to premium\n", "Login\n", "Get free account\n", "CMS Info Systems Ltd\n", "Notebook\n", "CMS Info Systems\n", "Summary\n", "Chart\n", "Analysis\n", "Peers\n", "Quarters\n", "Profit & Loss\n", "Balance Sheet\n", "Cash Flow\n", "Ratios\n", "Investors\n", "Documents\n", "Notebook\n", "CMS Info Systems Ltd\n", "₹ 431\n", "-1.66%\n", "24 Jan\n", " \n", " - close price\n", "Export to Excel\n", "Follow\n", "cms.com\n", "BSE:\n", " 543441\n", "NSE:\n", " CMSINFO\n", "About\n", "CMS Info Systems Limited is India's largest cash management company in terms of the number of ATM points and retail pick-up points as of March 31, 2021. The company is engaged in installing, maintaining, and managing assets and technology solutions on an end-to-end outsourced basis for banks, financial institutions, organized retail and e-commerce companies in India.\n", "Key Points\n", "Leadership\n", "[1]\n", "