Sign in to follow this  
Followers 0
gruntydatsun

Scrape Chart PNG from Web Page

3 posts in this topic

Hi,

I've written a little program that scrapes my internet usage data from my ISPs painfully unfriendly stats webpage and puts it into a little GUI.

I'd like to express the ratio of upload to download in a pie chart at the bottom of the GUI and I found a great URL to generate the pie chart:

http://chart.apis.google.com/chart?cht=p...t=p3&chd=t:60,40&chs=250x100

What I need help with is how to get the picture off the webpage and into my GUI. Although embarrassing, someone pointing to a function going "yeah just use WebPicToGUI() dumbass" would be really great.

Here's the code I have so far:

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.7.19 (beta)
Author:      Grunty Datsun
Script Function:
Internet usage GUI of extreme radness....
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <IE.au3>
#include <String.au3>
#include <Array.au3>
global $encrypted_password, $password, $oIE
$encrypted_password = _Manage_Password()           ;retrieve ecrypted pw or set a new one
$password = _StringEncrypt(0,$encrypted_password,_Get_UUID(),8)   ;decrypt password
_Load_Page("UserNameHere")             ;load up stats webpage silently
$html = _IEBodyReadHTML($oIE)             ;read page html into local variable
_IEQuit($oIE)                 ;close stats wepage

$perc_used_data = StringRegExp($html,'Data Used (\d*)%',1)  
$mb_used_data = StringRegExp($html,'% \((\d*) MB',1)    
$perc_mth_elapsed = StringRegExp($html,'Days Elapsed (\d*)%',1)  
$days_elapsed = StringRegExp($html,'\((\d*) days\)',1)  
$Used_Data_Perc = $perc_used_data[0]
$Used_Data_GB = Round($mb_used_data[0]/1000,1)
$Mth_Over_Perc = $perc_mth_elapsed[0]
$Mth_Over_Days = $days_elapsed[0]
$data_use_degree = $Used_Data_GB & " GB out of 500 GB"
$day_use_degree = "Day " & $Mth_Over_Days & " of " & _Days_In_Month()
$days_left_in_month = (_Days_In_Month() - $Mth_Over_Days)
$data_per_day_remainder = Round((500 - $Used_Data_GB)/$days_left_in_month,1)
$up_down_total = StringRegExp($string,'planDataU''>(\d*)',3)     ;array with uploaded, downloaded and total used


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Cable Internet Usage v0.6", 579, 283, 192, 124)
$grp_DataProg = GUICtrlCreateGroup("DATA CONSUMED - " & $data_use_degree, 8, 8, 441, 81)
GUICtrlSetFont($grp_DataProg, 12, 800, 0, "Verdana")
GUICtrlSetColor($grp_DataProg, 0xFF0000)
$prog_Data = GUICtrlCreateProgress(24, 32, 409, 41, BitOR($PBS_SMOOTH,$WS_BORDER))
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$grp_DataAvail = GUICtrlCreateGroup("DATA AVAILABILITY", 8, 200, 561, 65)
GUICtrlSetFont($grp_DataAvail, 12, 800, 0, "Verdana")
GUICtrlSetColor($grp_DataAvail, 0x000080)
$lbl_DataAvail = GUICtrlCreateLabel($data_per_day_remainder & " GB per day for the next " & $days_left_in_month & " days", 24, 232, 400, 22)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$grp_DataPercent = GUICtrlCreateGroup("PERCENT", 464, 8, 105, 81)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetColor(-1, 0xFF0000)
$lbl_DataPercent = GUICtrlCreateLabel($Used_Data_Perc & "%", 480, 32, 76, 36)
GUICtrlSetFont(-1, 20, 800, 0, "Verdana")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$grp_DaysPercent = GUICtrlCreateGroup("PERCENT", 464, 104, 105, 81)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetColor(-1, 0x008000)
$lbl_DaysPercent = GUICtrlCreateLabel($Mth_Over_Perc & "%", 480,amy rr 128, 76, 36)
GUICtrlSetFont(-1, 20, 800, 0, "Verdana")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$grp_DaysProg = GUICtrlCreateGroup("DAYS ELAPSED - " & $day_use_degree, 8, 104, 441, 81)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetColor(-1, 0x008000)
$prog_Days = GUICtrlCreateProgress(25, 127, 409, 41, BitOR($PBS_SMOOTH,$WS_BORDER))
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($prog_Data,$Used_Data_Perc)
GUICtrlSetData($prog_Days,$Mth_Over_Perc)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

Func _Days_In_Month()
Switch @MON
  Case 4,6,9,11
   return 30
  Case 2
   return 28  ;I know about leap years, just havent got around to it yet (%4)
  Case Else
   return 31
EndSwitch
EndFunc

Func _Load_Page($username)
$oIE = _IECreate ("https://memberservices.optuszoo.com.au/ms/usagemeter/currentmonthbroadbandusagemeter.htm",0,0) ;create IE instance and load Webmail
$o_form = _IEFormGetObjByName ($oIE, "login_form")          ;get handle to logon form
$o_userid = _IEFormElementGetObjByName ($o_form, "username")         ;get handle to user id field
$o_pwd = _IEFormElementGetObjByName($o_form,"j_password")         ;get handle to password field
$oSubmit = _IEGetObjByName ($oIE, "submit")           ;get handle to submit button
_IEFormElementSetValue ($o_userid, $username)            ;set user id to my email address
_IEFormElementSetValue($o_pwd,$password)
_IEAction ($oSubmit, "click")
_IELoadWait ($oIE)
Sleep(200)
EndFunc

Func _Manage_Password()
Local $reset, $encrypted_password, $handle, $pwfile
$pwfile = @ScriptDir & "\pw.enc"
$reset = msgbox(260,"PASSWORD RESET","Would you like to reset your password?",2)    ;does user want to rest password
if $reset = 6 OR FileExists($pwfile) = 0 Then            ;if resetting pword or pword file doesn't exist
  $encrypted_password = _StringEncrypt(1,InputBox("Title","Prompt","","*"),_Get_UUID(),8)  ;get pword and encrypt into a string, UUID as key
  $handle = FileOpen($pwfile,2)             ;open file in overwrite write mode
  FileWrite($handle,$encrypted_password)              ;write encrypted string into file
  FileClose($handle)                   ;close password file
Else
  $encrypted_password = FileRead($pwfile)             ;read in encrypted password from file
  FileClose($pwfile)                   ;close password file
EndIf
return $encrypted_password                ;return the encrypted password
EndFunc

Func _Get_UUID()
If @OSArch='x86' Then
  $reg='HKEY_LOCAL_MACHINE'
Else
  $reg='HKEY_LOCAL_MACHINE64'
EndIf
return RegRead($reg & '\SOFTWARE\Microsoft\Cryptography', 'MachineGuid')
EndFunc

Share this post


Link to post
Share on other sites



Nevermind, just answered my own premature question. :)

#include <IE.au3>
$oIE = _IECreate("http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Down|Up",0,0)
$oImgs = _IEImgGetCollection($oIE)
For $oImg In $oImgs
$oImgUrl = $oIMG.src
    InetGet($oImgUrl, "c:graphschart.png")
Next
_IEQuit($oIE)

Share this post


Link to post
Share on other sites

Hi

You might be interested to know that autoit can create a pie or bar chart on its own. Use the search to find the scripts. I would provide a link but on iphone sorry


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0