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
I tested my Python library SwagLyrics which is a faster approach to display lyrics on the currently playing Spotify song right in the terminal (or browser) for speed and accuracy on the US Top 50 Chart.

Here are the results, it takes 0.4s average per track given your internet speed is ok, even so, it's way faster than the alternatives since there's only one direct request and no API used due to a clever approach to directly format the URL (I'm so proud of it!)

[https://colab.research.google.com/gist/aadibajpai/06a596ad753007b0faea132e96f372e0/swaglyrics\_test.ipynb](https://colab.research.google.com/gist/aadibajpai/06a596ad753007b0faea132e96f372e0/swaglyrics_test.ipynb#scrollTo=vtE04ylUGxO-)

​

The repository in question, [https://github.com/SwagLyrics/SwagLyrics-For-Spotify](https://github.com/SwagLyrics/SwagLyrics-For-Spotify)

​

The method for getting the track from Spotify is novel too, since it doesn't use the API.

(I really wish I could write a paper on it haha, I researched naming conventions on Spotify and Genius to identify patterns so as to bridge them using nothing but string manipulations.)

​

What do you think? I'd love to know what could be better.

/r/Python
https://redd.it/cdgkqf
Receive data from Redis RQ worker process

Hi,

I am currently trying to get my Flask Web Application working with Redis RQ.

My application gets an input file and analyzes it for approx. 20 seconds. During the analysis it keeps an filling a dictionary which I want to access from my flask application to display the content of this dictionary in a nice way, like plots and graphs.

Now my idea is to allow the user to upload the file and hit "Analyze", which starts my program. Instead of waiting 20 seconds until the file has been processes and redirecting the user then to the page with all the plots I want to let my program run in the background. So if you click "Analyze" the browser directs the user directly to the page with the plots while in the background my analysis program is running.

For the task queue I am using redis RQ. The problem is, that I have no idea how I can access the dictionary, that is being filled by the worker process, through my flask application. Because the content of the dictionary keeps on growing I want to be able to present the user the live output as the analysis process keeps on running.

I tried using

/r/flask
https://redd.it/cdgs20
Using python to generate artistic images (Neural Style Transfer)

I made a [repository](https://github.com/Nick-Morgan/neural-style-transfer) which explores 2 methods ([Gatys, 2015](https://arxiv.org/pdf/1508.06576.pdf) and [Johnson, 2016](https://arxiv.org/pdf/1603.08155.pdf)) of Neural Style Transfer. I've included a link to Google Collab in the repository, making it easy to run the code on your own images.

​

I would love feedback on the repository, as well as any suggestions for future reading. I find this topic fascinating.

/r/Python
https://redd.it/cdk82d
I work at IBM, Django on the side.. need advice

Hey everyone, quick question. In my spare time, on the side, I like to build websites and recently finished one for a client (more like a friend who paid me ha) and it's something I really enjoy. (If you'd like to see the site click here: http://hendersonconstruction.org)

Just curious if anyone knows of any decent material (online video series, etc) that cover more advanced topics. Obviously I read the documentation, but I just was hoping to find something covering things such as optimization, best practices, or just anything that focuses on information beyond the technical aspect.

Now that I feel comfortable with Django I just want to improve the way my sites are built. I want to make them faster, make the code cleaner, and see different ways to do things and why each way may be useful given the circumstance.

If anyone could point me in the right direction I'd really appreciate it! God bless.

/r/django
https://redd.it/cdkvrv
Server redirect for JWT cookie storage (Flask-JWT-Extended)

I am storing JWT in httponly cookies via this method: https://flask-jwt-extended.readthedocs.io/en/latest/tokens_in_cookies.html

What I notice is when I use the @jwt_required decorator, it looks for the JWT access token in a cookie, but since it's httponly there is no JWT access token.

Instead, I am forced to do the redirect on the client side (i.e. if error = 401 (unauthorized) then redirect to login page). This is however not preferred.

Anybody have any suggestions for doing a server redirect with httponly jwt cookie storage?

/r/flask
https://redd.it/cdkc2o
Project Suggestion Site

Hi all,

I'm posting here to ask whether if this is a good side project idea to put on my resume.

Currently I have an idea to host a flask app that requires users to register (passwords are hashed with a randomly generated salt). Once registered they may post suggestions for side projects for programmers to undertake. These posts then need approval from an admin user which can approve them from within the site, they can also make more admins from within the site.

Once basic functionality is completed I will add more advanced features such as: comments, upvotes, etc.

The posts and users will be hosted on a Heroku PostgreSQL database.

Do people think that this is enough? Thanks in advance. :)

/r/flask
https://redd.it/cdk4ma
How to render latex formatted output from a code cell?

I've seen that sympy somehow can output latex formatted output, and that they are inmediately rendered correctly.

I was wondering how that was done, and how I would go about implementing it for other stuff.

Most specifically, I'm currently using [octave kernel](https://github.com/Calysto/octave_kernel), and you can do `latex(something)` and get latex formatted output.

I'm wondering how sympy achieves what it does and if they use magic commands for it. And maybe some tips on how I'd go about implementing that in octave if that's not the case

/r/IPython
https://redd.it/cdo2kr
Please Help Me Understand Why My Times and Dates Won't Update After Server Start

Hi everyone,

​

I am having trouble with getting accurate times. My page loads a form that is either empty, or, if another form has been submitted within the last hour, contains the last submission's entries pre-populated.

​

The logic to check this condition compares the last records date/time (which are strings, so either 2019-07-15 or 22:34), to one of the below functions, and then retrieves the last model object if within an hour.

​

import datetime

​

[datetime.](https://datetime.date.today)datetime.now().date() FOR DATES

and str([datetime.datetime.now](https://datetime.datetime.now)().time()\[0:5\]) FOR TIMES

​

I also set defaults in [models.py](https://models.py) and forms.py by using these lines.

​

I have just noticed that when posting the form and creating a new model record, it is being saved with the time that I started the server (I am running locally). I'll load a blank form at 22:30, but I've been working 30 minutes and I ran runserver at 21:59, that time shows instead.

​

Can someone please help me to get string representations of date (yyyy-mm-dd) and time (##:##) in 24hr. or some other way to compare dates and times that actually represent the time that they are called?

​

I have searched and found to use [datetime.date.today](https://datetime.date.today) but the condition fails on

/r/django
https://redd.it/cdrh3n
My enterprise tech company in the bay area still has alot of their codebase in python2.7 what happens come 5 months later when it supposed becomes unsupported? Will it be Y2K20?



/r/Python
https://redd.it/cdnhp3
How do I order multiple dates in django?

Hi their I have one model and a couple of fields some are date fields and some are date time fields the [models.py](https://models.py) file is like this:

# models.py
class Stocks(models.Model):
date_and_time_investment_was_made = models.DateTimeField(null=True)
date_dividend_was_deposited = models.DateField(null=True)
date_deposited = models.DateField(null=True)
date_withdrawn = models.DateField(null=True)

I need to filter it based on the date and time if there is one I have been trying to order it this way in my [view.py](https://view.py) file

# views.py

#------------------------------Dashboard Views--------------------------#
class DashBoardView(LoginRequiredMixin, ListView):
model = Stocks
template_name = 'dashboard.html'
context_object_name = 'investments'

def get_queryset(self):
return Stocks.objects.filter(who_by=self.request.user).order_by('date_and_time_investment_was_made', 'date_dividend_was_deposited', 'date_deposited','date_withdrawn')

#------------------------------------------------------------------------#


Now the problem with this approach is that in

/r/django
https://redd.it/cdokuq
Testing a django view with two forms.

I have a django view which includes both a signup and a login form. I cannot use ```self.client.post(url, data)``` as that cannot differentiate between the two forms. Nothing specific comes up on google.

/r/django
https://redd.it/cdterv
Async/Awaiting Production in Python

[https://dev.to/angulardevz/async-awaiting-production-in-python-20d5](https://dev.to/angulardevz/async-awaiting-production-in-python-20d5)

/r/Python
https://redd.it/cdrwir
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/cdxj37
Mind controlled text writer

# My python implementation of P300 speller

# [Video](https://www.youtube.com/watch?v=1GdjMx5t4ls&feature=youtu.be)

**Idea of P300 speller:**

Highlight rows and cols and record EEG reaction to these events. If row/col with target character is highlighted \~after 300ms peak on EEG diagram will occur and it's possible to train classifier to detect it. To remove noise from EEG data repeat it multiple times and use bandpass filter

​

**Hardware:** [OpenBCI Cyton](https://brainflow.readthedocs.io/en/latest/SupportedBoards.html#openbci-cyton)

**Software:**

* [BrainFlow library](https://github.com/Andrey1994/brainflow) to read and preprocess data from OpenBCI board
* [P300 implementation](https://github.com/Andrey1994/brainapps/tree/master/p300-speller)

/r/Python
https://redd.it/cdwea0
[P] TensorFlow DICOM Medical Imaging Decoder Operation

Hello, I wanted to share something our team has been working on for a while. I work on an early stage radiology imaging company where we have a blessing and curse of having too much medical imaging data. Something we found internally useful to build was a DICOM Decoder Op for TensorFlow. We are making this available open-source here: [https://github.com/gradienthealth/gradient\_decode\_dicom](https://github.com/gradienthealth/gradient_decode_dicom).

DICOM is an extremely broad standard, so we try to cover the 90% case of image formats (PNG, TIFF, BMP, JPEG, JPEG2000) by relying on the past work folks have done for [DCMTK](https://github.com/DCMTK/dcmtk). DCMTK is also largely considered an industry standard when it comes to parsing DICOMs. We also support multi-frame/multi-frame color images. Try images found here: [https://barre.dev/medical/samples/](https://barre.dev/medical/samples/). In the case an unsupported format is found, an empty Tensor is returned which can be filtered out. Reading the files directly off of bucket storage has allowed us to prevent data duplication of .dcm data (a single CT can be 300MB). You can play with the op in this Colab notebook: [https://colab.research.google.com/drive/1MdjXN3XkYs\_mSyVtdRK7zaCbzkjGub\_B](https://colab.research.google.com/drive/1MdjXN3XkYs_mSyVtdRK7zaCbzkjGub_B)

We firmly believe that having open-source resources in healthcare is what will enable its use in practice, not AI trade secrets. We plan on opening more of our work in the

/r/MachineLearning
https://redd.it/ce0lqk
Sources to learn flask

I just finished Corey Schafer’s playlist it’s great but I’m still can’t do anything in my own because I don’t know a lot in back end development so is there is any course , book or advice to be familiar with back end using flask

/r/flask
https://redd.it/cdz9my
Nice try

/r/Python
https://redd.it/ce3a62