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
YuleLog - A terminal based Yule Log Fireplace for the Christmas Season. Made with Asciimatics!

I had the idea this morning to make a terminal based fireplace like the ones you see on youtube around this time of year. I looked around and didn't really see anything like it so I figured I'd go ahead with it.

I have always loved Asciimatics and remembered there's an awesome fire effect built in. There was a Christmas example, but it only had floating text.

I then found a photo of a log and converted it with https://picascii.com/ and spent some time tweaking the position a bit till it looked good on different console sizes.

It's up on Pypi so you can

`$ pip install YuleLog`

Not a lot of work at all but I'm pretty happy with the outcome and I hope you all are too :D

tl;dr - YuleLog -

Screenshot: https://github.com/Duroktar/YuleLog/blob/master/yule_log/screenshot.png

Github - https://github.com/Duroktar/YuleLog

Pypi - https://pypi.python.org/pypi

Release page - https://github.com/Duroktar/YuleLog/releases/tag/0.0.1

Love, Peace and Happiness to you all. Merry Christmas!!

edit: WORKS BEST IN FULLSCREEN!

/r/Python
https://redd.it/5k5o9l
Basic Model concept but I can't wrap my head around how to do it... Help, please.

Spending part of the Christmas holiday working on my first big Django project and I've hit a wall. I just can't wrap my head around how to do this so any help would be appreciated.

Custom user account (already made and set up) has a field which is used to reference an external API. Information related to the user (transaction list with details) is pulled from the external API (JSON) and saved to my database. Each user will have multiple transactions and each transaction will have multiple pieces of data associated with it that needs to be saved (to be later presented as a graph).

I can't wrap my head around how to set up the model to get the JSON data into my database. This includes creating the model and saving it.

I realize it's probably an elementary problem but if anyone can just list what I need to do to get this done I'd appreciate it. Most tutorials use data from forms (or blog entries) to illustrate how to save data to a database so I guess I need to know how to process and save data from a non-form outside source.

/r/django
https://redd.it/5k45xh
I implemented a module in python for oversampling skewed datasets. Would love to hear your thoughts on it!

It is an implementation of the ADASYN algorithm (link to paper: bit.ly/22KgAnP) and is designed to work along the scikit-learn API. I ran into the need of an oversampling module that focuses more on examples that are harder to classify, and I said, what the heck... I will implement it on my own. Feel free to use it in your projects and if you find any bugs just open an issue

https://github.com/stavskal/ADASYN

Don't forget to star if you find it useful ;)

/r/pystats
https://redd.it/44r9ye
Supervisord project: Python 2 to 3 porting help needed

Supervisor is a process supervisor used by hundreds of thousands (millions?) of production systems. It is used by people who don't even use Python as their application language.

supervisord is one of the most useful tools to run production systems.. and is more relevant when we look at the Docker world..Where is it is usually run as "init 1".

For us (and a crazy ton of systems people who dont even use python for application code), the "supervisor" incompatibility is a blocker to move to py3.

Unfortunately, I think the maintainers are handicapped by py3 expertise - https://github.com/Supervisor/supervisor/labels/python%203

>Supervisor has some major issues on Python 3. Many of these issues are encoding related as well so merging this one patch doesn't move the needle much. We need someone who has strong experience in Python 2/3 porting and is willing to spend a non-trivial amount of time looking at these bytes/strings issues together.


https://github.com/Supervisor/supervisor/pull/471#issuecomment-267793117

/r/Python
https://redd.it/5k1875
a Py3.6 fizzBuzz oneliner with f-strings

print(*map(lambda i: f"{'Fizz' * (not i%3)}{'Buzz' * (not i%5)}" or i, range(1,101)), sep='\n')



/r/Python
https://redd.it/5k7lnb
How to build an interactive dashboard?

Do any packages exist allowing a dashboard with greater layout flexibility than the notebook allows?

/r/IPython
https://redd.it/4ogcgg
[AF] redirection issues

What I'm trying to do is redirect back to the home page (index.html) after a user has submitted their email. Once they submit their email address on a form located on index.html, they are sent to a thank you page (thanks.html). I'm having problems redirecting them back to index.html

I've already tried the official documentation and looked for help online.
I couldn't get return redirect or url_for to work. And all my html files are located in the template directory so that's no the problem.

here is a link to the code. http://pastebin.com/sMAKUu3d
Thanks for the help!

/r/flask
https://redd.it/5k8mlw
Plotting multiple data series side by side in Bokeh

I'm trying to something that seems like it should be really simple, but I haven't been able to figure it out. I have a pandas dataframe with two columns of data, targets and actuals achieved. I want to plot these two side by side in a Bokeh bar chart. However, I can't seem to figure out how to pass multiple data series to the Bar function. I'd rather not have to re-shape my entire dataframe to work with the Bokeh group function, which seems to require that the data to be plotted is all in one series. Thanks.

/r/IPython
https://redd.it/4oc9fy
Introducing geodjango-tigerleaflet, a django app for displaying US States and Counties on Leaflet maps and navigating through them.

