Way to get timestamp of last activity for all Slack users - python

I am building a Python script which retrieves a set of information for all Slack users of the organization that I work. Currently, I was asked by the stakeholders to retrieve the last time that our organization's users were active on Slack. I came across the users.getPresence method but this can only return a timestamp for the owner of the token. Has anybody worked on that before? Thanks.

It depends a bit how you define "active on Slack".
If getting the date and time a user was logged in last is enough, take a look at team.accessLogs, which will give you the timestamp of the last login for every user (date_last).
This will not reflect whether the user performed any activity, e.g. posting a message or uploading a file though.
However, note that this API method works for paid plans only.

Related

Triggering actions in Python Flask via cron or similar

I'm needing to trigger an action at a particular date/time either in python or by another service.
Let's say I have built an application that stores the expiry dates of memberships in a database. I'm needing to trigger a number of actions when the member expires (for example, changing the status of the membership and sending an expiry email to the member), which is fine - I can deal with the actions.
However, what I am having trouble with is how do I get these actions to trigger when the expiry date is reached? Are there any concepts or best practices that I should stick to when doing this?
Currently, I've achieved this by executing a Google Cloud Function every day (via Google Cloud Scheduler) which checks if the membership expiry is equal to today, and completes the action if it is. I feel like this solution is quite 'hacky'.
I'm not sure which database you are using but I'm inferring you have a table that have the "membership" details of all your users. And each day you run a Cron job that queries this table to see which row has "expiration_date = today", is that correct?.
I believe that's an efficient way to do it (it will be faster if you have few columns on that table).

Django + DRF: User schedule availability

I'm building an API where I need return to users events with a timestamp within in their available time. Since this is an API I don't need a front-side, I will receive a json in backend, but I am not clear about which data should I receive. User should be able to mark a schedule as monthly, weekly, etc. or just for one day. I have found projects like this one django-scheduler but I don't know if it will fits my needs. Any advice?

After executing a payment in PayPal's REST API, sometimes I don't get an email back

So, I have a Python PayPal REST API app that accepts payments. I create a Payment object and redirect the user to PayPal. When they get back I do:
payment = Payment.find(trans_id)
payment.execute({ "payer_id": payer_id })
If that's successful I get the email address of the payer like:
payer_info = payment.payer.payer_info.to_dict()
email = payer_info['email']
That works great, except sometimes it doesn't! Sometimes (actually just once so far) I get a payer back that doesn't have an email address. How is that possible? Is that something my code should expect? The system I'm working in needs an email as a primary key for our user database, so this is pretty hard to accommodate.
Thanks for any and all help!
Even if this question is 1 year old, this still seems to be a problem with the current Paypal REST API: sometimes the email field just doesn't show up.
Unfortunately I cannot provide a solution, as I am facing the same issue, but I have at least a little suggestion: the frequency of this phenomenon has slightly increased since I tried to get the email BEFORE executing the payment; when I moved the request AFTER the payment, this event became much less frequent; finally, in the few cases where this still occurs, a quick look at the payment log showed the proper email addresses, as expected, so these does not seem "special" paypal payments.
It seems to me that the email field is just "slow" to appear, even if the system properly waits each response from the paypal server... I am going to try to solve this problem by adding a timed retry in case of failure, in order to give few additional seconds to the paypal server to respond... but if someone more experienced than me could give a more solid opinion on this matter that would be greatly appreciated!
ps: actually my platform uses an up-to-date version of the official paypal PHP SDK

Get list of connected users with Django

I'm looking for a way to keep track of users that are online/offline. So if I present all users in a list i could have an icon or some kind of flag to show this. Is this built in in Django's default Auth system?
My first thought was to simply have a field in my profiles called last_logout in the models and update it with the date/time each time user logged out.
With this info and the built in last_login I should be able to make some kind of function to determine if the user is loggedin/online right?
Or should I just have a boolean field called "online" that I can change when user logs in and out?
With only django it will be hard to do. For such task async frameworks are more suitable.
For example, tornado.
Users won't do logout explicitly every time they go offline. They just close their browser and that's it. You can't know it with only django auth app. It is not designed for such tasks.
Even if you will check for not expired session, it not gives you all online users, because session can be non-expired for 30 days.
So to get real online users, possible solutions are:
Every user will send some data via javascript to your server, for example every 10 seconds. You can fetch that data on server and put user into cache and set cache key to be alive for 10 seconds. So when you need to know, who are online now, you'll check your cache. But it is not a good solution, because it will need a lot of server resources.
Use async framework (tornado) at server side (you can setup separate process for exact requests). And use websockets (SockJS is a good library for that at client side). It is a more complicated solution, but it is better.
You have to consider what exactly means for the users to be "online". Since any user can close the browser window any time and without the server knowing about that action, you'd end up having lots of false "online" users.
You have two basic options:
Keep track of the user's last activity time. Every time the user loads a page you'd update the value of the timer. To get a list of all online users you'd need to select the ones with an activity before X minutes. This is what is done by some web forums.
Open a websocket, long polling connection or some heartbeat to the server. This is what Facebook chat does. You'd need more than just django, since to keep a connection open another kind of server-side resources are needed.

Google Checkout Notification API Python Example

Currently, there are absolutely no code snippets of the Notification API in Python. I am currently at a loss as the documentation, as thorough as it is, seems to be missing important information necessary to actually code a solution for myself.
Currently, I have a single product that I wish to submit to Google Checkout along with a hidden item, which would be the userid of the user currently logged into my site. Upon payment completion, the callback URL will receive the information, and process the user's payment information (serial key, order number, userid) and update the database.
I am using Django.
Gchecky is there, but it doesn't seem to work - and I've attempted multiple times to get a hold of the developer.
Have a look at Chippy's Shop:
http://code.google.com/p/chippysshop/
http://code.google.com/p/chippysshop/source/browse/googlecheckout.py

Categories

Resources