A simple python-based DSL experiment allowing code to be executed via tweets
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Here is a proof of concept for a python-based twitter DSL that is adapted for running code via tweets (so the code needs to be short and concise) and have "first-class" access to live twitter data directly in the language via @user and #tag constructs. 

You can give the twitter_dsl.py any code via stdin.

	print @shitmydadsays[0]

Would simply print out the latest tweet from @shitmydadsays.

	print next((t for t in #fail if "cat" in t))
Would print out the first #fail tweet also mentioning a cat.

A little more contrived example (I call it The Irony Machine)

	t=@hwaara[0]; w=t.split(" "); r=randint(0, len(w)-1); print " ".join(w[:r]+["\"%s\"" % w[r]]+w[min(r+1,len(@hwaara)):])
This gets my latest tweet, finds a random word and puts quotes around it, making it "ironic" in some random sense.


One could expand on this idea, making a bot that accepts code and tweets the output. You could even implement a "goto" or "exec" builtin in the language, allowing to execute code in other tweets by id. 

If the bot allowed to rememeber a code tweet by a name and allow for input arguments you could then reuse previous code in your new code, allowing code tweets to be used as functions, and eventually evolving into a sort of big repository of code to build upon.


* #topic needs to be implemented. Need to switch to another twitter API lib with search capabilities (python-twitter doesn't have it).

* If you're gonna do this online safely, you need a sandboxed environment. For example pypy's: http://codespeak.net/pypy/dist/pypy/doc/sandbox.html

* Build the bot!