I've written a quick django package to help me split out some functionality related to US Census data (with code borrowed from geodjango-tigerline) and serve it for use on leaflet. It's a pretty niche thing, but offering it on github/pypi in case anybody else can make use of it. Of course, if you want to offer pull requests, make github issues or code review then I certainly won't turn it down.

[geodjango-tigerleaflet github](https://github.com/jlillest/geodjango-tigerleaflet)
[geodjango-tigerleaflet example project github](https://github.com/jlillest/geodjango-tigerleaflet-example)

I'm still learning the package creation process, as well as pypi documentation, so any pointers there are also appreciated. I found the process of creating the example app, package and submitting to pypi very easy using the cookiecutter utility. Many thanks to pydanny!

The overall utility of the package is to offer the state and county shapefiles/geojson files for use in the lightweight GIS toolset of leaflet. The templates provided are mostly to show how to get it up and running, though I'd love to make it more generic and use template tags for some of this. The real utility is the geojson views for providing data directly.

The app requires postgresql with the postgis extension, but if you're doing GIS-type work and need the shapefiles stored in your database then you already understand why this is required. Geodjango is such a great toolset for GIS.

Enjoy!

/r/django
https://redd.it/5k8nke
Plotting a transformed random variable

Let's say I've got a random variable X ~ uniform(-1,1) (is a random number between -1 and 1), and Y=X^2.

Using scipy.stats.uniform I can easily plot X's pdf by doing:

x=numpy.linspace(-4,4,100)
plot(x,uniform.pdf(x))

But I'm not sure how to plot Y's pdf/cdf.

Is there some sort of module that will do what I need?

/r/pystats
https://redd.it/42n7ge
Saving form with foreign key: 'NOT NULL constraint failed'

Hello fellow Django learners,

I am currently working an a 'IMDB' clone for me and my friends to use. The idea is that each of us gets an account and can either submit new movies or vote on already submitted ones. These movies are sorted by rating and users can access the detail view to see the individual reviews.

To achieve this I'm using foreign keys in my models.py - one for the movie entries (with information like director, title, etc) and one for the individual votes. The latter one uses foreign keys to fetch the movies title and the user that submitted the review.

However when testing the form that submits reviews I encountered the 'NOT NULL constraint failed: list_vote.voter_id_id' error. When browsing through the error page I discovered that the foreignkey values are not submitted to the database


params: [None, None, 9.0]
query: ('INSERT INTO "list_vote" ("movie_id_id", "voter_id_id", "rating") VALUES (?, ' '?, ?)')
self <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x7f77b8907dc8>

Yet, when I browse the error page for the local vars at the moment of the 'post.save()' command the missing variables seem to be there

entry: <Entry: Starwars 4>
form: <VoteForm bound=True, valid=True, fields=(rating)>
movie_id: 'Starwars 4'
post: <Vote: Vote object>
request: <WSGIRequest: POST '/vote/starwars-4/'>
slug: 'starwars-4'
voter_id : <SimpleLazyObject: <User: admin>>


If I add the ' movie_id' and ' user_id' values to my modelform (in the 'fields' variable) the form actually works. (though this is not what I want, as there could potentially be hundreds of movies in this database, making selection rather difficult. And right now, any user can pretend to be anyone)

I'm probably missing something very obvious, but for the life of me I cannot figure out what I'm doing wrong. The models, forms etc are based on both the Django_girls tutorial (where they work) and the 'Hello WebApp' book (though foreign keys are not used in this book)

Does anyone know what I'm doing wrong here?
I've included the relevant code below, many thanks in advance!






**These are the models used:**


class Entry(models.Model):
movie = models.CharField(max_length=255)
director = models.CharField(max_length=255)
total_votes = models.IntegerField(default=0)
rating = models.FloatField(default=0)
length = models.IntegerField(default=0)
year = models.IntegerField(default=0)
added_by = models.ForeignKey(User)
slug = models.SlugField(unique=True)

def __str__(self):
return self.movie

########################
Vote-model:
########################

class Vote(models.Model):

class Meta:
unique_together = (('voter_id','movie_id'),)

movie_id = models.ForeignKey(Entry)
voter_id = models.ForeignKey(User)
rating = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(10)])


**This is my form.py:**


class VoteForm(ModelForm):
class Meta:
model = Vote
fields = ('rating',)


**This is the relevant function form the view.py:**


def lets_vote(request, slug):
entry = Entry.objects.get(slug=slug)


if request.method == "POST":
form = VoteForm(request.POST)
if form.is_valid():
voter_id = request.user
movie_id = Entry.objects.get(slug=slug).movie
post = form.save(commit=False)
post.save()
return redirect('/movies/')

else:
form = VoteForm()

return render(request, 'list/lets_vote.html', {'entry':entry, 'form': form})


**Last but not least: the voteform from the html page:**

<form role="form" action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
{% endblock %}

/r/djangolearning
https://redd.it/5k87bx