Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
FLASK APP CAPTURE NOT WORKING WHEN DEPLOYED ON SERVER



I know nothing of Back-end Web development I just registered for a just for fun hackathon now My app works fine on local machine but when i deploy it on the server it fails to get the camera feed\` Given Below is the app.py file base.html ExecersicebicepCurl.html and bicepcurl.py **this is app.py**

import time
import cv2
from flask import Flask, render_template, Response
import mediapipe as mp
import numpy as np

from project import exerciseAI, yogaAI

#-----------------Routing----------------------------------

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/exercise/biceps-curl')
def exerciseBicepsCurl():
return render_template('exerciseBicepsCurl.html')

@app.route('/exercise/push-ups')
def exercisePushUps():

/r/flask
https://redd.it/12luau3
Release: NiceGUI 1.2.7 with ui.download, easier color definitions, "aggrid from pandas dataframe" and much more

With 21 contributors the just released NiceGUI 1.2.7 is again a wonderful demonstration of the strong growing community behind our easy to use web-based GUI library for Python. NiceGUI has a very gentle learning curve while still offering the option for advanced customizations. By following a backend-first philosophy you can focus on writing Python code. All the web development details are handled behind the scenes.


### New features and enhancements
- introduce `ui.download`
- introduce color arguments for elements like ui.button that accept Quasar, Tailwind, and CSS colors
- allow running in Python’s interactive mode by auto-disabling reload
- allow creating ui.aggrid from pandas dataframe
- fix navigation links behind reverse proxy with subpath
- allow sending "leading" and/or "trailing" events when throttling
- raise an exception when hiding internal routes with app.add_static_files
- add “dark” color to ui.colors

### Documentation
- enhance Trello "drag and drop" example to use a ToDo data model
- add workaround to docs for native mode when WebView2Loader.dll fails load
- add documentation and demo about element borders inside a ui.card
- add hint about exception when running executable with no console on Windows

Of course the release also includes some bugfixes (see release notes for details). Thanks to everyone who was involved in making this release happen.

/r/Python
https://redd.it/12m03v5
Logging code mess

Way overdue for me but I started getting a lot more detailed with my logging. I'm finding it really clutters up the code though. Are there any best practices people use? When I have a two line method that has another two lines for logging it just starts feeling clunky.

Is there a way to be more elegant about it or is this just how it is with production code?

Alternatively are there any good code repos you guys can point me to that you think implement this stuff well?

/r/Python
https://redd.it/12lzpvi
How do you guys handle pandas and its sh*tty data type inference

I often like to dump CSVs with 100s of columns and millions of rows into python pandas. and I find it very very frustrating when it gets various data types for columns wrong. nothing helps

including `infer_objects().dtypes` and `convert_dtypes().dtypes`

how do you guys auto-detect dtypes for your columns?

is there a better library out there ?

/r/Python
https://redd.it/12m2gn8
[Crosspost] Introducing BungIO - a python bungie.net / destiny 2 api wrapper

Original Post: https://www.reddit.com/r/DestinyTheGame/comments/12lt3f1/introducing_bungio_a_python_bungie_api_wrapper/

---

**Features**

* Python 3.10+
* Asynchronous
* 100% typed and raw api coverage
* Ratelimit compliant
* Manifest support
* OAuth2 support
* Easily used in combination with other libraries like FastApi and discord wrappers


**Github**: https://github.com/Kigstn/BungIO

**Docs & Getting Started**: https://bungio.readthedocs.io/en/latest/

**Guides**: https://bungio.readthedocs.io/en/latest/Guides/basic/

---

While the bungie api is very extensive with a **lot** of functionality, it is IMO very confusing for new users. It also has a bunch of inconsistencies and suboptimal documentation. So as a side project, I've been working on making it more accessible for new people and api veterans.

Fast forward a few months, I'm ready to share BungIO with you all. I've been using it for my personal discord bot for ~half a year now and hopefully ironed out all the major kinks. It is designed to be easy to use, but still requires you to loosely know the api.


## Full API Coverage
What sets this library apart from other projects is that it has full api coverage - every single route is fully typed and returns fully typed python classes! And better yet, the api is automatically generated from the api spec bungie publishes. This means when there is an update to the api, it needs literally one button click from me to update

/r/Python
https://redd.it/12m2kpe
Can I add column to the result of a query?

I query a table like this:


check = Example.query.filter_by(example_attribute=1).all()

I get something in return that looks like this:

[Example('1','something', something again')]

Can I add to this so that it will look like this:

[Example('1', 'something', 'something again', 'another something')]

I tried this:
for x in check:
x.add_columns({'added column': 'another something'})

and that doesn't work.


Am I supposed to JSON.dumps this and then add it?

/r/flask
https://redd.it/12ley46
Pdfkit vs weasyprint ?

I have a pretty heavy website and want to generate pdf tickets , can be up to 20 per user per order, I already have pdfkit installed and working nicely with a small users number. But as my website grows I ask myself what is the better option between those two? Or is there a better third option …

My main concern is scalability and performance, my setup is a docker compose with django and celery for async pdf generation, hosted on aws elastic beanstalk with their auto scaling.

Can someone share his experience with pdf generation in django ?

Thanks guys for reading

/r/django
https://redd.it/12m7t68
Django REST Framework's TokenAuthentication VS JWTs

Hello guys, can someone explain why they would prefer one over the other? In terms of security, use case etc.

/r/django
https://redd.it/12mhff1
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?

Use this thread to chat about and share Python resources!

/r/Python
https://redd.it/12mirgo
How to generate URL from @app.route url in FLASK?



I have a Flask code with decorator u/app.route(/bestApp) to fetch my data from Fetch API javascript.

this is my app.py :

​

​

@app.route('/bestApp', methods=['GET', 'POST'])

def bestapp():

app_data = AppDataFromUrl(app_url)

json.dumps(app_data)

permitted_directory='static/assets/upload/'

return send_from_directory(directory=permitted_directory, path=filename,as_attachment=True)

​

​

and this is my script.js

​

​

async function getExtract() {

try {

const response = await fetch("/bestApp", {

method: "post",

body: new FormData(document.querySelector(".testform")),

});

​

console.log(response);



}

​

​



whenever i download my file, it works but the problem is the link that shown in browser is like “http://127.0.0.1:5000/bestApp

how to convert http://127.0.0.1:5000/bestApp to normal URL? such http://127.0.0.1:5000/42342jnkjsahdkajsda87391237921dask.

I don’t wanna use Blob Object Url or Data URI.

/r/flask
https://redd.it/12kkjfd
This week I made my first ever python script! It scrapes and translates a single Japanese website for hotel bookings asynchronously. Please come take a look :)

There is a hotel in Japan that will give you the insanely low price of $40 per night if you book a 30 day chunk all at once. Their site only lets you search a single location one day at a time though, so I decided to make this and learn everything from scratch along the way. The most ironic part is, I didn't find a single booking! I think they discontinued the offer... I was going to make a frontend with English translations for regular use too...


I'm openly accepting tips and advice on how to design these things better. It's probably pretty simple for you, but it took me awhile to figure out! Eventually I'd like to swap careers into tech :) If you have any ideas for what to make next be sure to leave your suggestion!


The code on github: https://github.com/Gornel/apa\_scraper/blob/main/list\_gatherer.py
A youtube of the first time I ran it: https://www.youtube.com/watch?v=cGUOLdaKBuE

/r/Python
https://redd.it/12m6obx
Here's my project to explore stress control through controlled breathing using Python, BLE, and the Polar H10 Heart Rate monitor

Hey r/Python,

I've been exploring the data available from the widely available Polar H10 heart rate monitor. The Bleak package provides a simple way to connect to the device, and stream heart rate, acceleration, and ECG data.

In this project I looked into the relationship between breathing rate and heart rate variability, a common indicator of physiological stress response.
Github repo: https://github.com/kbre93/dont-hold-your-breath

/r/Python
https://redd.it/12mi0ij
What is the best way to store marketplace commissions and payouts in a database after each purchase?

The basic idea is that the marketplace takes payments on behalf of the businesses and every 2 weeks the platform sends the money to the business while keeping 5% as commission.


Each time a user purchases a product we create a new Purchase object:


class Purchase(models.Model):
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
product = models.ForeignKey(Product)
quantity = models.IntegerField(null=True, blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
total_price = models.DecimalField(max_digits=10, decimal_places=2)

​

Apart from this, we need to store commissions and payouts information in our database. I was thinking of creating 3 models:

* PlatformComission (gets created each time a purchase happens, and stores the amount that we earned on that purchase)
* BusinessEarning (gets created each time a purchase happens, and stores the amount we need to pay the business)
* Payout (gets created every 2 weeks when the payout is sent, gets linked to all the Business Earnings during those 2 weeks with a many to many

/r/django
https://redd.it/12msfa6
[R] Bert and XLNet: 85% Neurons Redundant, 92% Removable for Downstream Tasks
https://aclanthology.org/2020.emnlp-main.398.pdf

/r/MachineLearning
https://redd.it/12ms3wo
New search package in python

Searchlix

My first python package on PyPI

I want to try how I can develop a python package and upload it, and the result was: Searchlix

It is a simple and powerful package which helps with searching for patterns, emails, phone numbers and words in texts and websites! (Web scraping)

Some of the features:
-Patterns search in text (KMP algorithm)
-Word search in text
-Search for page name in website
-Find emails in text / Email validation
-Find emails in a website page
-Find a phone number in text / Phone number validation
-Find a phone number in a website page

And I will provide further features and examples in the future

I would be thankful if any one who tried it could show us how he used it (case study) and if there are any further suggestions

https://pypi.org/project/searchlix/

/r/Python
https://redd.it/12mw0dc
Mastering SOLID Principles in Python: A Guide to Scalable Code

The Single Responsibility Principle (SRP) is a fundamental SOLID principle that states that a class should have only one reason to change.

/r/Python
https://redd.it/12mxuoi
Basic question on what this syntax comes from: is this python code I am not familiar with; is it django -- Just not sure what to even call it so i can look up info on it.

/r/django
https://redd.it/12n1r76
Is having a single app standard in Django realm ?

hi there,

i started this new job as a Django backend developer. we have around 20 models. what i want to do is split them into couple apps along with their respective views etc. but my team mate argued that what i do is not right and all Django projects use a single app to manage everything.

is this correct ? what is the right way of doing this. a single app with 20 models in a models.py file seems hard to read/reach for me.

should i create separate apps or should i create multiple folders in a single app.

how do you structure your projects ?

/r/django
https://redd.it/12mwx7e
Django + Nextjs overkill?

I have built Django websites in the past as well as DRF + React. I know that the cool kids nowadays use Nextjs. It does indeed have a lot of good stuff but I feel kindda lost whether is a nice idea to combine the two frameworks and just use Nextjs as the frontend. I have read some posts mentioning that you will find a lot of problems down the road (CORS related, etc).

The reason to stick with DRF as backend is that I'm way more better developer and more used to python while I just know a couple of things in the Javascript world.


Any experience stories, guidance would be much appreaciated.

/r/django
https://redd.it/12neaj8