Skip to content

Instantly share code, notes, and snippets.

@adagio
Created November 14, 2018 04:18
Show Gist options
  • Save adagio/a2f4b8e5ef8b225a3cbb870ad29f3eca to your computer and use it in GitHub Desktop.
Save adagio/a2f4b8e5ef8b225a3cbb870ad29f3eca to your computer and use it in GitHub Desktop.
enums-switch.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "enums-switch.ipynb",
"version": "0.3.2",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/adagio/a2f4b8e5ef8b225a3cbb870ad29f3eca/enums-switch.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"metadata": {
"id": "XaXrVUKrbjSH",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Enum"
]
},
{
"metadata": {
"id": "YJaToC4caBiv",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"class ContentMode(enum.Enum):\n",
" content_attribute = 0\n",
" ext = 1"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "s8FeLelhbrek",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Fórmula"
]
},
{
"metadata": {
"id": "opjvU4KGbmK1",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"formulas = [\n",
" {\n",
" 'fkey': 'title',\n",
" 'html_pattern': 'meta[itemprop=\"name\"]',\n",
" 'content_mode': ContentMode.content_attribute\n",
" },\n",
" {\n",
" 'fkey': 'desc',\n",
" 'html_pattern': 'meta[itemprop=\"description\"]',\n",
" 'content_mode': ContentMode.content_attribute\n",
" },\n",
" {\n",
" 'fkey': 'url',\n",
" 'html_pattern': 'meta[itemprop=\"url\"]',\n",
" 'content_mode': ContentMode.content_attribute\n",
" },\n",
" {\n",
" 'fkey': 'episode',\n",
" 'html_pattern': '.microphone',\n",
" 'content_mode': ContentMode.text\n",
" },\n",
"]"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "bfGpR6MLbp4C",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Método que incorpora una estructura de control tipo Switch"
]
},
{
"metadata": {
"id": "te52IktmbqF9",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"def get_value(tag, content_mode):\n",
" if (content_mode == ContentMode.content_attribute):\n",
" return tag.attrs['content']\n",
" elif (content_mode == ContentMode.text):\n",
" return tag.getText().strip()\n",
" else:\n",
"return None"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "V_Y3PxQ6b8DZ",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
""
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment