Python Daily
2.56K subscribers
1.49K photos
53 videos
2 files
39.1K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Live Data Plotting with Matplotlib

Below is a program I am using to read and plot the value of a sensor (simply a potentiometer at the moment). I am using two DIGI XBEE Pro SX Modems to transceive the data. The majority of the code below is provided by DIGI. The program displays the value of the sensor on the screen but when the compiler reaches the plotting section it simply doesn't execute. There are no errors. I am using Python 3.8, jupyter notebook, and anaconda.

\#########################################################################

from digi.xbee.devices import XBeeDevice

from [digi.xbee.io](https://digi.xbee.io) import IOLine, IOMode

​

import matplotlib.pyplot as plt

import matplotlib.animation as animation

import time

import re

import csv

import serial

import datetime as dt

import math

%matplotlib notebook

​

​

\# TODO: Replace with the serial port where your local module is connected to.

PORT = "COM13"

\# TODO: Replace with the baud rate of your local module.

BAUD\_RATE = 9600

​

REMOTE\_NODE\_ID = "REMOTE"

​

IO\_SAMPLING\_RATE = 1 # 0.5 seconds.

IOLINE\_IN = IOLine.DIO3\_AD3

i=0

​

def main():



\#print(" +----------------------------------------------+")

\#print(" | XBee Python Library Handle IO Samples Sample |")

\#print(" +----------------------------------------------+\\n")

​

device = XBeeDevice(PORT, BAUD\_RATE)

global i

​

try:

[device.open](https://device.open)()

\# Obtain the remote XBee device from the XBee network.

xbee\_network = device.get\_network()

remote\_device = xbee\_network.discover\_device(REMOTE\_NODE\_ID)

if remote\_device is None:

print("Could not find the remote device")

exit(1)

​

\# Set the local device as destination address of the remote.

remote\_device.set\_dest\_address(device.get\_64bit\_addr())

​

\# Enable periodic sampling every IO\_SAMPLING\_RATE seconds in the remote device.

remote\_device.set\_io\_sampling\_rate(IO\_SAMPLING\_RATE)

​

\# Register a

/r/IPython
https://redd.it/bf8dg2
[P] Flattr, a book scanner app using TensorFlow Lite for realtime preview

Hello reddit!

We've just launched an app called **Flattr** that scans books quickly and beautifully, flattening the curved pages with the help of deep learning.

It uses TensorFlow Lite to flatten a page of a book and shows the flattened & cropped page in realtime. (The performance of the app may vary depending on your device.)

​

To see how it works, here's a demo video: [https://youtu.be/SlQbIQU62P4](https://youtu.be/SlQbIQU62P4)

​

Currently, its features are:

\- Live preview of the flattened book page

\- Auto-cropping

\- Scanned page enhancement that makes the flattened page much easier to read

\- Save pages to your gallery

​

You can download the app from here: [https://play.google.com/store/apps/details?id=com.voyagerx.flattr](https://play.google.com/store/apps/details?id=com.voyagerx.flattr)

​

The app is at an **early development stage** but we're improving fast and some of the features that could be added later are ...

​

**Our todo list**

\- Improve the quality of the scanned pages

\- Improve the page flattening model

\- Compile scanned pages into a book

\- Export to PDF

\- Support various document types

\- Add OCR: Recognizing texts in images

\- Add auto-scan: No need to touch the preview screen

\- Add auto page number detection & page sorting

Oh and it's **FREE!**

​

Give it a try and tell us your thoughts, thanks!

​

**Comparisons with existing apps**

\- Adding some comparison pics since there was a question about the how Flattr differs from existing solutions.

​

​

[CamScanner](https://i.redd.it/7snzgwa8idt21.jpg)

​

​

[MS Office Lens](https://i.redd.it/sxfbd6t9idt21.jpg)

​

[Flattr](https://i.redd.it/dnpn6wjdidt21.jpg)

I think

/r/MachineLearning
https://redd.it/bf8u41
The best production-ready Docker + Django configuration

Hi, there is a lot of tutorials and examples of Docker + Django config but where can I find the best one, production-ready? Perfectly with GitLab CI/CD. Can you recommend any article or github repo? Thanks!

/r/django
https://redd.it/bfb5lt
How to set up a 200,000 hits per second django server

Hi i need to set up a server that can handle ~200,000 hits per second. Specs are 128 core cpu, 64 gb ram.
Most requests will be within 1kb return and most of them are exactly same so caching will be possible.
I was thinking of nginx(for images) and redis with django .
Any help will be highly appreciated

/r/django
https://redd.it/bfb4zc
Python Tutorial: How to Read-Write Excel Files, Web-Scrap Google and Create Interactive Maps in 20 lines of Code

The following short article shows just how simple it is to use Python programming language in a data science project.

In this example, we’ll first go to Statista.com (public dataset provider) and download the MS Excel dataset that contains the list of 100 largest companies in the world. The file that contains only two columns, the company name and their current market value. Our goal is to use Python to read the rows and cells inside the Excel file and use it to search the internet for some additional information, such as the company’s headquarters location and it’s map coordinates (latitude and longitude). You’ll see how easily this can be done by using Python web-scraping capabilities.

We’ll also show how to write the newly found information back into the Excel sheet and use it to create an infographic that shows the headquarter location of 100 of the world’s top companies on the map.

https://www.joe0.com/2019/04/20/python-tutorial-reading-writing-excel-files-data-gathering-by-web-scraping-google/

As far as 20 lines, I know, better-formatted post could easily end up being 25 or even 30 lines long, but hey :)

Enjoy!

/r/Python
https://redd.it/bf9cgz
Django Wedding Site

I made a Django site for my wedding, which was last month. The site has a working RSVP and a comment section. Feel free to check it out! I'm not much of a style guy, so the CSS may not appeal to you, but let me know what you guys think.

[https://www.wilsonegoavil.com](https://www.wilsonegoavil.com)

I applied a login required decorator at the comment and RSVP sections so you'd be required to login before use of those features. If you've got any questions or criticisms, let me know.

Source code can be found at [https://github.com/shanewilson007/wedding-site](https://github.com/shanewilson007/wedding-site).

/r/django
https://redd.it/bffdml
How to switch your career to Python coding? (part-time)

Finance background, looking for part-time courses.

thanks,

P.

/r/Python
https://redd.it/bfh7xh
Searching for a trading api to trade stocks with python?

Hi there.
I'm a beginner to the world of stocks, not programing in python and I'm looking for some kind of module or api that allows me to trade stocks.

I don't need something fancy, I'm looking for some features:
- it's simple
- It allows a "sandbox" trading (virtual money for testing)
- I can set when it should automatically sell and buy a stock (Ex: if x% lose then sell stock)
- I can run my trading bot in any time-frame

/r/Python
https://redd.it/bfiwaw
Providing an additional, non-model parameter to a CreateAPIView subclass in DRF

Hi, I'm using Django Rest Framework and for one of my CreateAPIView subclasses I want to pass an extra (float) parameter to the view. This parameter is NOT part of the model and I don't want to store it. I just want to use it to set a value on the created object, depending on the range of the float value. I've tried adding a write only parameter to the serializer and reading it in my perform_create method but I am getting a TypeError when I try that:

TypeError: Got a `TypeError` when calling `Model.objects.create()`. This may be because you have a writable field on the serializer class that is not a valid argument to `Model.objects.create()`. You may need to make the field read-only, or override the Serializer.create() method to handle this correctly.

I feel like this shouldn't be overly difficult and yet here I am struggling with it. Any help would be much appreciated!

/r/django
https://redd.it/bfhkqa
Inline formset or records on demand based on model field value? Is this possible?

I have a class thats basically a name field. Say for eg.
`Class Car:`

`name = models.Charfield()`
`allow_records = models.Booleanfield()`

​

`Class Record:`
`type = models.Charfield()`
`manufacturer = models.Charfield()`


Only if allow\_records is set to True should it render inline formset(records) either in admin or template.
Is this possible?


I do know that your can ForeignKey the table and permanently make it hold records but i want to provide the user with choice.

/r/djangolearning
https://redd.it/bfen9d
Passing word .doc, pdf (or other formatted text) to website's front-end... (Guitar chords/lyrics)

Hi team,

It might be more a javascript/css front-end question, however thought I'd ask here first.

I'm not sure about the best methods in passing a word document, pdf or other formatted text to a render_template... I have a bunch of songs with guitar chords positioned in the correct place and what to add them to a section of my site.

Any ideas would be helpful :)

Cheers!

/r/flask
https://redd.it/bfaiqy
Trouble deploying on elastic beanstalk

Hi everyone,

​

I'm really struggling with my django project deployment. I'm attempting to deploy to elastic beanstalk using this guide.

[https://github.com/codingforentrepreneurs/Guides/blob/master/all/elastic\_beanstalk\_django.md](https://github.com/codingforentrepreneurs/Guides/blob/master/all/elastic_beanstalk_django.md)

​

Within Elastic Beanstalk, the health of my severe is 'severe' and I'm getting the following errors:

​

**Issue 1**

[Sun Apr 21 06:15:42.463620 2019] [:error] [pid 28281] [client 172.31.24.0:64074] Target WSGI script not found or unable to stat: /opt/python/current/app/application.py


When I try to run 'eb deploy', I get the following error:

​

**Issue 2**

Collecting pywin32==223 (from -r /opt/python/ondeck/app/requirements.txt (line 19))
Could not find a version that satisfies the requirement pywin32==223 (from -r /opt/python/ondeck/app/requirements.txt (line 19)) (from versions: )
No matching distribution found for pywin32==223 (from -r /opt/python/ondeck/app/requirements.txt (line 19))

I'm not sure if issue 1 is caused by the fact that I haven't successfully run 'eb deploy' yet.

​

Any insight would be appreciated! Thank you!

/r/django
https://redd.it/bfm9qc
One backend for serving the website and handling an internal API

This might be more of a general backend question, but also with the specific case of Flask.

I'm working on a project using Flask and React, and I'm responsible for building the backend, and I came up with an idea as follows: there will be one side of the server that simply serves the frontend managed with React, and another side which provides API access to the database.

So then the frontend people can simply write code not even needing to know how flask works, and making API calls whenever they need data from the database.

Does that sound reasonable? Is it something that's sometimes done?

/r/flask
https://redd.it/bfo845
Last 3 years I've developed/maintained this open-source distributed real-time group-chat backend in Python

Github: [https://github.com/thenetcircle/dino/](https://github.com/thenetcircle/dino/)

*Socketio front-end connects to this Flask backend.*

We're currently using it for a couple of our products in production, where the top usage is at peak time \~2.5-3k users, chatting in real-time. It's been running in production for over 2 years without major issues. It's scaling vertically over multiple instances/servers. Though maybe it might be of interest here.

**The licence is Apache 2.0.**

There are many areas that can be improved for sure, but I can only work on it if it brings return on time invested. I started this project since we had the need for it, and I couldn't find a good alternative out there. Our previous group chat was using ejabberd, but the amount of custom features we needed couldn't be covered by only me writing erlang modules, so we decided to do it in python instead.

Out top product (which has upwards to 3k simultaneous users in a single chat instance) is deployed currently like this:

* 14 instances (one instance per core) on two different servers,
* 2 redis instances,
* 1 master/slave pgsql instance.

As I said, it's not a full time project so there are many areas that can be improved, but if it's any help to others

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