0

For the past several days, I have looked into starting to turn my website towards realtime. I looked at Gevent (can't use b/c I'm using Python 3.3), Tornado, and Webalchemy.

Webalchemy and Tornado are both options. At this time, I have not successfully meshed their code with mine..that is, I have not been able to get a realtime result. I have set a modest goal for myself: getting the upvote/downvote ticker to display in realtime.

This is my upvote function:

@mod.route('/updebate/<int:entries_did>')
def up_vote(entries_did):
    connection = g.db.session.connection()
    g.db.engine.execute(
        'update users_user set rating = rating + 1 where id in (select id from users_debates where users_debates.did ="{0}")'.format(entries_did))
    g.db.engine.execute(
        'update users_debates set rating = rating + 1 where did = "{0}"'.format(entries_did))
    # g.db.commit()
    return redirect(request.referrer)

As you can see, right now I'm simply "request.referrer"-ing..definitely not what I want to do.

Here is the code from my HTML page:

{% for entry in entries %}
    <li><h2>
        <a href="/updebate/{{ entry.did }}" style="text-decoration:none; color:orange;">&#11014;</a>{{ entry.rating }}<a href="/downdebate/{{ entry.did }}" style="text-decoration:none; color:orange;">&#11015;</a><a href="/debate/{{ entry.did }}">{{ entry.title }}</a></h2>{{ entry.text|safe }}

        CREATED BY: {{ entry.name }}
  {% else %}
    <li><em>Unbelievable.  No entries here so far</em>
  {% endfor %}

Thoughts?

  • Your page would have to be constantly checking your server for changes to the page, not unlike the way a chat app works. – j08691 Jul 16 '13 at 17:00
  • 2
    possible duplicate of [How to make all connected browsers reload initiated by a server-side event](http://stackoverflow.com/questions/1964494/how-to-make-all-connected-browsers-reload-initiated-by-a-server-side-event) *and* [various others](https://www.google.co.uk/search?q=site%3Astackoverflow.com+notify+browser+when+page+content+changes+on+server&oq=site%3Astackoverflow.com+notify+browser+when+page+content+changes+on+server&aqs=chrome.0.69i57j69i58.9485j0&sourceid=chrome&ie=UTF-8) – Quentin Jul 16 '13 at 17:00
  • 1
    well, you need some real time process here, using socket.io and node.js are good stuff for this kind of work – Rikky Jul 16 '13 at 17:02
  • @rikky those are good suggestions, but long polling as suggested in quentin's link works great too – user428517 Jul 16 '13 at 17:05

2 Answers2

1

You can use technology as WebSocket to push modification to the browser or you can update the content of a piece of your page by using ajax call to the server at regular time.

Sirus64
  • 46
  • 4
0

after spending a while on the Internet, I've found FireBase, if you want to have a fast, cheap, simple and totally client-side work, this would help. Good examples here

Rikky
  • 475
  • 2
  • 7