Skip to content

Instantly share code, notes, and snippets.

@mhluska
Created September 9, 2016 19:20
Show Gist options
  • Save mhluska/1e66710a654357eea71a4154755fe733 to your computer and use it in GitHub Desktop.
Save mhluska/1e66710a654357eea71a4154755fe733 to your computer and use it in GitHub Desktop.
#!/bin/sh
# See https://github.com/xiaohan2012/twitter-sent-dnn
if [ "${#}" -eq 0 ]; then
echo "Usage: ${0} message"
exit 1
fi
html=$(curl 'https://twitter-sentiment-cnn.herokuapp.com/' \
-H 'Pragma: no-cache' \
-H 'Origin: https://twitter-sentiment-cnn.herokuapp.com' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \
-H 'Cache-Control: no-cache' \
-H 'Referer: https://twitter-sentiment-cnn.herokuapp.com/' \
-H 'Connection: keep-alive' \
--data "tweet=${*}&tweet_submit_button=Submit" \
--silent \
--compressed)
# Floating point regex, see http://stackoverflow.com/a/658662/659910
echo "${html}" | grep -m 1 'The sentiment index is' | grep -Eo '[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment