Last active
December 22, 2015 06:08
-
-
Save sletix/6428595 to your computer and use it in GitHub Desktop.
setup console odesk-meter script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# setup odesk-meter script | |
# | |
# to install -> | |
# foo@laptop ~/work $ bash <(curl -s https://raw.github.com/gist/6428595/setup.sh) | |
# - type your odesk login and password | |
# ... | |
# | |
# to use -> | |
# foo@laptop ~/work $ how_many | |
# Last data from odesk: | |
# * Developer - Company | |
# - 13:00 hrs this week (@$1000.50/hr = $13006.25) | |
# | |
CASPER_PATH="$(which casperjs)" | |
COFFEE_SCRIPT_PATH="$HOME/.odesk-meter.coffee" | |
BASH_SCRIPT_PATH="/usr/local/bin/how_many" | |
if [ -f "$CASPER_PATH" ]; then | |
printf "install console odesk-meter script...\n" | |
printf "please enter your odesk login: " | |
read -e odesk_login | |
printf "and password: " | |
read -s -e odesk_password | |
# put script to home | |
# | |
printf "$(cat <<eof | |
# | |
# .odesk-meter.coffee | |
# | |
casper = require('casper').create() | |
casper.options.waitTimeout = 45000 | |
casper.userAgent 'Mozilla/5.0 (Windows NT 6.1) ' + \\ | |
'AppleWebKit/537.36 (KHTML, like Gecko) ' + \\ | |
'Chrome/28.0.1468.0 Safari/537.36' | |
casper.start "https://www.odesk.com/login" | |
casper.waitForSelector "#login", -> | |
@fill "#login", | |
username: "$odesk_login", | |
password: "$odesk_password" | |
@click "#submit" | |
casper.then -> | |
if @exists "#formErrors" | |
@echo "authentication failed" | |
@exit() | |
casper.thenOpen "https://www.odesk.com/d/home/" | |
casper.waitForSelector "#hourlyContracts", -> | |
projects = @evaluate -> | |
# get all info from homepage with special selectors | |
# | |
info = [] | |
\$("#hourlyContracts tr").each -> | |
info.push { | |
time: \$.trim(\$(".nowrap:last",@).text()), | |
money: \$(".oMute:last",@).text(), | |
title: \$.trim(\$(".oRowTitle.oTxtMed",@).text().replace(/\s+/g," ")) | |
} | |
info | |
if projects.length > 0 | |
@echo "Last data from odesk:" | |
for info in projects | |
casper.echo " * #{info.title}" | |
casper.echo " - #{info.time} (#{info.money})\\\n" | |
else | |
@echo "something went wrong with projects in homepage" | |
casper.run() | |
eof)" > $COFFEE_SCRIPT_PATH | |
printf "$(cat <<eof | |
#!/usr/bin/env bash | |
# | |
# short script for run odesk-meter info | |
# | |
$CASPER_PATH $COFFEE_SCRIPT_PATH | |
eof)" > $BASH_SCRIPT_PATH | |
chmod +x $BASH_SCRIPT_PATH | |
cat << EOF | |
# --------------------------------------------------------------- | |
# install completed! | |
# --------------------------------------------------------------- | |
# | |
## using: | |
# | |
# to show your current odesk-meter info | |
# \`how_many\` | |
# | |
# or run with casper | |
# \`casperjs $COFFEE_SCRIPT_PATH\` | |
# | |
## !!! warning: !!! | |
# | |
# '$COFFEE_SCRIPT_PATH' contains your odesk password!!! | |
# u can apply chmod for this file, and using only from root, or ... | |
# | |
# | |
## to remove scripts: | |
# | |
# \`rm $COFFEE_SCRIPT_PATH $BASH_SCRIPT_PATH\` | |
# | |
# --------------------------------------------------------------- | |
EOF | |
echo "running..." | |
bash $BASH_SCRIPT_PATH | |
else | |
echo "FAILED: 'capsperjs' package not installed in your system, please install it first, using brew or apt-get and run again this script!" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment