Python

6681 readers
1 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 2 years ago
MODERATORS
201
 
 

Smassh is a TUI based typing test application inspired by MonkeyType -- A very popular online web-based typing application

Smassh tries to be a full fledged typing test experience but not missing out on looks and feel! There is a lot of room for improvements/additions and I am open to contributions and suggestions!

Github: https://github.com/kraanzu/smassh

Thank you! <3

202
 
 

I want to scrape a website using python selenium however every time it gives different id to same html element. I don't know how to circumvent it.

maybe XPATH is my saviour? but I don't know how reliable it is.

203
204
 
 

I often find myself defining function args with list[SomeClass] type and think "do I really care that it's a list? No, tuple or Generator is fine, too". I then tend to use Iterable[SomeClass] or Collection[SomeClass]. But when it comes to str, I really don't like that solution, because if you have this function:

def foo(bar: Collection[str]) -> None:
    pass

Then calling foo("hello") is fine, too, because "hello" is a collection of strings with length 1, which would not be fine if I just used list[str] in the first place. What would you do in a situation like this?

205
 
 

I recently picked up the python mastery bundle from humble bundle and one of the books (about larger-scale projects) has its exercises built around using anaconda virtual environments. I am able to create a project using:

% conda create -n project0 —channel=conda-forge python=3.12

But when I try to activate project0 I get an error that “activate” is an invalid choice. When I tried to initialize conda for Bash, my terminal behaved like the default echo for typed characters turned off.

206
 
 

So, you're an advanced beginner ...

207
 
 

Found via Planet Python

208
8
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/python
 
 

Hello,

I made a simple script to scraper threads.net using python and selenium. the script is just few lines long and it's easy to understand.

So what this script does?

first it will open edge browser(which you can change it to firefox or chrome). now you have to enter credentials to log into it. your browsing data and credentials will be stored in user_data which you can move around.

It scroll through threads's feed/hashtag/explore and It will store the src of every image it encounters so at the end we will have a links.txt file containing all the links to the images we have encountered.

now we have links.txt and we can use the following command to download all the images from the links.txt

wget -i links.txt

the script:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
import time

options = Options()
options.add_argument("--user-data-dir=user_data")

driver = webdriver.Edge(options=options)

driver.get('https://threads.net')

s = set()

input("Press any key to continue...")
for i in range(30):
    try:
        elements = driver.find_elements(By.XPATH, "//img")
        for e in elements:
            s.add(e.get_attribute("src"))
        driver.execute_script("window.scrollBy(0, 1000);")
        time.sleep(0.2)
    except:
        print("oopsie")

with open("links.txt", 'w') as f:
    links = list(s)
    for l in links:
        f.write(l+"\n")

driver.quit()

I hope it was usefull :D

Edit: here is a link to links.txt https://0x0.st/HGjx.txt

209
 
 

Big update to rye is out: 0.18.0. Lots of bug fixes, lock files with source references for better docker support, global Python shims now pick up .python-version, automatic venv recreation on move. https://github.com/mitsuhiko/rye/discussions/544

via https://hachyderm.io/@mitsuhiko/111790331145932934

210
40
Python 3.13.0 alpha 3 is now available (pythoninsider.blogspot.com)
submitted 1 year ago by mac to c/python
211
 
 

cross-posted from: https://lemmy.ml/post/10682032

I've been looking to create a local database of cooking recipes for personal use, but doing it manually is quite tedious, to say the least. It takes maybe 5-ish minutes per recipe to navigate the various websites copy the text, create file, re-format the inevitably flawed text into readable ASCII only, and look over the result for spelling, grammar, and readability errors (one guy who made the recipes was seemingly barely literate, could hardly pass 3rd grade English class).

Are there any utilities you are aware of that would make this easier? Obviously the more automated the better, but automating text-pulling from a website, line sizing, indents, list formatting, and easy headers would be the minimum to be "worth it". Useful features would be automated file creation and naming, savable config presets, unified functionality (I.E. one utility that does everything, rather than a web API, a reformatter, and a file-writer, for example). The recipes tend to be in a certain format (Rich text? not sure) that prevents much of the readability from being retained when copied and pasted manually.

I'm looking for one single utility if at all possible, due to not wanting excessive headaches on my end. I'm running Linux Mint. Thanks for the heads-up.

212
213
 
 

I have this XML

<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.50.2 (823bef54)" openSubsonic="true"><searchResult3><song id="3b9d81b5def61a60705b9b89611a217f" parent="03693dd7b835740421cc1d6a4da201f3" isDir="false" title="Good Day featuring ScHoolboy Q" album="I Am &gt; I Was" artist="21 Savage" track="11" year="2018" genre="Rap" coverArt="mf-3b9d81b5def61a60705b9b89611a217f_5c1d3668" size="9716623" contentType="audio/mpeg" suffix="mp3" duration="242" bitRate="320" path="21 Savage/I Am &gt; I Was/11 - Good Day featuring ScHoolboy Q.mp3" created="2024-01-08T16:40:53.026754212Z" albumId="03693dd7b835740421cc1d6a4da201f3" artistId="1ae1d36568c651d53f78f427f05e9766" type="music" isVideo="false" bpm="0" comment=""><genres name="Rap"></genres></song></searchResult3></subsonic-response>

Which I got from an API call

I would like to be able to interact with it so I can check the artist and then pull the id

I thought this would be as simple as calling a key on an array (wrong terminology I know. Dict?), how wrong was I?

Having done some searching, I'm in the process of figuring out how xml.etree.ElementTree works. But it feels so overly complicated for what I'm trying to do? Am I going down the wrong path?

214
6
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/python
 
 

