601
10
602
8

I'm getting errors with this function:

def compare_dates(date1: str, date2: str) -> str:
    date1_obj = datetime.strptime(date1, "%Y-%m-%dT%H:%M:%S")
    date2_obj = datetime.strptime(date2, "%Y-%m-%dT%H:%M:%S")
    return date1 if date1_obj > date2_obj else date2

Because the input sometimes includes microseconds. Is there a clearer way of dealing with this than what I've done?

def compare_dates(date1: str, date2: str) -> str:
    date_format = "%Y-%m-%dT%H:%M:%S"
    date1_obj = datetime.strptime(date1.split(".")[0], date_format)
    date2_obj = datetime.strptime(date2.split(".")[0], date_format)
    date1_obj = date1_obj.replace(microsecond=0)
    date2_obj = date2_obj.replace(microsecond=0)
    return date1 if date1_obj > date2_obj else date2
603
7
604
72
Python Cheatsheet (gto76.github.io)
submitted 3 years ago by eevee@lemm.ee to c/python@programming.dev
605
2
606
-1
607
8

To be clear, this was released on 11 July 2023.

608
14
609
8
610
16
Flood Fill Mazes (excess.org)
611
12
submitted 3 years ago* (last edited 3 years ago) by Devos@programming.dev to c/python@programming.dev

Hi Python enthusiastic! I'm excited to share my latest project! The Datalookup 🔍 library makes it easier to filter and manipulate your data. The module is inspired by the Django Queryset Api and it's lookups.

I'm actively seeking people to join in and help make this library even better! Whether you have ideas for new features, bug fixes, or improvements in documentation, anyone can contribute to Datalookup's development.

Github: https://github.com/pyshare/datalookup

612
29
submitted 3 years ago* (last edited 3 years ago) by GodOfThunder@lemm.ee to c/python@programming.dev

I've tried using pythorhead

search_results = lemmy.search(post_url)

but I get

AttributeError: 'Lemmy' object has no attribute 'search'

I've also tried requesting it myself but I don't get any results from the API even when I get it when searching for the same URL from the web interface.

@backoff.on_exception(
    backoff.expo,
    requests.exceptions.RequestException,
    max_time=MAX_BACKOFF_TIME,
)
def search(instance: str, url: str) -> Dict[str, Any]:
    api = f"https://{instance}/api/v3/search"
    query = f"?q={url}"
    response = requests.get(api + query)

    if response.status_code == 200:
        res: Dict[str, Any] = response.json()
        return res
    else:
        return {}

This makes it look more difficult than what I expected. https://programming.dev/comment/50809

613
44

An exercise-driven course on Advanced Python Programming that was battle-tested several hundred times on the corporate-training circuit for more than a decade. Written by David Beazley, author of the Python Cookbook, 3rd Edition (O'Reilly) and Python Distilled (Addison-Wesley). Released under a Creative Commons license. Free of ads, tracking, pop-ups, newletters, and AI.

614
14

Well, it ain't pretty, but it works eh :)

615
13
Python SQLite Recipe (constvoidblog.wordpress.com)

A copy/pastable Db class to help people get started on using SQLite in python!

616
6
617
11

When I'm writing webscrapers I mostly just pivot between selenium (because the website is too "fancy" and definitely needs a browser) and pure requests calls (both in conjunction with bs4).

But when reading about scrapers, scrapy is often the first mentioned Python package. What am I missing out on if I'm not using it?

618
5

Note that I mean the open version VSCodium and not VSCode. Even after manually installing the Python and Pylance vsix files into Codium I wasn't getting the Pylance hints in the editor. I find them super useful for ersatz static typing and just general problems.

619
19
620
25
621
18

Inspired by FastAPI and Kombu, Propan was created to simplify Message Brokers' code writing and to provide a helpful development toolkit, which existed only in HTTP-frameworks world until now.

It's designed to create reactive microservices around Messaging.

It is a modern, high-level framework on top of popular specific Python brokers libraries, based on pydantic, FastAPI, and pytest concepts.

622
3
623
10
Python's "next" function (www.pythonmorsels.com)

I guess I knew the whole "you can't use next on iterables" in the sense that I've never tried it.

I TIL'd about the default value for next.

624
31

I was inspired to try writing my own Python script for Lemmy after seeing some other scripts on here and seeing Plemmy.

With this script, you can specify multiple accounts to have communities blocked on. You can also specify multiple instances to block all communities from.

This might be a little niche, but I wanted an easier way to block everything from some specific NSFW instances. This is my first "real" python scripting project, so any feedback is appreciated!

625
25

Version 0.30 adds a new notification system. Similar to desktop notifications, it displays a small window with a title and message (called a toast) for a pre-defined number of seconds.

view more: ‹ prev next ›

Python

8022 readers
2 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 3 years ago
MODERATORS