A simple example to create a websocket server and stream tweets about a pre-defined subject to the page.
$ npm install socket.io, twitter
$ node ./app.js
| /** | |
| * For the brave souls who get this far: You are the chosen ones, | |
| * the valiant knights of programming who toil away, without rest, | |
| * fixing our most awful code. To you, true saviors, kings of men, | |
| * I say this: never gonna give you up, never gonna let you down, | |
| * never gonna run around and desert you. Never gonna make you cry, | |
| * never gonna say goodbye. Never gonna tell a lie and hurt you. | |
| */ |
| /* open up chrome dev tools (Menu > More tools > Developer tools) | |
| * go to network tab, refresh the page, wait for images to load (on some sites you may have to scroll down to the images for them to start loading) | |
| * right click/ctrl click on any entry in the network log, select Copy > Copy All as HAR | |
| * open up JS console and enter: var har = [paste] | |
| * (pasting could take a while if there's a lot of requests) | |
| * paste the following JS code into the console | |
| * copy the output, paste into a text file | |
| * open up a terminal in same directory as text file, then: wget -i [that file] | |
| */ |
| import argparse | |
| import re | |
| from multiprocessing.pool import ThreadPool as Pool | |
| import requests | |
| import bs4 | |
| root_url = 'http://pyvideo.org' | |
| index_url = root_url + '/category/50/pycon-us-2014' |
| var io = require('socket.io').listen(8000), | |
| nicknames = {}; | |
| io.sockets.on('connection', function (socket) { | |
| socket.on('user message', function (msg) { | |
| socket.broadcast.emit('user message', socket.nickname, msg); | |
| }); | |
| socket.on('nickname', function (nick, fn) { | |
| if (nicknames[nick]) { |