I am new at this part of web developing and was trying to figure out a way of creating a web app with the basic specifications as the example bellow:
A user1 opens a page with a textbox (something where he can add text or so), and it will be modified as it decides to do it.
If the user1 has problems he can invite other user2 to help with the typing.
The user2 (when logged to the Channel/Socket) will be able to modify that field and the modifications made will be show to the user1 in real time and vice versa.
Or another example is a room on CodeAcademy:
Imagine that I am learning a new coding language, however, at middle of it I jeopardize it and had to ask for help.
So I go forward and ask help to another user. This user access the page through a WebSocket (or something related to that).
The user helps me changing my code and adding some comments at it in real time, and I also will be able to ask questions through it (real time communication)
My questions is: will I be able to developed certain app using Django Channels 2 and multiplexing? or better move to use NodeJS or something related to that?
Obs: I do have more experience working with python/django, so it will more productive for me right know if could find a way working with this combo.
This is definitely possible. They will be lots of possibilities, but I would recommend the following.
Have a page with code on. The page has some websocket JS code that can connect to a Channels Consumer.
The JS does 2 simple things. When code is updated code on the screen, send a message to the Consumer, with the new text (you can optimize this later). When the socket receives a message, then replace the code on screen with the new code.
In your consumer, add your consumer to a channel group when connecting (the group will contain all of the consumers that are accessing the page)
When a message is received, use group_send to send it to all the other consumers
When your consumer callback function gets called, then send a message to your websocket
Related
This question is related to backend development. I am an intermediate-knowledge university student working in this field.
For my project, I am developing a website that alerts the user if something's missing from its place. For example, a valuable thing is placed under the scrutiny of CCTV. Then I detect the object using Image processing and as the thing is gone, I want to raise an alert.
I have done Image processing and am able to detect the presence/absence of the object on my local machine. I want to deploy such a thing on the server for end-consumer usage.
But then how to do this on the server because then two things need to be done at once, the video needs to be continuously processed, and when there is an alert, a notification should be kept in the notification feed (just like any social media platform), while also continuously monitoring the video.
I am familiar with Django.
In a nutshell, I want to understand how social media websites, also sometimes show notifications while we are scrolling the feed. How two things are managed at one time?
Thank you for the help.
Regards.
Here is the thing, When I submit a form from template to view ,since the process of this view will cost a lot time. I don's think our user enjoy to wait.
So, I want to this: when user click the submit button,the browser will redirect to a new page or just show a sub-page in the same window that can print the real-time executing information.
Before I post this question, I did a little research, looks like the celery can do this thing, am I right? If there is same problem already be asked in stackoverflow ,PLZ give me the link.
Thank for your time!
(English is not my mother language, so I don't know if we have any term to describe this function,if we do,PLZ give me a hint )
django-channels could be a good solution to send information as they execute on the server side in this way you can send information on the client side by opening a websocket.
Channel can be used to post data to the client side without having to wait for the HttpResponse.
Heroku has nice post explaning channels.
Hope this helps.
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.
I'm a Social Media Manager for Musicians and Bands across the globe, and have run in to a snag and am looking for anyones opinion who can help on the matter!
I'm using a service called Ping.FM that I use for updating status messages across multiple social networks. Unfortunately, it doesn't seem the development team is in the works anymore and two of the networks no longer work, Tagged and MyYearBook. Now, these two services have no custom service API, email update, or really any kind of function for updating status messages other then using a mouse, keyboard, and browser.
Now the second part. I have a shared web host (HostGator) that I use to run and leave Python scripts running to do my bidding whenever needed. What I'm thinking of is writing a script that will monitor an email account. When an email is received, it'll post the body as a status message.
Now the tricky part, how to post the status message. The shared host is all terminal only, no GUI. If there was a GUI, I would just use something like iMacro with Firefox and a Python script to alter it in order to post the status messages. Unfortunately though, no GUI, so as far as I'm aware it's not possible.
Is there any method of doing an idea like this, but without a GUI? Something terminal based, that can achieve the same idea? Any help is appreciated, thanks in advance!
All websites have an API, called HTTP. You can use mechanize to access it, so long as it doesn't use JavaScript for dynamic display.
I am building a website for a comedy group which uses Facebook as one of their marketing platforms; one of the requirements for the new site is to display all of their Facebook events on a calendar.
Currently, I am just trying to put together a Python script which can pull some data from my own Facebook account, like a list of all my friends. I presume once I can accomplish this I can move to pulling more complicated data out of my clients account (since they have given me access to their account).
I have looked at many of the posts here, and also went through the Facebook API documentation, including Facebook Connect, but am really beating my head against the wall. Everything I have read seems like overkill, as it involves setting up a good deal of infrastructure to allow my app to set up connections to any arbitrary user's account (who authorizes me). Shouldn't it be much simpler, given I only ever need to access 1 account?
I cannot find a way to retrieve data without having to display the Facebook login window. I have a script which will retrieve all my friends, but it includes a redirect where I have to physically log myself in to Facebook.
Would appreciate any advice or links, I just feel like I must be missing something simple.
Thank you!
Just posting up my notes on the successful advice, should others find this post;
Per Daniel and William's advice, I obtained the right permissions using the Connect options. From William, this link explains how the Facebook connection works
https://developers.facebook.com/docs/authentication/
This section on setting up the actual authentication was most helpful to me.
http://developers.facebook.com/docs/api
Basically, it goes as follows:
Post a link to the following URL. A user will need to physically click on it (even if that user is just you, the site admin).
https://graph.facebook.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://www.example.com/HANDLER
This will redirect to a Facebook login, which will return to http://www.example.com/HANDLER after the user authenticates. If you wish to do more than basic reads and news feed updates you will need to include this variable in the above link: scope=offline_access,user_photos. The scope variable just includes a comma separated list of values, which Facebook will explicitly tell the authenticating user about during the login process, and they will have to OK. Most helpful for me was the offline_access flag (user_photos lets you get at their photos too), so I can pull content without someone logging in regularly (so long as I store the access token obtained later)
Have a script located at http://www.example.com/HANDLER that will take a variable from the request (so facebook will redirect to http://www.example.com/HANDLER&code=YOUR_CODE after authentication). Your handler needs to pull out the code variable, and then send the following request:
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_CLIENT_ID&
redirect_uri=http://www.example.com/oauth_redirect&
client_secret=YOUR_SECRET_KEY&
code=YOUR_CODE
This request will return a string of the form access_token=YOUR_ACCESS_TOKEN.
Just parse off the 'access_token=', and you will have a token that you can use to access the facebook graph API, in requests like
http://graph.facebook.com/me/friends?access_token=YOUR_ACCESS_TOKEN
This will return a JSON object containing all of your friends
Hope this saves someone else some not fun time straining through documentation. Thanks for the help!
It is true, that Facebook's API is targeted at developers who are creating apps that will be used by many users.
Thankfully, the new Graph API is much simpler to use than its predecessor, and shouldn't be terribly difficult for you to work with without using or creating a lot of underlying infrastructure.
You will need to implement authorization, but this is not difficult, and as long as you prompt the user for the offline_access permission, it'll only need to be done once.
The documentation on Desktop Authentication would probably be most relevant to you at this point, though you might want to move to the javascript-based authentication once you've got a web app up and running.
Once the authentication is done, all you're doing is making GET requests to various urls and working with the resulting JSON.
Here's the documentation about Events, and you can get a list of friends from the friends connection of a User.
I'm not expert on Facebook/Facebook Connect, however I've seen it used/used applications with it and it seems there's really only the 'official' way to do it. I'm afraid it looks like your best bet would probably be something along the lines of this.
http://wiki.developers.facebook.com/index.php/Connect/Authentication_and_Authorization
Regardless of how you actually 'use' it, you'll still need to authorize the application to connect to the account and this means having a Facebook App as well.
The answer to Facebook application authentication is hard to find but is actually found within the "Analytics" page of the Graph API.
Specify the following: https://graph.facebook.com/oauth/access_token?client_cred&client_id=yourappid&client_secret=yourappsecret , you will then be given an access_token that you may use on all other calls.
The Facebook provided APIs do NOT currently provide this level of functionality.