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 |
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) |
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 | |
} | |
}); | |
}); | |
}); |
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; |
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}); |
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"], |
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; | |
}); |
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 | |
}; |
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; |
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