txtv

Swiss text tv in the terminal, forked from https://github.com/voidcase/txtv
git clone https://git.in0rdr.ch/txtv.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

listing_test.ipynb (4019B)


      1 {
      2  "cells": [
      3   {
      4    "cell_type": "code",
      5    "execution_count": 1,
      6    "metadata": {},
      7    "outputs": [],
      8    "source": [
      9     "import txtv\n",
     10     "import listing as ls\n",
     11     "import bs4\n",
     12     "import re"
     13    ]
     14   },
     15   {
     16    "cell_type": "code",
     17    "execution_count": 2,
     18    "metadata": {},
     19    "outputs": [],
     20    "source": [
     21     "inr = txtv.get_page(101)[0]"
     22    ]
     23   },
     24   {
     25    "cell_type": "code",
     26    "execution_count": 3,
     27    "metadata": {},
     28    "outputs": [
     29     {
     30      "name": "stdout",
     31      "output_type": "stream",
     32      "text": [
     33       " 101 SVT Text        Torsdag 17 jan 2019\n",
     34       " \u001b[34m \u001b[0m\u001b[34m                                      \u001b[0m\n",
     35       " \u001b[34m \u001b[0m\u001b[34m                           \u001b[0m\u001b[34m           \u001b[0m\n",
     36       " \u001b[34m \u001b[0m\u001b[34m                          \u001b[0m\u001b[34m \u001b[0m\u001b[34mSVT Text   \u001b[0m\n",
     37       "                                        \n",
     38       " \u001b[34m \u001b[0m\u001b[34m \u001b[0m\u001b[34m* = efter kl 12     Nyhetsrullen 188 \u001b[0m\n",
     39       "                                        \u001b[0m\n",
     40       "* S och SD har ökat sedan valet......106\u001b[0m\n",
     41       "* Opinionen enligt Novus mätning....160-\u001b[0m\n",
     42       "                                        \u001b[0m\n",
     43       "* Novus: Förtroenderas för politiker 107\u001b[0m\n",
     44       "* SD- och M-väljare mest kritiska....108\u001b[0m\n",
     45       "                                        \u001b[0m\n",
     46       "* Fler MP-profiler hoppar av.........109\u001b[0m\n",
     47       "                                        \u001b[0m\n",
     48       "* Migrationsministern S EU-kandidat..110\u001b[0m\n",
     49       "                                        \u001b[0m\n",
     50       "* Höjt skadestånd efter terrordådet..111\u001b[0m\n",
     51       "                                        \u001b[0m\n",
     52       "* Städade utan tillstånd hos polisen 112\u001b[0m\n",
     53       "                                        \u001b[0m\n",
     54       "                                        \u001b[0m\n",
     55       "          \u001b[2m \u001b[0m\u001b[2m \u001b[0mFler rubriker 102  \u001b[0m \u001b[0m        \u001b[0m\n",
     56       " \u001b[34m \u001b[0m\u001b[34m \u001b[0m\u001b[34mUtrikes 104  Sport 300  Innehåll 700 \u001b[0m\n"
     57      ]
     58     }
     59    ],
     60    "source": [
     61     "txtv.show_page(inr)"
     62    ]
     63   },
     64   {
     65    "cell_type": "code",
     66    "execution_count": 5,
     67    "metadata": {},
     68    "outputs": [
     69     {
     70      "data": {
     71       "text/plain": [
     72        "['S och SD har ökat sedan valet......106',\n",
     73        " 'Opinionen enligt Novus mätning....160-',\n",
     74        " 'Novus: Förtroenderas för politiker 107',\n",
     75        " 'SD- och M-väljare mest kritiska....108',\n",
     76        " 'Fler MP-profiler hoppar av.........109',\n",
     77        " 'Migrationsministern S EU-kandidat..110',\n",
     78        " 'Höjt skadestånd efter terrordådet..111',\n",
     79        " 'Städade utan tillstånd hos polisen 112']"
     80       ]
     81      },
     82      "execution_count": 5,
     83      "metadata": {},
     84      "output_type": "execute_result"
     85     }
     86    ],
     87    "source": [
     88     "entries = []\n",
     89     "for n in inr.children:\n",
     90     "    if isinstance(n, str):\n",
     91     "        #print(n, end='')\n",
     92     "        pass\n",
     93     "    elif isinstance(n, bs4.element.Tag):\n",
     94     "        if 'bgB' not in n.attrs['class'] and 'bgY' not in n.attrs['class']:\n",
     95     "            entries.append(n.get_text())\n",
     96     "entries = [e for e in entries if not re.fullmatch(' *', e)]\n",
     97     "entries"
     98    ]
     99   },
    100   {
    101    "cell_type": "code",
    102    "execution_count": null,
    103    "metadata": {},
    104    "outputs": [],
    105    "source": []
    106   }
    107  ],
    108  "metadata": {
    109   "kernelspec": {
    110    "display_name": "Python 3",
    111    "language": "python",
    112    "name": "python3"
    113   },
    114   "language_info": {
    115    "codemirror_mode": {
    116     "name": "ipython",
    117     "version": 3
    118    },
    119    "file_extension": ".py",
    120    "mimetype": "text/x-python",
    121    "name": "python",
    122    "nbconvert_exporter": "python",
    123    "pygments_lexer": "ipython3",
    124    "version": "3.7.2"
    125   }
    126  },
    127  "nbformat": 4,
    128  "nbformat_minor": 2
    129 }