Difference between revisions of "Data export"
From Awesome Baozam
| Line 33: | Line 33: | ||
# '''g1w''' - по неделям | # '''g1w''' - по неделям | ||
# '''g1m''' - по месяцам | # '''g1m''' - по месяцам | ||
| + | |||
| + | == VBA script == | ||
| + | <pre> | ||
| + | HTTPDownload "https://baozam.net/index.php?action=csv&hosts=<DEVICE>&period=<PERIOD>&stime=<STIME>&step=<STEP>", "E:\baozam.csv", <USR>, <PWD> | ||
| + | Sub HTTPDownload( myURL, myFile, myUser, myPwd ) | ||
| + | |||
| + | ' This Sub downloads the FILE specified in myURL to the file specified in myFile. | ||
| + | |||
| + | ' Based on a script found on the Thai Visa forum | ||
| + | ' http://www.thaivisa.com/forum/index.php?showtopic=21832 | ||
| + | ' by Rob van der Woude | ||
| + | ' http://www.robvanderwoude.com | ||
| + | |||
| + | ' Standard housekeeping | ||
| + | Dim i, objFile, objFSO, objHTTP, strFile, strMsg | ||
| + | Const ForReading = 1, ForWriting = 2, ForAppending = 8 | ||
| + | |||
| + | ' Create a File System Object | ||
| + | Set objFSO = CreateObject( "Scripting.FileSystemObject" ) | ||
| + | |||
| + | ' Create or open the target file | ||
| + | Set objFile = objFSO.OpenTextFile( myFile, ForWriting, True ) | ||
| + | |||
| + | ' Create an HTTP object | ||
| + | Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" ) | ||
| + | |||
| + | ' Download the specified URL | ||
| + | objHTTP.Open "POST", myURL, False | ||
| + | objHTTP.Send( "name=" + myUser + "&password=" + myPwd ) | ||
| + | |||
| + | ' Write the downloaded byte stream to the target file | ||
| + | For i = 1 To LenB( objHTTP.ResponseBody ) | ||
| + | objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) ) | ||
| + | Next | ||
| + | |||
| + | ' Close the target file | ||
| + | objFile.Close( ) | ||
| + | End Sub | ||
| + | </pre> | ||
Revision as of 10:53, 12 August 2016
Для получения данных по запросу вы можете использовать УРЛ
https://baozam.net/index.php?action=csv&hosts=<HOSTID>&period=<PERIOD_IN_SECONDS>&stime=<START_UNIXTIME>&step=<STEP>
для аутентификации необходимо передать логин и пароль в (только) POST.
если хотите, можем завести специального пользователя для таких запросов.
пример
HOST=baozam.net
DEVICE=
PERIOD=$(( 7 * 24 * 3600 ))
STIME=0
STEP=g1h
USER=
PWD=
curl "https://$HOST/index.php?action=csv&hosts=$DEVICE&period=$PERIOD&stime=$STIME&step=$STEP" \
-H "Host: $HOST" --compressed \
-d "name=$USER" -d "password=$PWD"
детали
STIME - unixtime с которого начинается период. Если = 0, то начало периода будет отсчитано от текущего времени.
STEP - целое число секунд. или предопределенные значения
- g1h - почасово
- g1d - по дням
- g1w - по неделям
- g1m - по месяцам
VBA script
HTTPDownload "https://baozam.net/index.php?action=csv&hosts=<DEVICE>&period=<PERIOD>&stime=<STIME>&step=<STEP>", "E:\baozam.csv", <USR>, <PWD>
Sub HTTPDownload( myURL, myFile, myUser, myPwd )
' This Sub downloads the FILE specified in myURL to the file specified in myFile.
' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832
' by Rob van der Woude
' http://www.robvanderwoude.com
' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
' Create or open the target file
Set objFile = objFSO.OpenTextFile( myFile, ForWriting, True )
' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
' Download the specified URL
objHTTP.Open "POST", myURL, False
objHTTP.Send( "name=" + myUser + "&password=" + myPwd )
' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
' Close the target file
objFile.Close( )
End Sub