So, I am still poking away at various ways to interface between the bash and various web components. This stuff is still shaking out of my Twitter to CLI to LCD project. I have been using some of the usual suspects (wget, python url libraries, etc) in an effort to find one that is best suited to sniffing and parsing html info. I have found that writing to serial is the most fail-proof means of mashing around data quickly, so that is my inspiration.
Anyhow, I was horsing around with curl on the command line. It turns out, that spoofing user agents is pretty simple to implement.
Take this two-line one liner for instance:
swantron@Dell15:~$ for (( y=1; y<=x; y++)) ; do curl --user-agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" swantron.com ; done
In a nutshell, this is acting to snag this site ten times, with credentials indicating the machine is running Windows 2000 and MS Internet Explorer 5.1. The success is indicated by my server statistics:
Not too bad. I am considering using this as a testing tool for my site. Messing around with PHP and CSS…I can put together a quick regression using some legacy operating systems and browsers to make certain that I can still snag my content. Granted, the example setup may seem like gross overkill, but as those stats indicate, I do see quite a few requests from ancient machines. Makes you wonder..
Anyhow, this layout is in need of some serious testing. If anyone is interested in a copy, drop me a line. Cheers.
I sort of forget what my original project entailed…something about tweeting via the command line, for Arduino purposes. You can pretty much just toss a bunch of words in a hat, and add ‘Arduino’ and ‘Command Line’ to them, and there you have one of my typical projects.
Anyhow, here we find ourselves. I am missing some dependencies with OAuth, but have managed to get twitter working from an interactive python shell:
This section is as much for my reference as it is for public knowledge…I snagged the commands that I ran to snag my comments. It first prints swantr0n (my dev account) and then my primary Twitter feed, @swantron
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import twitter
>>> api = twitter.Api()
>>> feedSwantron = api.GetUserTimeline(‘swantron’)
>>> feedSwantr0n = api.GetUserTimeline(‘swantr0n’)
>>> print [ x.text for x in feedSwantr0n]
[‘development account for @swantron | tune into http://t.co/SpDFBkK for projects’, ‘hello world’]
>>> print [ x.text for x in feedSwantron]
[‘@vftb …you better believe it’, ‘Twitter Project Teaser : http://t.co/7ZrOLUn | one step closer to tweeting from the #CLI … might take a run at make it tweet’, ‘Might need to implement some sleeves into my wardrobe… @adafruit just flipped the script with open source cuff links’, ‘unsafe at any speed… updating #ubuntu on the road http://t.co/Q8gfc56’, ‘Upgrading Mini 9 to #Ubuntu Natty http://t.co/7yT9w81 | posting to kill time… review here ( http://t.co/RM675lX ) lunch-aft on the morrow’, ‘https://swantron.com/basic-mower-cord-repair/ #DIY lawn mower repair from a #math major. spoiler: it works’, “#arduino no you didn’t https://swantron.com/html-to-python-to-arduino-to-lcd/ #LCD project, stepped up a bit”, ‘working on a python script to dump info from web to LCD https://swantron.com/python-teaser/ #arduino’, ‘http://youtu.be/MpomhE6dgww video of #boc unboxing (for the win)’, ‘#woot bag-o-crap unboxing @ https://swantron.com/woot-boc-unboxing/ not too shabby’, ‘https://swantron.com/compiz-error-in-ubuntu-natty/ still finding some compiz issues in #ubuntu 11.04’, ‘#Arduino project @ https://swantron.com/command-line-lcd-arduino-interface/ | driving LCD screen via command line’, ‘@RobotGrrl… what version are you running? I had no problems with IOIO / Droid 2 (froyo 2.2)’, ‘Easy LCD #Arduino Display | https://swantron.com/easy-lcd-arduino-display/ | feels good to have a warm soldering iron and functional hardware’]
I will keep plugging away until I get this thing hammered out. If not, I can print this suff to my LCD for a real-time Twitter display. Could be cool either way.
A while back, I tossed a little concept video out to the nets regarding CLI interface with my site’s comments and an LCD screen. I figured that I could do a similar thing with my Twitter account…spurred largely by Adafruit’s Make it Tweet challenge. Well, it turns out that Twitter has a few hurdles to jump, in regards to posting tweets to an account.
My failed usage from the command line was utilising curl
> curl -u swantron:pass -d status=”command line test” http://twitter.com/statuses/update.xml
I was getting an error message, that basic authentication was not supported. For the loss.
It turns out that you need a few keys in order to authenticate, which requires registering an app with Twitter… like this
There we go…keys in hand. Now, I need to figure out how to sew this together using curl or wget. If all else fails, I am pretty sure there is a py library that I can snag. Stay tuned…this one could be fun.
Last week found me standing tall upon my shell script soapbox, shouting command line praises to all who would listen.
Thou ought direct thine output aftways, to-wards thine USB port of thee. And that is well and righteous.
Well, that still is the case. My latest project has made it glaringly obvious that sometimes a little Python script will render a whole bunch of shell scripting moot. Namely, parsing HTML. Let’s see a picture…
Lunch hour project: parse the comments from swantron.com; feed said comments to an LCD screen.
I was horsing around with wget from a CLI a few days ago. I found myself trying to smash through the resultant file via pure regular expressions…which is incredibly clumsy. Well, as luck would have it, my go-to after my main go-to is Python, and this type of thing has been issue enough to warrant a library. BeautifulSoup. It acts to parse the HTML info into items, that can be smashed around as I see(med) fit.
My setup was simple: py script to snag my comments and write serial, Arduino sketch to drive a LCD and read/write serial. And a source of shade. And a WiFi signal to snag.
Liquid crystal displays are pretty awesome. Command line interfaces are very awesome. Hmm…
I started daydreaming at work about how to go about making hardware interface with an RSS feed. I have seen some projects that use Arduinos with ethernet shields to check Twitter, for example, but they seem unnecessarily bulky. Or clumsy. I spend a lot of time working on the command line, and love to put together dirty little scripts to solve problems. It sort of goes along the lines of ‘when you have a hammer, everything looks like a nail’…I figured that the same thing could be implemented with a little shell scripting and my trusty Arduino, sans anything complicated.
So far, so good.
I put together a sketch (after the bump) to drive my LCD, writing serial output to the screen. After verifying that the sketch worked via the Arduino IDE’s serial monitor, I popped open a CLI and got to work. FWIW, I am using Ubuntu 11.04 still…ctrl-alt-t pops open a terminal window…unity has me all over shortcuts these days. Anyhow, I was able to verify that I could echo text and direct it to the USB port that the Arduino was mounted to. No sweat.
As a proof of concept, I decided to display the number of times that I had the word “awesome” on swantron.com. Once the LCD was shown to work, the sky is the limit…see some regex, pipes, wget, and so forth in action: