Spaces:
Runtime error
Runtime error
File size: 4,418 Bytes
9c8a073 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This part only runs periodically for updating infos"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install schedule"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import schedule\n",
"import time\n",
"\n",
"def my_periodic_function():\n",
" print(\"This function runs periodically!\")\n",
"\n",
"# Schedule the function to run every 1 minute\n",
"schedule.every(1).minutes.do(my_periodic_function)\n",
"\n",
"# Run the scheduler\n",
"while True:\n",
" schedule.run_pending()\n",
" time.sleep(1) # Optional: Sleep to avoid high CPU usage\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/pedro/.local/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'vodafone.pt'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
" warnings.warn(\n",
"/home/pedro/.local/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.vodafone.pt'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
" warnings.warn(\n",
"Fetching pages: 38%|###8 | 2015/5279 [08:18<10:50, 5.01it/s] Error fetching https://www.vodafone.pt/ajuda/artigos/despiste-de-problemas-fixo/Internet/nao-sei-a-minha-password-ou-o-nome-da-rede-wi-fi.html with attempt 1/3: Server disconnected. Retrying...\n",
"Fetching pages: 49%|####8 | 2579/5279 [09:58<13:25, 3.35it/s]Error fetching https://www.vodafone.pt/press-releases/2015/10/fox-play-chega-hoje-a-tv-box-da-vodafone.html with attempt 1/3: Server disconnected. Retrying...\n",
"Fetching pages: 55%|#####5 | 2929/5279 [10:57<09:42, 4.03it/s]Error fetching https://www.vodafone.pt/press-releases/2009/5/geota-fundacao-vodafone-e-c-m-loures-apelam-a-criacao-de-corredores-verdes.html with attempt 1/3: Server disconnected. Retrying...\n",
"Fetching pages: 100%|##########| 5279/5279 [18:02<00:00, 4.88it/s]\n"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": [
"import nest_asyncio\n",
"\n",
"nest_asyncio.apply()\n",
"\n",
"from langchain.document_loaders import SitemapLoader\n",
"\n",
"from bs4 import BeautifulSoup\n",
"\n",
"import re\n",
"\n",
"# Wrap the function in a list\n",
"filter_urls = ['^(?!https:\\/\\/www\\.vodafone\\.ptpesquisa$)(https?|ftp):\\/\\/[^\\s/$.?#].[^\\s]*$'] #remove https://www.vodafone.ptpesquisas\n",
"\n",
"sitemap_loader = SitemapLoader(\n",
" web_path=\"https://vodafone.pt/sitemap.xml\",\n",
" filter_urls=filter_urls,\n",
")\n",
"\n",
"sitemap_loader.requests_per_second = 10\n",
"# Optional: avoid `[SSL: CERTIFICATE_VERIFY_FAILED]` issue\n",
"sitemap_loader.requests_kwargs = {\"verify\": False}\n",
"\n",
"docs = sitemap_loader.load()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"docs"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|