Command:
$ curl -vs "http://smashingtheory.blogspot.jp" 2>&1 | grep -o -m 2 "<span class='post-count' dir='ltr'>([0-9]*)" | tail -1 | sed -e 's/[^[[:digit:]]]*//g'
Result:
33
Showing posts with label tail (Unix). Show all posts
Showing posts with label tail (Unix). Show all posts
Wednesday, June 8, 2016
Thursday, February 4, 2016
Get a Random Line from CSV file
First line in a CSV file contains column names, so I ignore the line and get a line after it:
$ head -$[$[${RANDOM} % $[`wc -l < ./lines.csv` - 1]] + 2] ./lines.csv | tail -1
Friday, January 29, 2016
Cron: Tweet a Line Every 10-19 Minutes
Cron - Tweet a line every 30-40 mins:
lines.rb - using standard input:
*/10 * * * * perl -le 'sleep rand 540' && head -$[${RANDOM} \% `wc -l < /Users/username/lines.txt` + 1] /Users/username/lines.txt | tail -1 | ruby /Users/username/lines.rb
lines.rb - using standard input:
require 'json'
require 'oauth'
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
consumer = OAuth::Consumer.new(
consumer_key,
consumer_secret,
site:'https://api.twitter.com/'
)
endpoint = OAuth::AccessToken.new(consumer, access_token, access_token_secret)
# STATUS
status = STDIN.gets
# POST
response = endpoint.post('https://api.twitter.com/1.1/statuses/update.json', status: status )
result = JSON.parse(response.body)
Subscribe to:
Posts (Atom)