View gist:816cba067f0e0dccc524
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def get_status_code(url): | |
try: | |
r = requests.get(url) | |
print "Processing " + url | |
if len(r.history) > 0: | |
chain = "" | |
code = r.history[0].status_code |
View gist:3717461
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import urllib2 | |
import json | |
import re | |
def findID(str): | |
# extracts the status ID from teh following string example: | |
# "http://twitter.com/IBPTravels/statuses/75907873892339712" | |
matchObj = re.match('(.)+statuses\/(\d+)', str, re.I) | |
return matchObj.group(2) |
View node1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Client side | |
app.get('/trends', function(req, res){ | |
twitterProcessor.getTrends( function(error, trendData){ | |
res.render('trends.jade',{ locals: { | |
trends:trendData // here's the data you pass to client | |
} | |
}); | |
}); | |
}); |
View mr2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map = function(){ | |
emit(this.tag, {tag_date: this.tag_date, count:this.count}); | |
} | |
var reduce = function(key, values){ | |
var obj = {value: []}; | |
for(var i in values){ | |
obj.value.push({tag_date:values[i].tag_date, count:values[i].count}); | |
} | |
return obj; |
View mr1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coll.mapReduce( | |
//map | |
function(){ | |
emit(this.tag, {tag_date: this.tag_date, count:this.count}); | |
}, | |
// reduce | |
function(key, values){ | |
var obj = {value: []}; | |
for(var i in values){ | |
obj.value.push({tag_date:values[i].tag_date, count:values[i].count}); |
View get3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response.on('end', function(){ | |
var dataObj = JSON.parse(completeResponse); | |
var saveObj = { | |
id: dataObj["id"], | |
created_at: dataObj["created_at"], | |
description: dataObj["description"], | |
followers_count: dataObj["followers_count"], |
View get2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var completeResponse = ""; | |
request.on('response', function (response) { | |
response.on('data', function (chunk) { | |
//res.send("data: " + chunk); | |
completeResponse += chunk; | |
}); |
View get1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/', function(req, res){ | |
var user = "twitterapi; | |
var completeResponse = ""; | |
var options = { | |
host: 'api.twitter.com', | |
port: 80, | |
path: '/1/users/show.json?screen_name=' + user | |
}; |
View upload3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/', function(req, res){ | |
var temp_path = req.files.uploadfile.path; | |
var save_path = './public/images/' + req.files.uploadfile.name; | |
fs.rename(temp_path, save_path, function(error){ | |
if(error) throw error; | |
fs.unlink(temp_path, function(){ | |
if(error) throw error; |
View upload2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var fs = require('fs'); // we will need it for file uploads | |
var app = module.exports = express.createServer(); | |
app.configure(function(){ | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
app.use(express.static(__dirname + '/public')); |
NewerOlder