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 have created a personal assistant program called JARVIS in python. It uses various APIs. It is pretty cool! Check it out! I have also created KAREN - the Spiderman AI! Like this video and subscribe to my channel, if you want to see how to make that! Enjoy!
https://www.youtube.com/attribution_link?a=Xe1carOmEKM&u=%2Fwatch%3Fv%3D5mu6qlFY3x0%26feature%3Dshare

/r/Python
https://redd.it/amomu8
How to get column SUM/AVG calculated

Hey guys,

​

So I wanted to add up some numbers from the column, after doing some filtering. Here what I was able to come up with using info found online. But something is wrong...

seller_received_sum = query.with_entities(func.sum(Testimonials.received).label('sum')).filter(Testimonials.seller == seller) or '<no-data>'

this returns me "<class 'flask\_sqlalchemy.BaseQuery'> SELECT sum(testimonials.received) AS sum

FROM testimonials".

&#x200B;

Some posts online suggested using '.scalar()' on the end of the query, but that returns me error too.

&#x200B;

What does label('sum' is)?

What scalar() stands for?

What's wrong here?

/r/flask
https://redd.it/amn1so
[HELP] Django Rest Framework and Social Authentication

Hi! I started learning the Django framework 2 weeks back and it's been going great overall. However, now I'm stuck at an issue and don't know what the best approach is. I started working with the django rest framework and it was fairly straighforward until I came across having social app authentication. Im working with the django-rest-auth framework which uses allauth for social app authentication. But I have no idea what to do for authenticating my app with this and there aren't a lot of good resources that I am able to figure out. i am a complete novice with regards to the whole authentication scenario and would be immensely grateful in anyone could help me out on what to do. Thank you all in advance.

/r/django
https://redd.it/amra6b
Flask and Celery for my Rasberry Pi 3 Temperature Logger

To learn a bit more about using Celery and RabbitMQ with Flask, I built a little temperature logging station with a Raspberry Pi 3 + DS18B20 one-wire temperature sensor. Celery + celery beat + rabbitmq are definitely overkill for what I wanted, but it was fun a fun way to learn more about them!

The goal was to have a rest endpoint to get the temperature (Flask) and a periodic task to log the current temp reading to a DB (Celery, celery-beat, RabbitMQ, SQL-Alchemy) that I can consume with Grafana or my own front-end to observe temperature change over time in my daughter's nursery.

[https://github.com/kbutz/tempread](https://github.com/kbutz/tempread)

/r/flask
https://redd.it/amsgxc
[Beginner] [Postgres Query] Filter data for a given day (timezone aware datetime) from postgres directly

I want to filter all data for the following day (which is timezone aware).

**Assumptions:**

* server data is in a specific timezone
* client query is coming from different timezone

**My current approach is:**

date = received_date_timezone_aware # any time of that day
lower = date.replace(hour=0,minute=0,second=0)
upper = lower + datetime.timedelta(day=1)
data = Model.objects.filter(date__gte=lower, date__lt=upper)

**Question**

Is there a direct solution to this using django orm or raw query?

I wanted to know if there is a better alternative which can save me a few lines of code of manipulating the datetime stuffs.

/r/django
https://redd.it/amqheh
Re-Apply Migrations?

I am using django-cookiecutter and want to know how to run all the migrations again if I want to drop the database? Is there a way or would I have to start from scratch? I would assume there is a way since it would have to run when I move it to Production?

/r/django
https://redd.it/amuj78
Not Found: /favicon.ico?

Trying to just return plain text because Ive just started a django project but im still greeted with the django page and not the plain text. in the command prompt i have errors like these, i followed the tutorial exactly so how do i fix this?

/r/django
https://redd.it/amvcs0
[AF] why am i all of a sudden getting this error? Method Not Allowed The method is not allowed for the requested URL.

Hi all,

I am working on two machines. Mac and Linux. I work on linux during the day, do all my work, head home at night and continue on mac.

I use docker-compose to allow this to happen and I've had little to no troubles all this time.

I finalised another conversion script yesterday on the mac, works a treat. CSV files upload,get converted, life is good. I've made many of these scripts using my workflow.

This morning though I've loaded the same script on the linux machine and am getting `Method Not Allowed. The method is not allowed for the requested URL.`

I have never had this before. I'm simply using:

<form method=POST enctype=multipart/form-data action='convertData'>
<input type='file' name='file' class='UCSV_FileInput'></input>
<button type='submit' value='Upload'>Submit</button>
</form>

and on my views.py I'm doing this kind of thing:

@myroute.route('/convertData', methods=['GET', 'POST'])
def convertData():
if request.method == 'POST':
# all the upload stuff is here

I literally have dozens of these,

/r/flask
https://redd.it/amvbna
My "Python for Data Science" video series!

Finally, I am done with the recording of my "Python for Data Science" video series! This 32-part video series provides a brief yet comprehensive introduction of the basic Python libraries required for Data Science to the beginners.

[https://indianpythonista.tech/pyfds](https://indianpythonista.tech/pyfds)

\#python #data\_science #numpy #matplotlib #pandas #tutorial #beginners

/r/Python
https://redd.it/amyds2
This media is not supported in your browser
VIEW IN TELEGRAM
I used neuroevolution with python to beat OpenAI games!

/r/Python
https://redd.it/amwt0v
Is there a Marie Kondo technique for refactoring spaghetti code?

I've found *lots* of post about how not to get to unmanageable code, but lets face it most of the unmanageable code we inherit from someone else. I've recently inherited a *huge* amount of code that was hacked together by someone who has just started coding and i need to add new features to it but I'm having a hard time trying to figure out where to start and how I get it to where i want it.

I guess Marie Kondo makes others deal with their own piles junk, but in an age where being a good organiser can make you famous perhaps we need something equivalent in the programming world.

Anyone have a technique/strategy that worked for them?

/r/Python
https://redd.it/an00ho
DRF/Django/React/Redux/MaterialUI and Antd/ Heroku ready and complete User template set up Boilder Plate

Greetings all,

&#x200B;

I have created a Django/React w/Redux Postgesql/Heroku User Boiler Plate. This boiler plate includes a user sign up, log in, log out, AND get user information which is all created using Redux and Django Rest Framework API's. You can follow my models, views, and serializers to create your own data base objects (models) in Django and then make those calls follwoing my API calls to user information. Pretty simple! Create a model and view or post to it through api calls in redux. Just map your components to your store and you are done!

It takes about 20 minutes to get the site up and running on heroku. It's the only place I know how to deploy to. Maybe this could be expanded upon by other users. Anyways, any comments, suggestions are much appreciated! This is kinda my first time doing anything like this, I'm a total noob and haven't been programming for a year yet.

So I'd really appreciate any suggestions.

[https://github.com/barictj/djreactboiler](https://github.com/barictj/djreactboiler) for the git

[http://djreactboiler.herokuapp.com/](http://djreactboiler.herokuapp.com/) for the installation instructions/ readme

/r/django
https://redd.it/amx1yr
Writing data to django sqlite3 database from an exterior python script questions

OK- so I have a python script that is up and running and pushing data nicely to a sqlite3 database right now (not my django db). And I want to eventually have it write to my django sqlite3 database instead. I just have a few questions about doing this:

1. Is there anything special I must put in my Python script, relating to the django site/database? Right now, I am assuming all I have to do is just connect to my django db instead of outside db ie: sqlite3.connect('path\\to\\django\\db')
2. Do I need to re-create the sql table in [models.py](https://models.py) of my django site? If so, I assume it must match exactly to the SQL I am executing in Python currently..? Any tricks on doing this?

Any help would be much appreciated!

/r/django
https://redd.it/an2b23
DRF/Django/React/Redux/MaterialUI and Antd/ Heroku ready and complete User template set up Boilder Plate



Greetings all,

I have created a Django/React w/Redux Postgesql/Heroku User Boiler Plate. This boiler plate includes a user sign up, log in, log out, AND get user information which is all created using Redux and Django Rest Framework API's. You can follow my models, views, and serializers to create your own data base objects (models) in Django and then make those calls follwoing my API calls to user information. Pretty simple! Create a model and view or post to it through api calls in redux. Just map your components to your store and you are done!

It takes about 20 minutes to get the site up and running on heroku. It's the only place I know how to deploy to. Maybe this could be expanded upon by other users. Anyways, any comments, suggestions are much appreciated! This is kinda my first time doing anything like this, I'm a total noob and haven't been programming for a year yet.

So I'd really appreciate any suggestions.

[https://github.com/barictj/djreactboiler](https://github.com/barictj/djreactboiler) for the git

[http://djreactboiler.herokuapp.com/](http://djreactboiler.herokuapp.com/) for the installation instructions/ readme

/r/djangolearning
https://redd.it/amx8nw
[R] TuckER: Tensor Factorization for Knowledge Graph Completion

&#x200B;

https://i.redd.it/gicg4kh0zie21.png

&#x200B;

**Paper:** [**https://arxiv.org/abs/1901.09590**](https://arxiv.org/abs/1901.09590)

**PyTorch Code:** [**https://github.com/ibalazevic/TuckER**](https://github.com/ibalazevic/TuckER)

&#x200B;

**Key contributions:**

* proposing TuckER, a relatively simple **linear** model for **link prediction** in knowledge graphs that achieves **state-of-the-art results** across all standard datasets;
* proving that TuckER is **fully expressive** and deriving a bound on the entity and relation embedding dimensionality for full expressiveness which is several orders of magnitude lower than the bound of previous state-of-the-art models ComplEx and SimplE; and
* showing that TuckER **subsumes several previously proposed tensor factorization approaches** to link prediction, i.e. that RESCAL, DistMult, ComplEx and SimplE are all special cases of our model.

**Abstract:**

Knowledge graphs are structured representations of real world facts. However, they typically contain only a small subset of all possible facts. Link prediction is a task of inferring missing facts based on existing ones. We propose TuckER, a relatively simple but powerful linear model based on Tucker decomposition of the binary tensor representation of knowledge graph triples. TuckER outperforms all previous state-of-the-art models across standard link prediction datasets. We prove that TuckER is a fully expressive model, deriving the bound on its entity and relation embedding dimensionality for full expressiveness which is several orders of magnitude smaller than the bound of previous state-of-the-art models ComplEx and SimplE. We further show

/r/MachineLearning
https://redd.it/an09n8
How to keep the ML model of spaCy running for faster response

I am working on an NLP project in spaCy. I want to deploy my project on the internet, but I am facing a problem. The application checks individual sentences for their grammatical correctness and it is really quick once the ML model is loaded in the memory (with the command spacy.load('en')).
The problem is loading the ML model takes some time, around 30 seconds. How can I keep the model loaded so that it doesn't have to reload every time a new request comes in on the server?

/r/django
https://redd.it/an39k5
[Noob question] Should Django share a MySQL database with independent parts of the application?

There's two aspects to the database:

* The Django auto-created tables (auth_group, auth_user, django_session, etc.)

* The tables I will be creating separately. I have a crawler that's constantly inputting and modifying data in the db. This data will be used when rendering the HTML, as well as exposing it as a web service API.

I'm using Kubernetes and I have 3 containers in the pod:

* Django

* MySQL

* Crawler

I'm fairly inexperienced with all these technologies, and I'm just wondering if it's better to have all data under one database, or separate databases.

If I use just one database, should the source of truth (who creates the database) be Django?

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