#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GUIConstantsEx.au3>
Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)
Opt('TrayMenuMode', 3)
Global $sDateTime, $iFile2GTime, $asText1, $asText2, $sText2, $sFile1Size, $hGUI, $hListView, $nCh1, $hButt1, $hButt2, $hButt3, $hGUIState, $hExit, $sLVText
Global $iCheck = True, $sFile1SizePrev = 0, $iOffset = 1, $hFile1, $sFile1 = @ScriptDir & '\1.txt', $sFile2 = @ScriptDir & '\2.txt'
Global $hMAIL = 0, $sCDOConfig = "http://schemas.microsoft.com/cdo/configuration/"
Global $sSMTPServer = 'smtp.inbox.ru' ; SMTP-сервер
Global $sFromAddress = '[email protected]' ; E-mail отправителя
Global $sSendPassword = 'XXXXXXXXX' ; Пароль E-mail отправителя
Global $sToAddress = '[email protected]' ; E-mail получателя
Global $sSubject = 'Price: ' ; Тема письма
$hGUI = GUICreate('Статистика:', 615, 280, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetBkColor(0xB9D1EA)
$hListView = GUICtrlCreateListView('ASIN-10 |Old Price|New Price|SalesRank|Name|Date & Time', 5, 5, 605, 240, _
$LVS_NOSORTHEADER, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_HEADERDRAGDROP))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
Opt("GUIResizeMode", $GUI_DOCKSTATEBAR)
$hButt1 = GUICtrlCreateButton('Скопировать все', 30, 255, 100, 23)
$nCh1 = GUICtrlCreateCheckbox('АвтоОтправка E-mail', 170, 255, 120, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$hButt2 = GUICtrlCreateButton('Очистить список', 330, 255, 100, 23)
$hButt3 = GUICtrlCreateButton('Выйти из программы', 470, 255, 120, 23)
$hGUIState = TrayCreateItem('Отобразить/Скрыть Окно')
TrayCreateItem('')
$hExit = TrayCreateItem('Выход')
GUISetOnEvent($GUI_EVENT_CLOSE, '_CLOSEClicked')
GUICtrlSetOnEvent($hButt1, '_ListViewCopy')
GUICtrlSetOnEvent($nCh1, '_CheckboxState')
GUICtrlSetOnEvent($hButt2, '_ListViewClear')
GUICtrlSetOnEvent($hButt3, '_Exit')
TrayItemSetOnEvent($hGUIState, '_CLOSEClicked')
TrayItemSetOnEvent($hExit, '_Exit')
GUISetState(@SW_HIDE)
$iFile2GTime = FileGetTime($sFile2, 0, 1)
_FilesOpen_Reads(1)
While 1
While 1
$sFile1Size = FileGetSize($sFile1)
Select
Case $sFile1SizePrev < $sFile1Size
$sFile1SizePrev = $sFile1Size
Case $sFile1SizePrev > $sFile1Size
$sFile1SizePrev = 0
_FilesOpen_Reads(0)
EndSelect
$asText1 = StringRegExp(FileReadLine($hFile1), '"(.+?)"\t|[^\t]+', 3)
If @error Or $asText1[0] == 'ASIN' Then
Sleep(50)
ContinueLoop
EndIf
For $i = 0 To 1
$asText2 = StringRegExp($sText2, '\v' & $asText1[0] & '\|(.+?)\|(.+?)\|(.+?)\|', 1, $iOffset)
If @error Then
$iOffset = 1
Else
$iOffset = @extended
ExitLoop 2
EndIf
Next
If @error Then ContinueLoop
WEnd
If $asText1[3] <> 'N/A' And $asText2[1] <> 'N/A' Then
;~ If Number(StringReplace($asText2[1], ',', '.')) / Number(StringReplace($asText1[3], ',', '.')) >= 2 And Number($asText1[9]) < 300000 Then
If Number(StringReplace($asText2[1], ',', '.')) > Number(StringReplace($asText1[3], ',', '.')) And Number($asText1[9]) < 30000000 Then
$sDateTime = @MDAY & '/' & @MON & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC
$sLVItemText = $asText1[0] & '|' & $asText2[1] & '|' & $asText1[3] & '|' & $asText1[9] & '|' & $asText1[1] & '|' & $sDateTime
GUICtrlCreateListViewItem($sLVItemText, $hListView)
GUISetState(@SW_SHOWNORMAL)
SoundPlay(@WindowsDir & '\media\Windows Ringin.wav')
$sLVText &= $sLVItemText & '|' & @CRLF
If $iCheck Then _SendMail($asText1[9], $asText1[0], $asText1[1], 'https://www.autoitscript.com', $sDateTime, $asText2[1], $asText1[3])
EndIf
EndIf
WEnd
Func _FilesOpen_Reads($iFirstStart)
Local $iF2GT, $i = 0
$sText2 = ''
If Not $iFirstStart Then
FileClose($hFile1)
While 1
$i += 1
$iF2GT = FileGetTime($sFile2, 0, 1)
If $iF2GT > $iFile2GTime Then
$iFile2GTime = $iF2GT
ExitLoop
EndIf
If $i >= 60 Then Exit MsgBox(16, 'Ошибка!', 'Файл "2.txt" не обновился.' & @LF & 'Программа будет закрыта.')
Sleep(100)
WEnd
EndIf
For $i = 0 To 30
$hFile1 = FileOpen($sFile1)
If $hFile1 <> -1 Then ExitLoop
Sleep(100)
Next
If $hFile1 = -1 Then Exit MsgBox(16, 'Ошибка!', 'Неудалось открыть файл "1.txt".' & @LF & 'Программа будет закрыта.')
For $i = 0 To 30
$sText2 = StringRegExpReplace(FileRead($sFile2), '\n"(\w{10,12})"\t".+?"\t([\d,N/A]+)\t([\d,N/A]+)\t([\d,N/A]+)\t.+', '${1}|${2}|${3}|${4}|')
If Not @error Then Return
Sleep(100)
Next
MsgBox(16, 'Ошибка!', 'Не удалось открыть или прочитать файл "2.txt".' & @LF & 'Программа будет закрыта.')
_Exit()
EndFunc ;==>_FilesOpen_Reads
Func _SendMail($sRang, $sASIN, $sTitle, $sLink, $sDTime, $sOldPrice, $sNewPrice)
Switch $hMAIL
Case 0
$hMAIL = ObjCreate("CDO.Message")
With $hMAIL
.From = $sFromAddress
.To = $sToAddress
EndWith
With $hMAIL.Configuration.Fields
.Item($sCDOConfig & "sendusing") = 2
.Item($sCDOConfig & "smtpserver") = $sSMTPServer
.Item($sCDOConfig & "smtpusessl") = True
.Item($sCDOConfig & "smtpauthenticate") = 1
.Item($sCDOConfig & "sendusername") = $sFromAddress
.Item($sCDOConfig & "sendpassword") = $sSendPassword
.Item($sCDOConfig & "smtpserverport") = 465
.Update
EndWith
ContinueCase
Case Else
With $hMAIL
.Subject = $sSubject & $sDTime
.HTMLBody = 'Rang: ' & $sRang & '
' & _
'ASIN: ' & $sASIN & '
' & _
'Title: "' & $sTitle & '"
' & _
'Link: <a href="' & $sLink & '">' & $sASIN & '</a>
' & _
'Time: ' & $sDTime & '
' & _
'Old Price: ' & $sOldPrice & ' => New Price: ' & $sNewPrice
.Send
EndWith
EndSwitch
EndFunc ;==>_SendMail
Func _CLOSEClicked()
GUISetState(BitAND(WinGetState($hGUI), 2) ? @SW_HIDE : @SW_SHOWNORMAL)
EndFunc ;==>_CLOSEClicked
Func _CheckboxState()
$iCheck = Not $iCheck
EndFunc ;==>_CheckboxState
Func _ListViewCopy()
ClipPut($sLVText)
ToolTip('Список скопирован в буфер обмена.', Default, Default, 'Сообщение.', 1, 7)
Sleep(900)
ToolTip('')
EndFunc ;==>_ListViewCopy
Func _ListViewClear()
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
$sLVText = ''
EndFunc ;==>_ListViewClear
Func _Exit()
If $hFile1 Then FileClose($hFile1)
Exit
EndFunc ;==>_Exit