AutoIt-Quelltext
#include <WinHTTP.au3>
#include <Array.au3>
Local $iLastTweet, $sIniPath, $hSess, $hConnect, $sTweets, $iSiS, $aRet, $iUbound
$sIniPath = @ScriptDir & "\TwitterConfig.ini"
If Not FileExists($sIniPath) Then FileWrite($sIniPath, "[Data]" & @CRLF & "Account=AutoItTweetBot" & @CRLF & "LastTweet=-1")
$iLastTweet = IniRead($sIniPath, "Data", "LastTweet", -1)
$sAccount = IniRead($sIniPath, "Data", "Account", "AutoItTweetBot")
$hSess = _WinHttpOpen("AutoIt Twitter Tool")
$hConnect = _WinHttpConnect($hSess, "twitter.com")
$sTweets = _WinHTTPRequest($hConnect, "/" & $sAccount)
$iSiS = StringInStr($sTweets, "<ol id='timeline'")
$sTweets = StringMid($sTweets, $iSiS)
If Not $iSiS Then Exit MsgBox(0, "", "Keine Tweets gefunden")
$aRet = _RegExp($sTweets, 'id="status_(\d+)"(?>(?>.*\s+)+?<span class="entry-content">)(?s)(.+?)</span>')
$iUbound = @extended
For $i = $iUbound - 1 To 0 Step -1
ConsoleWrite($aRet[$i][0] & @TAB & $iLastTweet & @CRLF)
If $aRet[$i][0] < $iLastTweet Then ExitLoop
$iLastTweet = $aRet[$i][0]
IniWrite($sIniPath, "Data", "LastTweet", $iLastTweet)
$aRet[$i][1] = StringRegExpReplace($aRet[$i][1], "<[^>]+>", "")
Local $iSiS = StringInStr($aRet[$i][1], ":"), $aCommand[2] = [StringLeft($aRet[$i][1], $iSiS - 1), StringMid($aRet[$i][1], $iSiS + 1)]
If Not $iSiS Then
MsgBox(0, "", "Folgender Befehl konnte nicht verarbeitet werden!" & @CRLF & @CRLF & $aRet[$i][1])
ContinueLoop
EndIf
Switch $aCommand[0]
Case "au3"
MsgBox(0, "", "Führe AutoIt Code aus: " & @CRLF & @CRLF & $aCommand[1])
$sCode = BinaryToString(InetRead($aCommand[1], 1))
ConsoleWrite($sCode & @CRLF)
If StringInStr($sCode, "Make New Paste!") Then ContinueLoop ; Pastebin Script abgelaufen
If StringLeft($sCode, 9) = "<!DOCTYPE" Then ; Pastebin Script
$sCode = StringRegExpReplace($sCode, "[\w\W]+<pre>([\w\W]+)</pre>[\w\W]+", "\1")
Local $aReplace[2][2] = [[""", """"],["&", "&"]]
For $j = 0 To UBound($aReplace) - 1
$sCode = StringReplace($sCode, $aReplace[$j][0], $aReplace[$j][1])
Next
MsgBox(0, "Pastebin Code", $sCode)
EndIf
RunScript($sCode)
Case "Execute"
MsgBox(0, "", "Execute File: " & @CRLF & @CRLF & $aCommand[1])
ShellExecute($aCommand[1])
Case "dos"
MsgBox(0, "", "Führe Dos Befehl aus: " & @CRLF & @CRLF & $aCommand[1])
RunWait(@ComSpec & " /C " & $aCommand[1], "", @SW_HIDE)
Case Else
MsgBox(0, "", "Unbekannter Parameter: " & $aCommand[0])
MsgBox(0, "", "Folgender Befehl konnte nicht verarbeitet werden!" & @CRLF & @CRLF & $aRet[$i][1])
EndSwitch
Next
MsgBox(0, "", "Keine neuen Befehle (mehr)")
Func _WinHTTPRequest($hConnect, $sSite, $sPost = "", $sReferer = "", $fQueryHeaders = False)
;Author: SEuBo
Local $hRequest, $sHTML, $sMode = "GET", $sHeaders = $WINHTTP_NO_ADDITIONAL_HEADERS, $sOptional = $WINHTTP_NO_REQUEST_DATA
If $sReferer = "" Then $sReferer = $WINHTTP_NO_REFERER
If $sPost <> "" Then
$sMode = "POST"
$sOptional = $sPost
$sHeaders = "Content-Type: application/x-www-form-urlencoded" & @CRLF
EndIf
ConsoleWrite("WinHTTP Request <<< " & $sMode & " >>> ===========> " & $sSite & @TAB & @TAB & $sPost & @CRLF)
$hRequest = _WinHttpOpenRequest($hConnect, $sMode, $sSite, "HTTP/1.1", $sReferer) ; Anfrage an die Seite stellen
_WinHttpSendRequest($hRequest, $sHeaders, $sOptional) ; Anfrage senden.
_WinHttpReceiveResponse($hRequest) ; Warte auf Antwort des Servers
If $fQueryHeaders Then $sHTML &= _WinHttpQueryHeaders($hRequest)
Do
$sHTML &= _WinHttpReadData($hRequest) ; Antwort aus dem Buffer lesen.
Until @error ; bis ein fehler auftritt (übertragung abgeschlossen)
_WinHttpCloseHandle($hRequest)
Return $sHTML
EndFunc ;==>_WinHTTPRequest
Func _RegExp($sTest, $sPattern, $iOffset = 0)
Local $aRet, $iUB, $iUB2, $aDummy, $aNewArr
$aRet = StringRegExp($sTest, $sPattern, 4, $iOffset)
If @error Then Return
Local $iUB = UBound($aRet), $iUB2 = UBound($aRet[0]), $aNewArr[$iUB][$iUB2 - 1]
For $i = 0 To $iUB - 1
Local $aDummy = $aRet[$i], $iUBD = UBound($aDummy)
If $iUBD - 1 > $iUB2 Then
$iUB2 = $iUBD
ReDim $aNewArr[$iUB][$iUB2]
EndIf
For $j = 1 To $iUBD - 1
$aNewArr[$i][$j - 1] = $aDummy[$j]
Next
Next
Return SetError(0, $iUB, $aNewArr)
EndFunc ;==>_RegExp
; #FUNCTION# ======================================================================================
; Name ..........: RunScript()
; Description ...: Führt AutoIt Code aus.
; Syntax ........: RunScript($sAu3Code)
; Parameters ....: $sAu3Code - Code, der ausgeführt werden soll.
; Author ........: SEuBo
; Remarks .......: Der Code wird in eine temporäre Datei gespeichert, und diese im Anschluss gelöscht.
; =================================================================================================
Func RunScript($sAu3Code) ; Author: SEuBo
Local $sPath = @TempDir & "\~tempscript", $iCnt
While FileExists($sPath & $iCnt & ".au3") * Sleep(10)
$iCnt += 1
WEnd
Local $sPath = $sPath & $iCnt & ".au3"
FileWrite($sPath, $sAu3Code)
RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sPath & '"')
Sleep(100)
While FileExists($sPath) * Sleep(10)
FileDelete($sPath)
WEnd
EndFunc ;==>RunScript
Func _FixHTML(ByRef $sCode)
Local $aEntities[96][2] = [[""", 34],["&", 38],["<", 60],[">", 62],[" ", 3],[" ", 32] _
,["¡", 161],["¢", 162],["£", 163],["¤", 164],["¥", 165],["¦", 166] _
,["§", 167],["¨", 168],["©", 169],["ª", 170],["¬", 172],["­", 173] _
,["®", 174],["¯", 175],["°", 176],["±", 177],["²", 178],["³", 179] _
,["´", 180],["µ", 181],["¶", 182],["·", 183],["¸", 184],["¹", 185] _
,["º", 186],["»", 187],["¼", 188],["½", 189],["¾", 190],["¿", 191] _
,["À", 192],["Á", 193],["Ã", 195],["Ä", 196],["Å", 197],["Æ", 198] _
,["Ç", 199],["È", 200],["É", 201],["Ê", 202],["Ì", 204],["Í", 205] _
,["Î", 206],["Ï", 207],["Ð", 208],["Ñ", 209],["Ò", 210],["Ó", 211] _
,["Ô", 212],["Õ", 213],["Ö", 214],["×", 215],["Ø", 216],["Ù", 217] _
,["Ú", 218],["Û", 219],["Ü", 220],["Ý", 221],["Þ", 222],["ß", 223] _
,["à", 224],["á", 225],["â", 226],["ã", 227],["ä", 228],["å", 229] _
,["æ", 230],["ç", 231],["è", 232],["é", 233],["ê", 234],["ë", 235] _
,["ì", 236],["í", 237],["î", 238],["ï", 239],["ð", 240],["ñ", 241] _
,["ò", 242],["ó", 243],["ô", 244],["õ", 245],["ö", 246],["÷", 247] _
,["ø", 248],["ù", 249],["ú", 250],["û", 251],["ü", 252],["þ", 254]]
EndFunc ;==>_FixHTML
#include <WinHTTP.au3>
#include <Array.au3>
Local $iLastTweet , $sIniPath , $hSess , $hConnect , $sTweets , $iSiS , $aRet , $iUbound
$sIniPath = @ScriptDir & "\TwitterConfig.ini"
If Not FileExists ( $sIniPath ) Then FileWrite ( $sIniPath , "[Data]" & @CRLF & "Account=AutoItTweetBot" & @CRLF & "LastTweet=-1" )
$iLastTweet = IniRead ( $sIniPath , "Data" , "LastTweet" , - 1 )
$sAccount = IniRead ( $sIniPath , "Data" , "Account" , "AutoItTweetBot" )
$hSess = _WinHttpOpen( "AutoIt Twitter Tool" )
$hConnect = _WinHttpConnect( $hSess , "twitter.com" )
$sTweets = _WinHTTPRequest( $hConnect , "/" & $sAccount )
$iSiS = StringInStr ( $sTweets , "<ol id='timeline'" )
$sTweets = StringMid ( $sTweets , $iSiS )
If Not $iSiS Then Exit MsgBox ( 0 , "" , "Keine Tweets gefunden" )
$aRet = _RegExp( $sTweets , 'id="status_(\d+)"(?>(?>.*\s+)+?<span class="entry-content">)(?s)(.+?)</span>' )
$iUbound = @extended
For $i = $iUbound - 1 To 0 Step - 1
ConsoleWrite ( $aRet [ $i ] [ 0 ] & @TAB & $iLastTweet & @CRLF )
If $aRet [ $i ] [ 0 ] < $iLastTweet Then ExitLoop
$iLastTweet = $aRet [ $i ] [ 0 ]
IniWrite ( $sIniPath , "Data" , "LastTweet" , $iLastTweet )
$aRet [ $i ] [ 1 ] = StringRegExpReplace ( $aRet [ $i ] [ 1 ] , "<[^>]+>" , "" )
Local $iSiS = StringInStr ( $aRet [ $i ] [ 1 ] , ":" ) , $aCommand [ 2 ] = [ StringLeft ( $aRet [ $i ] [ 1 ] , $iSiS - 1 ) , StringMid ( $aRet [ $i ] [ 1 ] , $iSiS + 1 ) ]
If Not $iSiS Then
MsgBox ( 0 , "" , "Folgender Befehl konnte nicht verarbeitet werden!" & @CRLF & @CRLF & $aRet [ $i ] [ 1 ] )
ContinueLoop
EndIf
Switch $aCommand [ 0 ]
Case "au3"
MsgBox ( 0 , "" , "Führe AutoIt Code aus: " & @CRLF & @CRLF & $aCommand [ 1 ] )
$sCode = BinaryToString ( InetRead ( $aCommand [ 1 ] , 1 ) )
ConsoleWrite ( $sCode & @CRLF )
If StringInStr ( $sCode , "Make New Paste!" ) Then ContinueLoop ; Pastebin Script abgelaufen
If StringLeft ( $sCode , 9 ) = "<!DOCTYPE" Then ; Pastebin Script
$sCode = StringRegExpReplace ( $sCode , "[\w\W]+<pre>([\w\W]+)</pre>[\w\W]+" , "\1" )
Local $aReplace [ 2 ] [ 2 ] = [ [ """ , "" "" ] , [ "&" , "&" ] ]
For $j = 0 To UBound ( $aReplace ) - 1
$sCode = StringReplace ( $sCode , $aReplace [ $j ] [ 0 ] , $aReplace [ $j ] [ 1 ] )
Next
MsgBox ( 0 , "Pastebin Code" , $sCode )
EndIf
RunScript( $sCode )
Case "Execute"
MsgBox ( 0 , "" , "Execute File: " & @CRLF & @CRLF & $aCommand [ 1 ] )
ShellExecute ( $aCommand [ 1 ] )
Case "dos"
MsgBox ( 0 , "" , "Führe Dos Befehl aus: " & @CRLF & @CRLF & $aCommand [ 1 ] )
RunWait ( @ComSpec & " /C " & $aCommand [ 1 ] , "" , @SW_HIDE )
Case Else
MsgBox ( 0 , "" , "Unbekannter Parameter: " & $aCommand [ 0 ] )
MsgBox ( 0 , "" , "Folgender Befehl konnte nicht verarbeitet werden!" & @CRLF & @CRLF & $aRet [ $i ] [ 1 ] )
EndSwitch
Next
MsgBox ( 0 , "" , "Keine neuen Befehle (mehr)" )
Func _WinHTTPRequest( $hConnect , $sSite , $sPost = "" , $sReferer = "" , $fQueryHeaders = False )
;Author: SEuBo
Local $hRequest , $sHTML , $sMode = "GET" , $sHeaders = $WINHTTP_NO_ADDITIONAL_HEADERS , $sOptional = $WINHTTP_NO_REQUEST_DATA
If $sReferer = "" Then $sReferer = $WINHTTP_NO_REFERER
If $sPost <> "" Then
$sMode = "POST"
$sOptional = $sPost
$sHeaders = "Content-Type: application/x-www-form-urlencoded" & @CRLF
EndIf
ConsoleWrite ( "WinHTTP Request <<< " & $sMode & " >>> ===========> " & $sSite & @TAB & @TAB & $sPost & @CRLF )
$hRequest = _WinHttpOpenRequest( $hConnect , $sMode , $sSite , "HTTP/1.1" , $sReferer ) ; Anfrage an die Seite stellen
_WinHttpSendRequest( $hRequest , $sHeaders , $sOptional ) ; Anfrage senden.
_WinHttpReceiveResponse( $hRequest ) ; Warte auf Antwort des Servers
If $fQueryHeaders Then $sHTML &= _WinHttpQueryHeaders( $hRequest )
Do
$sHTML &= _WinHttpReadData( $hRequest ) ; Antwort aus dem Buffer lesen.
Until @error ; bis ein fehler auftritt (übertragung abgeschlossen)
_WinHttpCloseHandle( $hRequest )
Return $sHTML
EndFunc ;==>_WinHTTPRequest
Func _RegExp( $sTest , $sPattern , $iOffset = 0 )
Local $aRet , $iUB , $iUB2 , $aDummy , $aNewArr
$aRet = StringRegExp ( $sTest , $sPattern , 4 , $iOffset )
If @error Then Return
Local $iUB = UBound ( $aRet ) , $iUB2 = UBound ( $aRet [ 0 ] ) , $aNewArr [ $iUB ] [ $iUB2 - 1 ]
For $i = 0 To $iUB - 1
Local $aDummy = $aRet [ $i ] , $iUBD = UBound ( $aDummy )
If $iUBD - 1 > $iUB2 Then
$iUB2 = $iUBD
ReDim $aNewArr [ $iUB ] [ $iUB2 ]
EndIf
For $j = 1 To $iUBD - 1
$aNewArr [ $i ] [ $j - 1 ] = $aDummy [ $j ]
Next
Next
Return SetError ( 0 , $iUB , $aNewArr )
EndFunc ;==>_RegExp
; #FUNCTION# ======================================================================================
; Name ..........: RunScript()
; Description ...: Führt AutoIt Code aus.
; Syntax ........: RunScript($sAu3Code)
; Parameters ....: $sAu3Code - Code, der ausgeführt werden soll.
; Author ........: SEuBo
; Remarks .......: Der Code wird in eine temporäre Datei gespeichert, und diese im Anschluss gelöscht.
; =================================================================================================
Func RunScript( $sAu3Code ) ; Author: SEuBo
Local $sPath = @TempDir & "\~tempscript" , $iCnt
While FileExists ( $sPath & $iCnt & ".au3" ) * Sleep ( 10 )
$iCnt += 1
WEnd
Local $sPath = $sPath & $iCnt & ".au3"
FileWrite ( $sPath , $sAu3Code )
RunWait ( '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sPath & '"' )
Sleep ( 100 )
While FileExists ( $sPath ) * Sleep ( 10 )
FileDelete ( $sPath )
WEnd
EndFunc ;==>RunScript
Func _FixHTML( ByRef $sCode )
Local $aEntities [ 96 ] [ 2 ] = [ [ """ , 34 ] , [ "&" , 38 ] , [ "<" , 60 ] , [ ">" , 62 ] , [ " " , 3 ] , [ " " , 32 ] _
, [ "¡" , 161 ] , [ "¢" , 162 ] , [ "£" , 163 ] , [ "¤" , 164 ] , [ "¥" , 165 ] , [ "¦" , 166 ] _
, [ "§" , 167 ] , [ "¨" , 168 ] , [ "©" , 169 ] , [ "ª" , 170 ] , [ "¬" , 172 ] , [ "­" , 173 ] _
, [ "®" , 174 ] , [ "¯" , 175 ] , [ "°" , 176 ] , [ "±" , 177 ] , [ "²" , 178 ] , [ "³" , 179 ] _
, [ "´" , 180 ] , [ "µ" , 181 ] , [ "¶" , 182 ] , [ "·" , 183 ] , [ "¸" , 184 ] , [ "¹" , 185 ] _
, [ "º" , 186 ] , [ "»" , 187 ] , [ "¼" , 188 ] , [ "½" , 189 ] , [ "¾" , 190 ] , [ "¿" , 191 ] _
, [ "À" , 192 ] , [ "Á" , 193 ] , [ "Ã" , 195 ] , [ "Ä" , 196 ] , [ "Å" , 197 ] , [ "Æ" , 198 ] _
, [ "Ç" , 199 ] , [ "È" , 200 ] , [ "É" , 201 ] , [ "Ê" , 202 ] , [ "Ì" , 204 ] , [ "Í" , 205 ] _
, [ "Î" , 206 ] , [ "Ï" , 207 ] , [ "Ð" , 208 ] , [ "Ñ" , 209 ] , [ "Ò" , 210 ] , [ "Ó" , 211 ] _
, [ "Ô" , 212 ] , [ "Õ" , 213 ] , [ "Ö" , 214 ] , [ "×" , 215 ] , [ "Ø" , 216 ] , [ "Ù" , 217 ] _
, [ "Ú" , 218 ] , [ "Û" , 219 ] , [ "Ü" , 220 ] , [ "Ý" , 221 ] , [ "Þ" , 222 ] , [ "ß" , 223 ] _
, [ "à" , 224 ] , [ "á" , 225 ] , [ "â" , 226 ] , [ "ã" , 227 ] , [ "ä" , 228 ] , [ "å" , 229 ] _
, [ "æ" , 230 ] , [ "ç" , 231 ] , [ "è" , 232 ] , [ "é" , 233 ] , [ "ê" , 234 ] , [ "ë" , 235 ] _
, [ "ì" , 236 ] , [ "í" , 237 ] , [ "î" , 238 ] , [ "ï" , 239 ] , [ "ð" , 240 ] , [ "ñ" , 241 ] _
, [ "ò" , 242 ] , [ "ó" , 243 ] , [ "ô" , 244 ] , [ "õ" , 245 ] , [ "ö" , 246 ] , [ "÷" , 247 ] _
, [ "ø" , 248 ] , [ "ù" , 249 ] , [ "ú" , 250 ] , [ "û" , 251 ] , [ "ü" , 252 ] , [ "þ" , 254 ] ]
EndFunc ;==>_FixHTML