github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

lukeman / tootfiles

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 6
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Store binary files in your Twitter stream. Why not? This is the internet. — Read more

  cancel

http://lukehatcher.com/2009/05/storing-binary-data-in-twitter/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Updated blog post URL, as I changed the slug at the last minute. 
lukeman (author)
Sun May 03 13:23:26 -0700 2009
commit  727cffcc44d3bc72bf3780e43036c2817d502b5c
tree    c33c44ee556ad6c695453f06231db8061ab5e355
parent  eafc08f22984f4990d4a061af027224612483dd4
tootfiles /
name age
history
message
file README.md Loading commit data...
file helloworld.gif
file tootfiles.py
README.md

tootfiles.py

by Luke Hatcher

Original blog post here: http://lukehatcher.com/2009/05/storing-binary-data-in-twitter/

Store your data in Twitter. Brilliant.

Let's be honest: this is probably the worst idea ever, but I laughed so hard at the prospect of storing useful amounts of data in 140 byte text messages that I had to see how it would work.

I don't think using this script is against the Twitter TOS, but I really can't be responsible if you somehow abuse things and screw it up for all of us. Don't pee in the pool, OK?

Prerequisites

  • python-twitter - Used to post tootfiles to Twitter HQ.
  • simplejson - Used to parse toots in the decode process.
  • BeautifulSoup - Used to scrape toots in the decode process. This might be removed in a later version, if I ever implement toots as linked-lists.

Usage

This script can be used either as a standalone utility script or as a library.

Standalone

Encoding a file to toots

To test encoding a file, simply pass the script a binary file with the encode flag and it will print the toot array to standard out. Go hog wild if you wish, but know that large files will generate a huge amount of output.

python tootfiles.py -e helloworld.gif

To send that file to a Twitter stream, simply add your Twitter credentials using the user and password flags. I highly recommend setting up a second Twitter account to publish any data to. Small files are good here--keep it under 5KB for best results.

python tootfiles.py -e helloworld.gif -u someuser  -p somepass

Decoding a published tootfile

To decode a published tootfile, you'll need to find a valid header status id to work with. I just happen to have one available, so we'll use it. Because we're playing nicely, the decoded file will go to standard out, but feel to redirect it to an actual file for your own purposes.

This command will pull down a small 'hello world' image:

python tootfiles.py -d 1684586022 > helloworld.gif

This command pulls down the Google logo (82 toots in all!):

python tootfiles.py -d 1684577533 > google.gif

As a code library

If you're interested in using tootfiles in another python project, you can stick its folder somewhere on your python path and just import it. The below code snippet outlines how to encode and decode using the library.

import tootfiles

# encode a file
t = TootEncoder('filename')
print t

# publish said tootfile to twitter
t.publish('username', 'password')

# decode a file
d = TootDecoder('12345678')  # arg is the tootfile headers
                             # twitter status id
print d

# write it out with its original filename
d.write()                    # if file exists, you must grant
d.write(overwrite=True)      # overwrite privs, or it will error

d.write('somenewfilename.out')
d.write('somenewfilename.out', overwrite=True)

License

This work is covered under the MIT license, which means you're free to do what you want with it. Libre, you dig?

Copyright (c) 2009 Luke Hatcher

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Special Thanks

Special thanks goes to Peter Burns for taking a look at my code and making sure I didn't commit any high crimes or pythonic treason. His suggestions ultimately led to a better implementation of this awful idea.

Also, I should thank Scott Carpenter for his blog post on scraping toots with BeautifulSoup. I replaced my terribly poor initial method with his approach and cleaned up the code quite a bit.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server