Search though accounts on flask-stormpath - python

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 =)

Related

Using AIML files' Predicate and Sessions with discord.py

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!!

G suite admin SDK for python insert

I am trying to find code examples on how G Suite is dealing with api calls in python. For example there is a method called insert: https://developers.google.com/admin-sdk/directory/v1/reference/users/insert#try-it which permits you to create new users under your enterprise.
The point is that they dont have an example on how you can do that and i find a bit difficult to figure it out through their documentation. Are there any know examples that i could consult?
This worked for me, also using the QuickStart guide.
First, build your user object with the minimum required fields.
Note, this is just a dictionary containing a basic representation of a user object.
The minimum fields to use look like this:
user = {"name": {"familyName": "Burton", "givenName": "Haniel",}, "password": "some_pass", "primaryEmail": "haniel#yourgsuitedomain.com",}
You can add or update additional fields like any other dictionary:
user["orgUnitPath"] = "/Imported"
Then, call the insert method like this in your main() program:
result = service.users().insert(body=user).execute()
Result should be a JSON representation returned by the Directory API with additional attributes that are automatically added by Google.
Some additional links in case anyone else finds it useful:
https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.users.html
I'm working on building a small script/app to handle user creation, updates, and password resets to automate provisioning from our student information system. Depending on how it goes I might post to GitHub and add links here to save others time.

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.

Python, mongo + spider monkey

Ok, so this isn't exactly a question that I expect a full answer for but here goes...
I am currently using a python driver to fire data at a mongo instance and all it well in the world. Now I want to be able to pull data from mongo and evaluate each record in the collection. Now I need to pass in to this evaluation a script that will look at the row of data and if a condition is met return true i.e.
(PSUDO CODE)
foreach(row in resultSet)
if(row.Name=="Chris) return true
return false
Now the script that I use to evaluate each item in the row should be sandboxes somehow with limited functionality/security privileges.
In other words the code will be evaled, and I dont want it to have rights to i.e. include external libraries, call remote servers or have access any files on the server etc...
With this in mind I know that mongo uses something called spider monkey (which I gather is a JS evaluator) to write queries. I wonder would it be possible to take the result of a mongo call and pass it to an evaluated javascript function using spider monkey (somehow) to achieve what I am after? If so would this be safe enough.
To be honest, Im writing this question and I realize its sounding a lot like one of those "please help, how to code the world" type questions but any pointers would be helpful.
Have you looked at $where clauses in MongoDB? Seems like those would pretty much give you exactly what you're looking for. In PyMongo it would look something like:
db.foo.find().where("some javascript function that will get applied to each document matched by the find")

Categories

Resources