{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Download various data formats from the internet using the Python `requests` library and save them to disk.\n",
    "\n",
    "Data formats:\n",
    "  - XML\n",
    "  - CSV\n",
    "  - Image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "from pathlib import Path\n",
    "\n",
    "data_folder = Path('data')\n",
    "data_folder.mkdir(exist_ok=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# XML\n",
    "# TEI-XML file from the Blotius edition (https://edition.onb.ac.at/blotius)\n",
    "xml_data = requests.get('https://edition.onb.ac.at/blotius/o:blo.inventar-mz/datastreams/TEI_SOURCE/content')\n",
    "\n",
    "with open(data_folder / 'tei-xml_example.xml', 'wb') as file:\n",
    "    file.write(xml_data.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CSV\n",
    "# Historic postcards metadata sheet\n",
    "\n",
    "csv_data = requests.get('https://labs.onb.ac.at/gitlab/labs-team/raw-metadata/-/raw/master/akon_postcards_public_domain.csv.bz2?ref_type=heads&inline=false')\n",
    "\n",
    "with open(data_folder / 'csv_example.csv.bz2', 'wb') as file:\n",
    "    file.write(csv_data.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Image\n",
    "# Stock image from pexels.com\n",
    "img_data = requests.get('https://images.pexels.com/photos/572056/pexels-photo-572056.jpeg?cs=srgb&dl=pexels-serpstat-572056.jpg&fm=jpg&w=5664&h=3778')\n",
    "\n",
    "with open(data_folder / 'image_example.jpg', 'wb') as file:\n",
    "    file.write(img_data.content)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}