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 built a Django-powered job board/aggregator for remote Python jobs (x-post on /r/python)

Hi guys,

I just launched https://www.RemotePython.com a few days ago (built in Python of course, with Django). I started the project as I'm a freelance Python developer and only work remotely, and thought it would be nice if there's a site that only lists remote Python jobs as that would save people time from having to check/subscribe to multiple sites.

Right now, I'm doing the job postings manually. I have a list of sites that I check daily. I make sure that the job actually involves Python before posting it as sometimes you'll see postings like "we're a Java shop, but we'd also consider candidates who have experience in Python, etc.", and they get tagged as "python" because it appeared in the text.

I hope some of you will find the site useful and any feedback is appreciated!

P.S. For those curious about the tech stack:

- Python 3.5
- Django 1.10
- PostgreSQL 9.6
- Ubuntu 14.04
- Nginx
- Gunicorn
- Bootstrap 3
- jQuery


/r/django
https://redd.it/5mbji3
Help needed to create app similar to IFTTT

I am trying to emulate the workflow of IFTTT on one of my work. The app will be consuming natural event data like Earthquake, Hurricane, etc. Users can subscribe on those events based on some rule like IFTTT e.g. User1 (U1) subscribes on Earthquake with magnitude >4 and User2 (U2) subscribes on magnitude >5. Based on this, if an earthquake with magnitude of 6 occurs, U1 and U2 should be notified. If it happens to be magnitude 4.5, only U1 should be notified. I am planning to do this in Django using MongoDB + PostgreSQL. My approach is something like this: Save rules for each user in MongoDB. Once an event occurs, find users who are subscribed on it and if the rule matches, fire a notification. Is there any better way to solve this problem? Any help is appreciated. Thanks.

/r/django
https://redd.it/5mc2qv
Passing invalid form with errors to another view?

If view 1's form POST's to view 2, and view 2 handles the form data (ex: validation, using form data to change database, etc.), but then you want to re-render view 1's template with form errors in the case of invalid data... What useful solutions exist? Besides Javascript and handling (I'd like to know if there is a conventional server side solution).

I'm thinking re-direction is necessary, otherwise rendering the old template from view 2 will require repeating tons of logic.

I considered using sessions to pass the form data back to view 1, and have view 1 check the session for form data before creating a new form to render, but am wondering if there's a simpler way.

Thanks!

/r/djangolearning
https://redd.it/5mbhlj
psync - sync files to remote server with ease; feedback / PR appreciated
https://github.com/lazywei/psync

/r/Python
https://redd.it/5mddww
[Help] An email listener of sorts

I'd like to set up a self-hosted email address. It won't be used for sending email, just and end-point to receive an email and then process it with a python script. From there it will be able to use the parsed data to do things like push rich notifications, etc.

Where I'm stuck, is the world of email. Can anyone point me to the easiest solution to this on Ubuntu?

/r/Python
https://redd.it/5mbukv
[Ask Flask] Using Flask alongside an apache server

Hello there /r/flask,

so I am building a web application which is served by an apache server on my raspberry.
Flask is running on the same server, but a different port (5000).

If I try to make a GET request with JQuery, there is a "Cross-Origin Request Blocked" in JavaScript, due to flask running on a different port than the apache server.

*if you have ideas on how to improve the setup (i.e. not using an apache server) please share those too.*

**How would you go about solving this?**

/r/flask
https://redd.it/5md1wq
Need help! Python script for geocoding!

The below code was given to me by a DBA who was let go. My knowledge with python is quite basic, so I'm hoping this sub can help. I really appreciate any help!!!
My issues:
1. I'm not sure exactly how he ran the file.
2. Where do I put the .py file and the addresses.txt file? Same folder?

Here is a sample of the addresses.txt file:

1,16088+San+Pedro+Ave.+San+Antonio,+TX+78232

2,10811+Town+Center+Dr+San+Antonio,+TX+78251

3,25615+N.+US+Hwy+281+San+Antonio,+TX+78258

4,8230+N.+Loop+1604+W.+San+Antonio,+TX+78249

And now the code: [Pastebin Link](http://pastebin.com/Mk5XUXd1)

import urllib, json
from urllib import request

uid=""
address=""

f=open("addresses.txt","r")
fo=open("latlng.txt","w")

for row in f:
uid=row.split(",",1)[0]
address=row.split(",",1)[1].replace("\n","")
myurl = "https://maps.googleapis.com/maps/api/geocode/json?address=" +address +"&key=MY_KEY_HERE"
try:
googleResponse = request.urlopen(myurl)
jsonResponse=json.loads(googleResponse.read().decode("utf-8"))
lat=jsonResponse["results"][0]["geometry"]["location"]["lat"]
lng=jsonResponse["results"][0]["geometry"]["location"]["lng"]
fo.write(str(uid)+"|"+str(lat)+"|"+str(lng)+"\n")
except Exception as e:
print(uid,address,e)
pass

f.close()
fo.close()

Edit: code formatting

/r/Python
https://redd.it/5memtv
One annoying thing about Django

long time flask user, everytime i want to start django this one thing annoys me and i end up leaving django.
i usually create a dir, then go into that dir and create env, install django via pip, then create project and then create app. result is this awful looking dir structure for a single app site. doesnt anyone else find this annoying?

projectname/
env/
projectname/
projectname/...
projectnameapp/...
manage.py

ideally i would like this:

projectname/
env/
manage.py
projectname/
appname/

how? or why not?

/r/django
https://redd.it/5mf5sd
ListView in views.py

Hi, I'm pretty new to Django, how would I change the below snippet to work with other data which needs to be passed through render()

urls.py

url(r'^$', ListView.as_view(queryset=Product.objects.all()
.order_by("-time_created")[:4], template_name="main_site/index.html")),

It works EXACTLY how I want it, however I can't pass other data through to the template in views.py

This is my view:

def index(request):

data = {
'categories':[
('footballs', 'Footballs'),
('accessories', 'Accessories'),
('kits', 'Football Kits'),
('training-equipment', 'Training Equipment'), ]
}


Also, feel free to criticize my code to help me improve! Thanks!

I've tried everything I know to pass it through..

/r/django
https://redd.it/5mdbpb
[D] Why is everything so quiet on the natural language processing front?

At NIPS this year, there was a clear focus GANs, image processing, Bayesian ML and reinforcement learning (as well as parties and RocketAI). I picked out a couple of interesting talks on natural language generation, but it seems to me things are generally quiet on that front, and there certainly was not much buzz in 2016 apart from some efforts in translation.

Is this due to blockers, secrecy or both? I'm fascinated that we can now generate photo-realistic content, but not realistic language utterances. Natural language is a discrete space and most people only use ~2000-3000 words to communicate or ~100-200 characters.

/r/MachineLearning
https://redd.it/5mcs0x
Form method POST, still allowing 'back' button. At risk for double submittal.

I'm still relatively new to Django, but I can't seem to find this answer anywhere.

Any change to database is being done through forms via 'post' method and not 'get'. However, I still seem to be able to go 'back' on the web browser navigation through multiple 'posted' forms. I'm afraid this may end up in a double submittal.

I figured that this would not be allowed by default, but is this something I have to code for? Is it because I'm using the built-in webserver instead of Apache, IIS, etc.? Any advice would be appreciated. Thanks.

/r/django
https://redd.it/5mgwxw
I made a GUI for Jupyter Notebook, let me know what you think!

I've called it Jupyter Wrapper. Here's the description I provide on the website.


Jupyter Wrapper provides a GUI for Jupyter Notebook server.

I developed this because I was tired of always needing to keep a cmd window open while the server is running,
and that configuring command line arguments and working directory required a custom batch file.

This tool also provides the ability to restart the Jupyter Server remotely via a browser.
To do so: select an available port, forward this port in your router, then visit the specified ip:port combination in a browser.
Eg. If you have an external ip address of 27.121.21.55 and you've chosen port number 65000, you would visit http://27.121.21.55:65000?server_restart to trigger a server restart


It can be found here: http://ashhall.net/projects/jupyterwrapper/

/r/IPython
https://redd.it/5mhn6g
What font do you use for development?

I generally use Consolas on Windows and Ubuntu Lite on Linux. I mostly use vim in terminal/cygwin these days with the occasional Notepad++ when I'm on Windows. The 2 fonts seem to work fine for the most part but there are a few letters, numbers, and characters that look too similar. There was a premium font that made specifically for developers that made a conscious effort to distinguish some of those characters. Naturally I went looking for it on the web but turned up empty handed. I did however stumble upon [this topic on Slant](https://www.slant.co/topics/67/~programming-fonts) and it made me wonder what other fonts developers use? Specifically Python developers

/r/Python
https://redd.it/5mif4u