Skip to content

Commit

Permalink
working hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Swizec committed Jan 14, 2011
1 parent 22721ed commit 3dbf075
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions TweetAWakeup/TweetAWakeup.sh
@@ -0,0 +1,6 @@
#!/bin/bash

~/.bin/isightcapture -t jpg ~/tmpTweetAWakeup.jpg
sleep 10
URL=`python ~/Documents/random-coding/TweetAWakeup/upload.py ~/tmpTweetAWakeup.jpg`
twurl tweet -d "status=${URL} #TweetAWakeup"
25 changes: 25 additions & 0 deletions TweetAWakeup/upload.js
@@ -0,0 +1,25 @@
var http = require('http');
var multipart = require('multipart');
var sys = require('sys');

function upload_file(req, res) {
req.setBodyEncoding('binary');

var stream = new multipart.Stream(req);
stream.addListener('part', function(part) {
part.addListener('body', function(chunk) {
var progress = (stream.bytesReceived / stream.bytesTotal * 100).toFixed(2);
var mb = (stream.bytesTotal / 1024 / 1024).toFixed(1);

sys.print("Uploading "+mb+"mb ("+progress+"%)\015");

// chunk could be appended to a file if the uploaded file needs to be saved
});
});
stream.addListener('complete', function() {
res.sendHeader(200, {'Content-Type': 'text/plain'});
res.sendBody('Thanks for playing!');
res.finish();
sys.puts("\n=> Done");
});
}
14 changes: 14 additions & 0 deletions TweetAWakeup/upload.py
@@ -0,0 +1,14 @@

import urllib2, base64, urllib, json, sys
from datetime import datetime

if __name__ == '__main__':
print json.loads(urllib2.urlopen('http://api.imgur.com/2/upload.json',
data=urllib.urlencode({
'key': '927ff7a7e84621a6371c2f0aaf8dc770',
'image': base64.encodestring(
open(sys.argv[1]).read()),
'type': 'base64',
'name': 'TweetAWakeup: '+str(datetime.now()),
'title': 'TweetAWakeup: '+str(datetime.now())
})).read())['upload']['links']['imgur_page']

0 comments on commit 3dbf075

Please sign in to comment.