Using AIML files' Predicate and Sessions with discord.py - python

I was learning about AIML files with Python. I know I need to use aiml module of Python, but I want to use it with discord.py.
I want to make it so that, suppose I am talking with the bot, and I tell that my dog name is Blake. And there is another person whose dog name would be Tiger. How can I store it? In a db or I should use json files? I can make the sessionID as the user ID. But then, I need some guidance regarding storing all this information...
Sorry for not showing any code that I wrote, because I am not able to understand how can I achieve this. Some help/guidance would be appreciated, so that, the bot would be able to respond, like I ask it, what's my dog's name, then it would answer with Blake...
Thank you

To set a predicate in AIML, you should use
<category>
<pattern>MY DOG IS CALLED *</pattern>
<template>Ok, I will learn your dog is called <set name="dog"><star/></set></template>
</category>
You can keep track of each person by keep a note of their clientid. Your AIML interpreter should keep a track of these predicates and you don't need to specify how to store them.

Use SQL databases:
SQLite
https://www.sqlite.org/index.html
PostgreSQL
https://www.postgresql.org/
Or NoSQL:
MongoDB atlas
JSON is not a database, and should not be used as one!!

Related

Mapping fields inside other fields

Hello I would like to make an app that allows the user to import data from a source of his choice (Airtable, xls, csv, JSON) and export to a JSON which will be pushed to an Sqlite database using an API.
The "core" of the functionality of the app is that it allows the user to create a "template" and "map" of the source columns inside the destination columns. Which source column(s) go to which destination column is up to the user. I am attaching two photos here (used in airtable/zapier), so you can get a better idea of the end result:
adding fields inside fields - airtableadding fields inside fields - zapier
I would like to know if you can recommend a library or a way to come about this problem? I have tried to look for some python or nodejs libraries, I am lost between using ETL libraries, some recommended using mapping/zipping features, others recommend coding my own classes. Do you know any libraries that allow to do the same thing as airtable/zapier ? Any suggestions ?
Save file on databases is really a bad practice since it takes up a lot of database storage space and would add latency in the communication.
I hardly recommend saving it on disk and store the path on database.

Search though accounts on flask-stormpath

I have a flask.ext.stormpath instance and I would like to fetch all users (filtered with created_at)
I have tried several stuff that are not working
flask.ext.stormpath.accounts
Sorry for the short question but for clarity, I think I need something like this
https://docs.stormpath.com/rest/product-guide/latest/reference.html#search-filter
Heyo,
When you use Flask-Stormpath, you can access the underlying Application object by saying:
stormpath_manager.application
This means you can do stuff like:
for account in stormpath_manager.application.accounts:
print('Email: {}'.format(account.email))
Any sort of Python SDK stuff will work here as expected =)

Django+autocomplete_light dynamic choiceField in form

I have a strange problem.
I don't know how I should even start doing it, my written english is really bad, so I can't really google it, because it seems complicated.
I'm doing a simple database web application using Django 1.7.1, I want to use autocomplete_light for autocompletion of some fields.
I'm using SQLite Database, in DB I have some "dictionary" tables, it means that user is likely to use some names multiple times in other records, so in "master" table, I store just id of that name. Is there any way of making such ChoiceFields and MultipleChoiceFields (for "reversed" situation), that if user will write new value (not stored in "dictionary" yet) in it, it will be automatically added to "dictionary" table?
I would be really thankful for any advices, or even suggestions where should I search such thing.
I did it as simple add another like in administration panel:
http://django-autocomplete-light.readthedocs.org/en/stable-2.x.x/addanother.html

Is there a way to print out output in a pyramid view callable?

I am new to python and pyramid and I am trying to figure out a way to print out some object values that I am using in a view callable to get a better idea of how things are working. More specifically, I am wanting to see what is coming out of a sqlalchemy query.
DBSession.query(User).filter(User.name.like('%'+request.matchdict['search']+'%'))
I need to take that query and then look up what Office a user belongs to by the office_id attribute that is part of the User object. I was thinking of looping through the users that come up from that query and doing another query to look up the office information (in the offices table). I need to build a dictionary that includes some User information and some Office information then return it to the browser as json.
Is there a way that I can experiment with different attempts at this while viewing my output without having to rely on the browser. I am more of a front end developer so when I am writing javascript I just view my outputs using console.log(output).
console.log(output) is to JavaScript
as
????? is to Python (specifically pyramid view callable)
Hope the question is not dumb. Just trying to learn. Appreciate anyones help.
This is a good reason to experiment with pshell, Pyramid's interactive python interpreter. From within pshell you can tinker with things on the command-line and see what they will do before adding them to your application.
http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/narr/commandline.html#the-interactive-shell
Of course, you can always use "print" and things will show up in the console. SQLAlchemy also has the sqlalchemy.echo ini option that you can turn on to see all queries. And finally, it sounds like you just need to do a join but maybe aren't familiar with how to write complex database queries, so I'd suggest you look into that before resorting to writing separate queries. Likely a single query can return you what you need.

Query regarding data entry form

I am curious about something I encountered when I was registering on the wakari website. I entered my username which was something like abc.def.ghi and all other information and submitted the form ( or at least tried to submit! ). It threw up an error which said "username must be a valid python variable", so they were obviously doing something in their back-end with usernames as python variables. Would anyone explain to me if this is some sort of design scheme that they are using wherein they store user information as python variables or something like that. Again I apologize since this is not really a specific programming question but this is eating me up and I must know why that happened.
The following is the URL:
https://www.wakari.io/usermgmt/loginorregister
This is pure conjecture. One thing I could see wakiri doing is using the usernames as a module name for your code. That might be interesting. So storing user code as wakiri.<username>. Then the application might be doing an import wakiri.<username> with some interesting stuff in the __init__.py that runs whatever it finds.
Maybe that's it. Or maybe they are storing user code in files on disk. Maybe user code is written out to a file that contains lots of dictionaries that contain code and are named after the username?
Maybe they aren't even using it and just think it is cute to restrict people to valid Python variables.
I'm a Wakari developer, and we've only just caught this question. The short version is that you are pretty safe with a valid UNIX username, and the "error" text should say something using better "plain english" to this effect.
The reason we say the username needs to be a valid Python module name is that we're imagining a day when users could have something like ~/public_python as a place to put directly-shareable code, and then other users could access this via something like from wakari.users import steve. We'd leave it up to you to figure out if you trust user steve enough to import his code directly.

Categories

Resources