****FIXED IT! ****

    if "TXXX:FMPS_Rating_Amarok_Score" in tags:
      rating = tags["TXXX:FMPS_Rating_Amarok_Score"]
      print([key for key in rating])
    else:
      print(" ".join(["No rating exists for",mp3_file,"this song"]))

This code snippet prints the key as ['0.66'] That 0.66 is the exact value that I need?

A searching the internet showed me that people often want this the other way round, but no one seems to try to do what I'm doing? Does anyone have any idea on how to do it?

215
 
 

In my file, I have

from mutagen.id3 import ID3
tags = ID3(mp3_file)

Now if I do print(tags.keys())

It informs me that there's a TXXX:FMPS_Rating_Amarok_Score

But when I attempt to print(tags["TXXX:FMPS_Rating_Amarok_Score"])

It says there's a KeyError. What am I doing wrong?

216
48
Python 3.13 gets a JIT (tonybaloney.github.io)
submitted 1 year ago by [email protected] to c/python
217
 
 

cross-posted from: https://beehaw.org/post/10863052

Noob question incoming, thanks in advance for any help with this!

I have a specific use case in which I want to send an automated email or text to myself once a day (the message is different each time--otherwise I would just set an alarm, lol!). I'm running Pop_OS on an old desktop computer. Where I'm stuck is getting an email to successfully send from the command line. I'm looking for easy-to-follow instructions that would help me do that, and none of the articles or videos I've come across thus far have helped.

I'm aware of Twilio and other services that send SMS messages, but I'm looking for something free. Especially since I only need to text one person (myself), and infrequently at that.

Below is my attempt to send an email with the telnet command. Nothing ever came through...

XXXXXXXX@pop-os:~$ telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 pop-os ESMTP Exim 4.95 Ubuntu Sun, 07 Jan 2024 15:12:28 -0500
HELO gmail.com
250 pop-os Hello localhost [::1]
mail from: [email protected]
250 OK
rcpt to: [email protected]
250 Accepted
data
354 Enter message, ending with "." on a line by itself
Subject: Test
Body: Is this working?
.
250 OK id=1rMZW4-0002dj-Uy
quit
218
219
7
Python Rgonomics | Emily Riederer (emilyriederer.netlify.app)
submitted 1 year ago* (last edited 1 year ago) by ericjmorey to c/python
 
 

cross-posted from: https://programming.dev/post/8257343

Emily Riederer Writes:

Switching languages is about switching mindsets - not just syntax. New developments in python data science toolings, like polars and seaborn’s object interface, can capture the ‘feel’ that converts from R/tidyverse love while opening the door to truly pythonic workflows

Just to be clear:

  • This is not a post about why python is better than R so R users should switch all their work to python
  • This is not a post about why R is better than python so R semantics and conventions should be forced into python
  • This is not a post about why python users are better than R users so R users need coddling
  • This is not a post about why R users are better than python users and have superior tastes for their toolkit
  • This is not a post about why these python tools are the only good tools and others are bad tools

The Stack

WIth that preamble out of the way, below are a few recommendations for the most ergonomic tools for getting set up, conducting core data analysis, and communication results.

To preview these recommendations:

Set Up

Analysis

Communication

Miscellaneous

  • Environment Management: pdm
  • Code Quality: ruff

Read Python Rgonomics

220
221
11
submitted 1 year ago by jnovinger to c/python
222
223
 
 

I’m not a software developer, but I like to use Python to help speed up some of my office work. One of my regular tasks is to print a stack of ~40 sheets of paper, highlight key information for each entry (about 3 entries per page), and fill out a spreadsheet with that information that then gets loaded into our software.

This is time-consuming, and I’d like to write a program that can scan the OCR-ed PDFs and pull the relevant information into a CSV.

I’m confident I could handle it from there, but I know that PDFs are tricky files to work with. Are there any Python modules that might be a good fit for the approach I’m hoping to take here? Thanks!

224
 
 

cross-posted from: https://discuss.online/post/4110869

Conda (@[email protected]) writes:

Conda is moving our social media presence from Twitter/X to Mastodon and LinkedIn at the start of 2024. It's past time to move into spaces that are welcoming and more in line with our community values. Going forward, you can find us at 🐘 @[email protected] (https://fosstodon.org/@conda) 🔗 Conda Community on LinkedIn

Read Conda is moving to Mastodon & LinkedIn | conda.org/blog

Conda (Software)

Conda provides package, dependency, and environment management for any language.

Using conda provides a streamlined approach to package management, platform compatibility, environment isolation, and access to an extensive package ecosystem. It is particularly beneficial for data scientists, researchers, and developers working with diverse software requirements across different projects.

Conda Community

The "conda" community is made up of millions of users, packaging maintainers and tool developers. Conda is not a single organization but rather a concerted effort of many different organizations, all devoted to the mission of providing easy access to various types of free software regardless of the operating system or programming language.

We firmly believe that everyone belongs in open-source, and we want to start by thanking you for taking the time to read this page. What follows is a high level summary of all the projects and organizations which make up the conda community with links provided where you can learn more or get involved yourself. The many meanings of "conda"

Traditionally associated with the Anaconda distribution, nowadays the term "conda" refers to more than just a package manager or a software repository. Its many definitions also encompass community packaging efforts like conda-forge and bioconda, as well as new tools developed in the Mamba and conda-incubator organizations. All these efforts show that the conda ecosystem is no longer defined by a single actor and continues to grow and thrive.

Organizations on GitHub include:

Some tools you might be familiar with are conda or conda-build themselves but also community efforts like mamba, boa, setup-miniconda, conda-lock or conda-tree, among many more.

Read more about the conda community.

225
 
 

Just fyi.

view more: ‹ prev next ›