Work the Shell - Still Parsing the Twitter Stream
The answer isn't that hard. The stream is newest to oldest, and the message ID values are assigned sequentially by the server, so all we need to do is cache the most recent message ID we've seen after we have answered all queries. Then, on subsequent invocations, compare each query ID to the most recent we've answered. If they're greater, we need to answer them. If not, we've already done so. Like this:
if [ "$id" == "$previouslatestid" -o $answered -eq 1 ] ; then echo "already answered query \"$msg\" from $name: skipped" answered=1 else ...
The previouslatestid is what's cached. We'll also capture the most recent ID of the current wave of queries like this:
if [ -z "$latestid" ] ; then latestid=$id # store most recent ID fi
Of course, there are a few more steps. We need to grab the cached value at the beginning of the script:
if [ -f "$lastidcache" ] ; then previouslatestid="$(cat "$lastidcache")" else previouslatestid="0" fi
And, we need to save it at the end:
echo $latestid > "$lastidcache"
That's it. I've run out of space, but the full script is available at ftp.linuxjournal.com/pub/lj/listings/issue191/10695.tgz. Next month, we'll polish it a bit and see what fun we can have with a tweetbot!
Dave Taylor has been hacking shell scripts for a really long time. He's the author of the popular Wicked Cool Shell Scripts and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- ServersCheck's Thermal Imaging Camera Sensor
- The Italian Army Switches to LibreOffice
- Linux Mint 18
- Chris Birchall's Re-Engineering Legacy Software (Manning Publications)
- Petros Koutoupis' RapidDisk
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Privacy and the New Math
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide