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
Making an NLP application in python

I need to make an NLP tool for an IoT application that will basically take queries from users (like 'turn on the pump for 1 minute and inform Mark') and will process it to extract 3 basic things for further processing \- the device (pump), duration (1 minute) and the person (Mark). How should I proceed with this?

/r/Python
https://redd.it/8q7c7c
Help with quick app - what should I use?

So I am wanting to make a private, sort of quick hobbyist web app using python to gather data from Monopoly games. It definitely does not have to have many features but I would like it to have a mainly visual interface (not command line / text\-based) and do enough that it does not take away from playing Monopoly. My desire is for the player\-facing web app to be essentially like a VERY small Venmo for monopoly where players can keep track of their balances and send money to each other with a short memo attached. Additionally, I would like it to keep track of owned properties and property upgrades with the ability to trade them with other players and keep track of the amount that the properties were traded for. On the backend, I would like to keep track of all actions into a SQLite database for later analysis of the transactions themselves. The application would be a web app that *each* player can access from their phones (not an app downloaded from an app store), and mostly single view with a couple pop\-up dialogue., Maybe a settings page if we are getting frisky with the features. \-\-I really only say all this to describe the (shallow) depth of this project and what I would need it to do. This definitely is not a 'scalability' or 'big data' problem.

In the past i have used Google Sheets to keep track of data and had my players learned on my preferred format, but it really made the game not fun to actually play (which inevitably affects the data itself). **I am hoping for guidance with finding a small stack of packages/technologies in Python I could use quickly to build this app, and hopefully have it remain free to develop** (server hosted locally, spun up for each monopoly game is an idea). The app's main purpose is to gather data, not be a robust tool to use with every Monopoly game (maybe eventually...), but still be visual enough for the players and not detract from gameplay. I have been needing to learn Flask/Django and this could be my opportunity but would they be too much for this project? What would be the *easiest* stack with the smallest learning curve?

Thanks all for the input!

/r/Python
https://redd.it/8q7mdr
Django REST and OAuth2

Hello everyone!

I'm starting a project with *Django REST framework* , and I have a question about the login operation, I'm planning to use OAuth2.

When I get the user information, login, password, etc, and I use a serialize, all that information is going to a json api, but what about the password? It will be there in the middle of the json for everyone (I mean everyone who is working in the project) to see it? I'm just wondering, I didn't start the project yet, about to start this next week.

/r/django
https://redd.it/8q5xvf
Forms: Attribute Error

As part of learning Django, I am currently trying to build a little project. At this stage, as a preliminary task, I am attempting to pass the user\-input from the Form to the template (results.html). However, I am getting the error the below, and I can't seem figure out why!

If anybody could let me know what I'm doing wrong, I'd be greatly appreciative :D Thanks in advance!

**ERROR**

AttributeError at /search_query/ 'SearchHashtagForm' object has no attribute 'cleaned_data'
Request Method: POST
Django Version: 2.0
Exception Type: AttributeError
Exception Value:'SearchHashtagForm' object has no attribute 'cleaned_data'
Exception Location:/mnt/data/.python-3.6/lib/python3.6/site-packages/django/forms/models.py in _save_m2m, line 424
Python Executable:/mnt/data/.python-3.6/bin/python
Python Version:3.6.5
Python Path:['/mnt/project', '/mnt/data/.python-3.6/lib/python36.zip', '/mnt/data/.python-3.6/lib/python3.6', '/mnt/data/.python-3.6/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6', '/mnt/data/.python-3.6/lib/python3.6/site-packages']

**models.py**

from django.db import models


class Location(models.Model):
""" Model representing a Location, attached to Hashtag objects through a M2M
relationship """

name = models.CharField(max_length=1400)

def __str__(self):
return self.name


class Hashtag(models.Model):
""" Model representing a specific Hashtag serch by user """

search_text = models.CharField(max_length=140, primary_key=True)
locations = models.ManyToManyField(Location, blank=True)

def __str__(self):
""" String for representing the Model object (search_text) """
return self.search_text

def display_locations(self):
""" Creates a list of the locations """
# Return a list of location names attached to the Hashtag model
return self.locations.values_list('name', flat=True).all()

**forms.py**

from django import forms
from django.forms import ModelForm

from .models import Location, Hashtag


class SearchHashtagForm(ModelForm):
""" ModelForm for user to search by hashtag """

def clean_hashtag(self):
data = self.cleaned_data['search_text']
# Check search_query doesn't include '#'. If so, remove it
if data[0] == '#':
data = data[1:]
# return the cleaned data
return data


class Meta:
model = Hashtag
fields = ['search_text',]
labels = {'search_text':('Hashtag Search'), }
help_texts = { 'search_text': ('Enter a hashtag to search.'), }

**views.py**

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse

from .models import Location, Hashtag
from .forms import SearchHashtagForm


def hashtag_search_index(request):
""" View function for user to enter search query """
hashtag_search = SearchHashtagForm()
# If POST, process Form data
if request.method == 'POST':
# Create a form instance and populate it with data from request (binding)
form = SearchHashtagForm(request.POST)
# Check if form is valid
if form.is_valid():
hashtag_search.search_text = form.cleaned_data['search_text']
hashtag_search.save()
# redirect to a new URL
return HttpResponseRedirect(reverse('mapping_twitter:results'))

# If GET (or any other method), create the default form
else:
form = SearchHashtagForm()

context = {'form':form}
return render(request, 'mapping_twitter/hashtag_search_index.html', context)

def results(request):
""" View for
search results for locations associated with user-inputted
search_text """

search_text = hashtag_search
location = get_object_or_404(Hashtag, search_text=search_text)
location_list = location.display_locations()

context = {'search_text':search_text, 'location_list':location_list}
return render(request, 'mapping_twitter/results.html', context)

/r/djangolearning
https://redd.it/8q8buz
authtools: do not create one-to-one profile object on user creation.

Hello,

I am using the authtools plugin to manage the user and its profile in django, but when I create the user, it does not create its profile, I have to go to the admin part of the site and create it manually.

I separated the applications into account and profile.

This is the profiles model:

class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
primary_key=True)
slug = models.UUIDField(default=uuid.uuid4, blank=True, editable=False)
email_verified = models.BooleanField("Email verified", default=True)


This is the signal.py, that is inside of the profiles application:

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_profile_handler(sender, instance, created, **kwargs):
if not created:
return
profile = models.Profile(user=instance)
profile.save()
logger.info('New user profile for {} created'.format(instance))

This is the admin.py of the account app:

class UserProfileInline(admin.StackedInline):
model = Profile


class NewUserAdmin(NamedUserAdmin):
inlines = [UserProfileInline]
list_display = ('is_active', 'email', 'name', 'permalink',
'is_superuser', 'is_staff',)

# 'View on site' didn't work since the original User model needs to
# have get_absolute_url defined. So showing on the list display
# was a workaround.
def permalink(self, obj):
url = reverse("profiles:show",
kwargs={"slug": obj.profile.slug})
# Unicode hex b6 is the Pilcrow sign
return format_html('<a href="{}">{}</a>'.format(url, '\xb6'))


admin.site.unregister(User)
admin.site.register(User, NewUserAdmin)
admin.site.register(Profile)


When I signup a user, both the user and the profile objects are created, only they are not linked. Why is that?

Thank you




/r/django
https://redd.it/8q4ob3
Add multiple ordered similar arguments to manage command

I'm trying to build out a command that'll looker similar to this

`python manage.py gen-data primary=10-state with=30-users with=30-visits`

The goal here is to do test-data generation where the command doesn't become crazy for any of our front end devs. That command would do something like create 10 states, create 30 users who live in each state, and create 30 web visits for each of those users.

I know how to do the actual generation of the data, but I can't seem to find out how to handle having the same argument repeated like that.

Any help would be much appreciated.

Solved:
Turns out you can do a list object as a arg

parser.add_argument(
'--with', default=[], dest='withs', action='append',
help="Specify district ids by comma separated list.")

` python manage.py generate_data --model=user --with=Super --with=cali --with=frag --with=ilistice --with=xpial --with=idocious`

`['Super', 'cali', 'frag', 'ilistice', 'xpial', 'idocious']`


/r/django
https://redd.it/8q9scf
[D] Improving Language Understanding with Unsupervised Learning
https://blog.openai.com/language-unsupervised/

/r/MachineLearning
https://redd.it/8qbzom
[P] Simple Tensorflow implementation of StarGAN (CVPR 2018 Oral)

/r/MachineLearning
https://redd.it/8qh7e5
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


/r/Python
https://redd.it/8qj87y