Permalink
Browse files

Repeat requests if unsuccessfully

Sometimes in HTML returns 0, while the actual balance has not equal
zero.
  • Loading branch information...
1 parent 272af7e commit 71e7081728e5407072774cc965f8fcf28c738185 @Otetz committed Nov 14, 2011
Showing with 21 additions and 4 deletions.
  1. +21 −4 services/moscow.megafon.ru/monitor
@@ -7,9 +7,26 @@ OLDPATH=$PATH; PATH=".:..:$(dirname $0):$PATH"; . _spmon_lib; PATH=$OLDPATH
UA='Mozilla/5.0 (Linux; U; Android 2.2; en-us; Desire_A8181 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
-request -O $TM/1.html --no-check-certificate https://moscowsg.megafon.ru/
-request -O $TM/2.html --no-check-certificate --post-data="MOBILE_MODE=AUTH&LOGIN=$LOGIN&PASSWORD=$PASSWORD" https://moscowsg.megafon.ru/ps/scc/mobile/
+STRVAL=""
+ZERO_VALUE=$(echo "scale=2; 0.0" | bc)
+ATTEMPT=0
-# <span id="statusbalance"><span class="balance_good">&#1058;&#1077;&#1082;&#1091;&#1097;&#1080;&#1081; &#1073;&#1072;&#1083;&#1072;&#1085;&#1089;: 123.45 &#1088;&#1091;&#1073;.</span></span>
+megafon()
+{
+ request -O $TM/1.html --no-check-certificate https://moscowsg.megafon.ru/
+ request -O $TM/2.html --no-check-certificate --post-data="MOBILE_MODE=AUTH&LOGIN=$LOGIN&PASSWORD=$PASSWORD" https://moscowsg.megafon.ru/ps/scc/mobile/
-sed -ne '/<span id="statusbalance">/ { s,^<span id="statusbalance">.*: \([0-9.-]*\) .*$,\1,; p; }' <$TM/2.html
+ # <span id="statusbalance"><span class="balance_good">&#1058;&#1077;&#1082;&#1091;&#1097;&#1080;&#1081; &#1073;&#1072;&#1083;&#1072;&#1085;&#1089;: 123.45 &#1088;&#1091;&#1073;.</span></span>
+
+ STRVAL=`echo "scale=2; $(sed -ne '/<span id="statusbalance">/ { s,^<span id="statusbalance">.*: \([0-9.-]*\) .*$,\1,; p; }' <$TM/2.html)" | bc`
+ let ATTEMPT++
+
+ # Manual test insertion for processing of returning wrong balance (sometimes returns 0, while the actual balance has not equal zero)
+ if [ $ATTEMPT -eq 1 ]; then STRVAL=$ZERO_VALUE; fi
+
+ # Repeat if unsuccessfully, maximum 5 times
+ if [ $ATTEMPT -lt 5 ] && [ "$STRVAL" == "$ZERO_VALUE" ]; then megafon; fi
+}
+
+megafon
+echo $STRVAL

0 comments on commit 71e7081

Please sign in to comment.