avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1847

Abstract

         </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*5rujoKBIegDTG1eBgwpfww.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><h1 id="cfbc">Don’t tell me medium writers don’t write with emotion</h1><p id="495b">I can be funny too, albeit unintentionally:</p><div id="1f60" class="link-block">
      <a href="https://readmedium.com/is-he-a-handyman-ca25fea7776f">
        <div>
          <div>
            <h2>Is he a handyman?</h2>
            <div><h3>Has he cracked open a book or two in his lifetime?</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*Lnv-Fka8JTKgHcquNWVoCg.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><p id="3278">To my astonishment, three people (all men) found this hysterical:</p><div id="af9d" class="link-block">
      <a href="https://readmedium.com/let-not-this-happen-to-you-b195f417e26d">
        <div>
          <div>
            <h2>Don’t Get Fucked Over</h2>
            <div><h3>Warning: Stay away from a woman like this. ¶

Open letter to Prussian Blue ¶

Hey, I hope none of this happens to you…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nURHYmXFjhV82s05NrAGyg.jpeg)"></div> </div> </div> </a> </div><p id="45b5">Can you see me here? Do you think this really happened? Or is it some bullshit fluff I spewed out to entertain the masses?</p><div id="9b6b" class="link-block">

Options

      <a href="https://readmedium.com/you-broke-me-and-you-left-me-for-dead-9b92de2aa619">
        <div>
          <div>
            <h2>You Broke Me And You Left Me For Dead</h2>
            <div><h3>You will never let me be happy, you will never leave me be.</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*UA3LpM8WT6OiVwS90to1kw.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><p id="1a51">And there’s plenty more where that came from:</p><div id="87bf" class="link-block">
      <a href="https://readmedium.com/happy-fucking-mothers-day-you-cruel-selfish-woman-e227e255604d">
        <div>
          <div>
            <h2>Happy Fucking Mother’s Day</h2>
            <div><h3>Happy Mother’s Day, You Cruel Excuse for a Parent ¶</h3></div>
            <div><p></p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*lCE42VvYVz2BxcbwFUl-rg.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><p id="202d">I have simply blocked the worst of the listicle authors and advice-givers. Unfollow just wasn’t cutting it.</p><p id="c178">I do hope you like my stories and I would be ecstatic if you were to respond to any of them.</p><p id="4e9e">Mother of Fuckin’ Jesus, I have pecked out a whole story on my phone and I haven’t even gotten out of bed yet.</p><p id="2085">Yes, it’s a first draft ;-).</p><p id="5d05">What? My cut-out-the-sermonizing comment got twenty views in a couple of hours?</p><p id="2000">Yes, that was a cranking-up of the shameless-self-promotion engine.</p></article></body>

PYTHON — Creating A New Python Package

The Internet is becoming the town square for the global village of tomorrow. — Bill Gates

Insights in this article were refined using prompt engineering methods.

PYTHON — Migrating Sqlite With Python

# Creating a New Python Package

In this tutorial, you’ll learn how to create a new Python package that you can later publish to PyPI. The package consists of five files: config.txt, __main__.py, __init__.py, feed.py, and viewer.py. I'll guide you through each of these files and explain their purpose.

Let’s start by creating a new folder for your package. Inside this folder, you’ll create the following files: config.txt, __main__.py, __init__.py, feed.py, and viewer.py.

config.txt

# config.txt

[feed]
url = https://realpython.com/atom.xml

The config.txt file is a configuration file used to specify the URL of the feed of Real Python tutorials. It contains key-value pairs separated into sections, with this particular file containing only one section (feed) and one key (url).

main.py

# __main__.py

from configparser import ConfigParser
from importlib import resources  # Python 3.7+
import sys

from reader import feed
from reader import viewer

def main():
    """Read the Real Python article feed"""
    cfg = ConfigParser()
    cfg.read_string(resources.read_text("reader", "config.txt"))
    url = cfg.get("feed", "url")

    if len(sys.argv) > 1:
        article = feed.get_article(url, sys.argv[1])
        viewer.show(article)
    else:
        site = feed.get_site(url)
        titles = feed.get_titles(url)
        viewer.show_list(site, titles)

if __name__ == "__main__":
    main()

The __main__.py file acts as the entry point of the program and takes care of the main flow, calling other parts as needed. It reads the URL of the Real Python feed from the config file and then either shows a specific article or lists all articles based on the command-line arguments.

init.py

# __init__.py

__version__ = "1.0.0"

The __init__.py file represents the root of your package. It holds the __version__ variable, which is a convention in Python for adding version numbers to your package.

feed.py

# feed.py

import feedparser
import html2text

_CACHED_FEEDS = dict()

def _feed(url):
    """Only read a feed once, by caching its contents"""
    if url not in _CACHED_FEEDS:
        _CACHED_FEEDS[url] = feedparser.parse(url)
    return _CACHED_FEEDS[url]

def get_site(url):
    """Get name and link to web site of the feed"""
    info = _feed(url).feed
    return f"{info.title} ({info.link})"

def get_titles(url):
    """List titles in feed"""
    articles = _feed(url).entries
    return [a.title for a in articles]

def get_article(url, article_id):
    """Get article from feed with the given ID"""
    articles = _feed(url).entries
    article = articles[int(article_id)]
    html = article.content[0].value
    text = html2text.html2text(html)
    return f"# {article.title}\n\n{text}"

The feed.py file contains functions for reading from a web feed and parsing the result. It interacts with external libraries like feedparser and html2text to achieve this.

viewer.py

# viewer.py

def show(article):
    """Show one article"""
    print(article)

def show_list(site, titles):
    """Show list of articles"""
    print(f"The latest tutorials from {site}")
    for article_id, title in enumerate(titles):
        print(f"{article_id:>3} {title}")

The viewer.py file contains functions for displaying articles and lists of articles. It provides a simple interface for printing the data to the terminal.

Now that you’ve set up the base structure for your package, you can add some configuration to prepare your package for publication. This tutorial demonstrates how to create a package from scratch, including the necessary files and their content. Happy coding!

PYTHON — Python Sockets Part 1 Overview

Creating
Python
Package
New
Recommended from ReadMedium