{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating and consuming rss feeds." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " !pip install feedparser feedgen" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ " from feedgen.feed import FeedGenerator\n", " import feedparser\n", " from pathlib import Path\n", " import ipywidgets as W\n", " from IPython.display import display, Markdown\n", " from collections import UserDict\n", " import deathbeds\n", " import pandas\n", " from sidecar import Sidecar\n", " from deathbeds.__summarizing_notebooks_with_gensim import summarize" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2963: UserWarning: Discarding nonzero nanoseconds in conversion\n", " exec(code_obj, self.user_global_ns, self.user_ns)\n", "C:\\Anaconda3\\lib\\site-packages\\nbconvert\\filters\\datatypefilter.py:41: UserWarning: Your element with mimetype(s) dict_keys(['application/literallycanvas+json']) is not able to be represented.\n", " mimetypes=output.keys())\n" ] } ], "source": [ "feed = FeedGenerator()\n", "root = Path(deathbeds.__file__).parent\n", "paths = list(root.glob('[0-9]*.ipynb'))\n", "feed.id(str(root))\n", "feed.title(deathbeds.__name__)\n", "feed.author({'name': 'deathbeds'})\n", "feed.link(href=str(root))\n", "\n", "for path in paths:\n", " stats = path.stat()\n", " entry = feed.add_entry()\n", " entry.id(str(path))\n", " entry.title(' '.join(path.name.split('-')[3:]))\n", " entry.author( {'name':'deathbeds'} )\n", " entry.link(href=str(path))\n", " entry.description(summarize(path, ratio=.05).summary)\n", " entry.updated(pandas.to_datetime(stats.st_mtime_ns, utc=True).to_pydatetime())\n", "\n", "posts = feedparser.parse(feed.atom_str())" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "df = pandas.Series(posts['entries']).apply(pandas.Series)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idguidislinklinktitletitle_detailupdatedupdated_parsedauthorsauthor_detailauthorcontentsummarylinks
45c:\\users\\deathbeds\\deathbeds.github.io\\deathbe...Truec:\\users\\deathbeds\\deathbeds.github.io\\deathbe...Tracing edges of image text.ipynb{'type': 'text/plain', 'language': None, 'base...2018-07-19T17:10:30.512923+00:00(2018, 7, 19, 17, 10, 30, 3, 200, 0)[{'name': 'deathbeds'}]{'name': 'deathbeds'}deathbeds[{'type': 'text/plain', 'language': None, 'bas...* plot the outlines over top of the labelled i...[{'href': 'c:\\users\\deathbeds\\deathbeds.github...
28c:\\users\\deathbeds\\deathbeds.github.io\\deathbe...Truec:\\users\\deathbeds\\deathbeds.github.io\\deathbe...Literate Markdown Kernel.ipynb{'type': 'text/plain', 'language': None, 'base...2018-07-26T19:52:31.588995+00:00(2018, 7, 26, 19, 52, 31, 3, 207, 0)[{'name': 'deathbeds'}]{'name': 'deathbeds'}deathbeds[{'type': 'text/plain', 'language': None, 'bas...from deathbeds.__Literate_Markdown_Kernel impo...[{'href': 'c:\\users\\deathbeds\\deathbeds.github...
\n", "
" ], "text/plain": [ " id guidislink \\\n", "45 c:\\users\\deathbeds\\deathbeds.github.io\\deathbe... True \n", "28 c:\\users\\deathbeds\\deathbeds.github.io\\deathbe... True \n", "\n", " link \\\n", "45 c:\\users\\deathbeds\\deathbeds.github.io\\deathbe... \n", "28 c:\\users\\deathbeds\\deathbeds.github.io\\deathbe... \n", "\n", " title \\\n", "45 Tracing edges of image text.ipynb \n", "28 Literate Markdown Kernel.ipynb \n", "\n", " title_detail \\\n", "45 {'type': 'text/plain', 'language': None, 'base... \n", "28 {'type': 'text/plain', 'language': None, 'base... \n", "\n", " updated updated_parsed \\\n", "45 2018-07-19T17:10:30.512923+00:00 (2018, 7, 19, 17, 10, 30, 3, 200, 0) \n", "28 2018-07-26T19:52:31.588995+00:00 (2018, 7, 26, 19, 52, 31, 3, 207, 0) \n", "\n", " authors author_detail author \\\n", "45 [{'name': 'deathbeds'}] {'name': 'deathbeds'} deathbeds \n", "28 [{'name': 'deathbeds'}] {'name': 'deathbeds'} deathbeds \n", "\n", " content \\\n", "45 [{'type': 'text/plain', 'language': None, 'bas... \n", "28 [{'type': 'text/plain', 'language': None, 'bas... \n", "\n", " summary \\\n", "45 * plot the outlines over top of the labelled i... \n", "28 from deathbeds.__Literate_Markdown_Kernel impo... \n", "\n", " links \n", "45 [{'href': 'c:\\users\\deathbeds\\deathbeds.github... \n", "28 [{'href': 'c:\\users\\deathbeds\\deathbeds.github... " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.sample(2)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ " blob = lambda x: \"\"\"# [{title}]({link})\n", " \n", " ---\n", " {summary}\n", " \n", " ---\"\"\".format(**x.to_dict())" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ " def cap(object):\n", " out = W.Output()\n", " with out: display(Markdown(object))\n", " return out" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "with Sidecar():\n", " acc = W.Accordion(children=df.apply(blob, axis =1 ).apply(cap).tolist())\n", " [acc.set_title(*object) for object in enumerate(df.title)] and acc\n", " display(acc)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }