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
Getting the email of a user after they are authenticated using gmail.

I allow users to authenticate(using social-auth-app-django) they are part of my uni by logging in through google login. Since I don't know whether or not they are a new user or a returning user, I want to get their email so I can check whether or not they are already a user.

/r/django
https://redd.it/b6e3sy
Made my first library, any suggestions?

My library, [sacred-tui](https://github.com/justaboredkid/sacred-tui/tree/development), is a library that converts, places, and potentially animates ASCII art in the terminal. It is also my first library. Any suggestions on what I can improve on?

/r/Python
https://redd.it/b6g44z
Simple and lightweight C interface

Hey everyone!

I just wrote this C interface, and I couldn't find another one of comparable simplicity, so I'd like to share it:

https://github.com/Finomnis/PythonCModule

Its use-case is when you need to speed up like 1-2 functions and don't want to set up an entire compiler chain, or you need to share your code with someone and want it to work just out-of-the-box.

The advantages are:

* very small and easy to understand
* no explicit compiler invocations necessary
* automatic re-building if C code changes
* IDE compatibility, like PyCharm, without any extra work
* platform agnostic (tested on Windows, Linux, MacOS)

I hope this makes somebody's life easier.
Happy coding!

/r/Python
https://redd.it/b6gaug
How can I retreive users sigup details when they login

How can I retreive users sigup details when they login, I want them to go to another page if the category field is investor or business. I want to collect the CATEGORY field for redirection. How can I do that. I am new to the framework

settings.py
AUTH_USER_MODEL = 'Nilon.User'

models.py

class User(AbstractUser):
phone_number = models.CharField(('phone number'), max_length=15,default='+234',
help_text=('Field to save the phone number of the user.'),unique=True)
fullname=models.CharField(max_length=50)
is_verified = models.BooleanField(('verified'), default=False,
help_text=('Designates whether this user should be treated as '
'verified.'))
Gender=models.CharField(choices=gender,max_length=20)
Category=models.CharField(choices=categories,max_length=20)


def full_name(self):


/r/djangolearning
https://redd.it/b635zq
Updating website realtime

Hey guys!
I am quite a beginner at flask, currently learning from Corey Schaeffer's youtube videos (which are amazing, recommend for everyone).

I have a website that by filling a form activates a backend python script , redirect and shows the logs.

But i would like to show the logs at real time while the script is running.

Any idea on how can i achieve that?
No code needed, would like to do that by myself but being better directed would be great.

Thank you :)

/r/flask
https://redd.it/b6f1tr
Dropdown selection

Hello,
I am new to Flask.
I had a simple question.
I am getting JSON files from different sources, a weather channel and also from new organizations.
What I am doing now is getting all the weather from different cities at once, also all the news headlines from different sources at once.
Is there a way to show in FLASK a dropdown with the selection of what the user wants to see, then display that information?
eg. the dropdown has Tokyo, New York, Irvine, then when the user selects one of those it shows the weather for it. Once the user changes the selection the output changes based on the selection.
Should I be sending all the data blob at once from python to flask, or should I load it up based on what they select?
Any example tutorials or code will be helpful.

Regards


/r/flask
https://redd.it/b6idri
How to pass port as parameter?

I saw in docs that you can pass port number as parameter -p, like:

python3 "/.../routes.py" -p 5003

but it isn't working for me!

/r/flask
https://redd.it/b6n437
Advanced web scraping in pythong using Scrapy

So I've been trying to teach myself web scraping, I can do basic, normal webscraping completely fine but now I want to teach myself how to scrape a website that has anti-webscraping mechanisms.

So I chose this website: [https://sneakersnstuff.com/en/858/new-arrivals](https://www.sneakersnstuff.com/en/858/new-arrivals)

​

I previously tried scraping proxies from: [https://free-proxy-list.net/](https://free-proxy-list.net/) then use these proxies to try and scrape the above website link with BeautifySoup and requests but got 403, and even with Scrapy so far I have been getting 403 FORBIDDEN HTTP status code, meaning that I haven't passed through their anti-webscraping mechanism.

So I want to know any suggestions, tips and tricks explained in a beginner-friendly way with a code example, to achieve this feat.

/r/Python
https://redd.it/b6i2ya
[R] Implementation of Neural Ordinary Differential Equations [slides + notebooks + code]

Hi, sharing with my slides and notebooks on NeuralODE. During my talk I put stress on explaining what are ordinary differential equations, how to solve them numerically (how to implement simple black box solver), how to integrate ODE when problem function is given by Neural Network, how to compute gradients with adjoint method vs naive approach. Finally, what are Continuous Normalizing Flows derived in the paper.

Link to repo: [github/2019-03-Neural-Ordinary-Differential-Equations](https://github.com/kmkolasinski/deep-learning-notes/tree/master/seminars/2019-03-Neural-Ordinary-Differential-Equations)

In the repo you can find:

* tensorflow implementation of NeuralODE (eager mode + keras API) - however for the sake of simplicity I implemented only few fixed grid solvers i.e. Euler, RK2 and RK4
* jupyter notebooks which show how to implement black-box ODE solver, integrate NN with it, how to use adjoint method to optimize bullet trajectory etc
* re-implementation of Continuous Normalizing Flows:

[Example result obtained with Continuous Normalizing Flows \(two moons problem from paper\)](https://i.redd.it/pjoslv7xrto21.gif)

​

/r/MachineLearning
https://redd.it/b6ghg3
Admin page not displaying list_display

I'm working through MDN's tutorial on Django and I'm up to the Admin page stuff.

I am trying to register my Author model in my admin pages like so:

from django.contrib import admin
from .models import Author

@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
list_display = ('last_name', 'first_name', 'date_of_birth', 'date_of_death')

When I go to `localhost:8000/admin/catalog/author` I'm still seeing the `__str__()` representation of the model. What am I getting wrong?

/r/djangolearning
https://redd.it/b6ozi7
Django app getting pinged by bots looking for vulnerabilities--what should I be doing in response for security(site on Heroku behind Cloudflare)?

Hey all, have a django site running on heroku behind cloudflare and noticed in the logs that site is often getting pinged by bots looking for vulnerabilities (ie. queries to mysite.com/wp-login or mysite.com/com/fileuploader etc.). It's not that frequent that it's a DDOS, these all show 404 error codes so I think they just don't get through, and most of the pings are for wordpress sites anyway.

I'm wondering if I should be doing anything to prevent these attacks or ban these ips? I am on the Cloudflare plan with the WAF. Cloudflare has an option in the WAF to ban certain IPs, should I be adding these IPs to that list(any way to automate this?) or something else? Just wondering if there's a best practice here. Thank you all.

/r/django
https://redd.it/b6p8nu
defer and some concurrency [AF]

Hey everyone,

I've got a request that does a large amount of insertions in a psql db. This takes quite some time and results in the request/response cycle returning a tiimeout. Someone a lot more knowledgable than I'll ever be suggested flask_defer but for the life of me I can't get it to provide the response back to the client prior to inserting the data into the database. I've seen the likes of celery and python-rq. Although these seem scary and like way too much to simply have a task running in the background with me being the sole client to access this site.

So just to lay out the problem better. Every evening I'll automatically start submitting data to the database. The insertion of the data takes quite some time and thus the response isn't returned in a timely manner. The site will only be used by me, so it won't be receiving a lot of attention. I want it to be able to return the response prior to doing the database insertions. Some level of concurrency will be needed as when flask returns the response, I'll immediately start another request, to insert another set of data, and if the prior

/r/flask
https://redd.it/b45634
Getting data from dynamically created inputs

I have some code where I can dynamically add inputs via javascript code. But I'm unable to figure out how to get the data from the input boxes created. How can I get the data back into my python scripts? Do I have to do this with JS?

EDIT: So I found a solution.

In my forms.py I utilize a HiddenField(). Then in my javascript I take my addCount var used in generating the input boxes and store that value into my HiddenField. Then from my routes.py I am able to access the HiddenField data via request.form.get('hiddenNum'). Once I have that value, I can loop over the range to generate the names for each added input box.

Forms:

class SubDirForm(FlaskForm):
subDirName = TextField(validators=[DataRequired()])

class SubDirsForm(FlaskForm):
subDirList = FieldList(FormField(SubDirForm), min_entries=0)
submit = SubmitField(label='Print')
addField = ButtonField(label='Add Field', id='addNewField')
hiddenNum = HiddenField()



Route:

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


/r/flask
https://redd.it/b3tkb1
[P] I scraped 32,000 cars, including the price and 115 specifications

NEW cars. Specs include MSRP, Gas Mileage, Engine, EPA Class, Style Name, Drivetrain, SAE Net Torque @ RPM, Fuel System, Engine Type, SAE Net Horsepower @ RPM, Displacement, etc. The cars are all cars available on the American market.

Get the CSV (44MB) on my [drive](https://drive.google.com/file/d/1HnpfG2xj_6EZ7Tgle2QB9Yn_YS7r7uVA/view?usp=sharing), or look how I did it on [Github](https://github.com/nicolas-gervais/predicting-car-price-from-scraped-data/blob/master/scraping).


/r/MachineLearning
https://redd.it/b6r34a
[AF]Tag input form in Flask?

I've been trying to implement what is really just a form where you type a word, hit a comma, and the word is put into a little container with an 'X' next to it, pretty much what you would expect from a form that is looking to separate tags.

Does anyone know the name of what this box is called or point me to a form/library that does this? It has been difficult Googling help for this as I don't seem to be coming on the right name for it.

/r/flask
https://redd.it/b3ss4k
Added Docker support for dev environment

Hi guys,

previously is shared my boilerplate for flask, now i am here with another change that is docker based development environment. I added the docker support for the dev environment.

Here is the link to the repo:

[https://github.com/a-wakeel/flask-bp](https://github.com/a-wakeel/flask-bp)

​

Will appreciate any suggestions and appreciations.

Cheers !

/r/flask
https://redd.it/b3n2i2
If you were to create only the frontend part of an eCommerce site in 2019, is it a terrible idea to use Django?

I'm looking at using Saleor for the backend of an eCommerce and making use of the GraphQL API to build a "core" backend that can be replicated over a number of shops with the database being the only variable, and a number of frontends for different shops for each of the brands that we sell.

Now I'm not much of a javascript guy (outside of some basic jQuery stuff, the "modern" ES6 syntax makes me feel a little sick) so I really do not understand the Saleor React based [storefront frontend](https://github.com/mirumee/saleor-storefront).

​

So I'm left with a few options:

1. Suck it up and try and learn their complicated React frontend
2. Build a frontend in Django and use that to talk to the backend, use Django templates and a spinkling of jQuery as I have done in the past.
3. Build a new frontend in React or Vue and learn how it all works for myself

​

The requirements any front end would meet would be:

* Any easy to understand templating system, ideally something similar to [Shopify's liquid templates](https://shopify.github.io/liquid/basics/introduction/) or [EKM Tags](https://tags.ekm.com/)
* Full server side rendering, SEO is very important to us

​

I'm not looking to build fancy SPA's or PWA's, just simple, performant shops based on

/r/django
https://redd.it/b6vewm
I used the Spotify lyrics script uploaded here last week to create a Telegram bot. It sends you the lyrics of the song you're currently listening, so you can get them on the go! Running as Chatot bot (@Spoti_lyrics_bot) on Telegram.

[https://github.com/manuhortet/spotify-lyrics-bot](https://github.com/manuhortet/spotify-lyrics-bot)

/r/Python
https://redd.it/b6vx0i
Nullable PositiveIntegerField to non-nullable CharField with default w/ Postgres

I am having an issue with my migrations. I am trying to change nullable PositiveIntegerField into non-nullable CharField with a default value. Said migration works like a charm if I don't have any null values in the db, it crashes however with `django.db.utils.OperationalError: cannot ALTER TABLE because it has pending trigger events` error when it encounters a null. I have a workaround that first changes the int field to nullable char field and maps null values to empty string. I would then make yet another migration that would make the field not-nullable. However, I would like to do it all in a single migration. Any ideas or suggestions?


/r/django
https://redd.it/b6yu2l