Jump to content

Add an expiry date to script


naru
 Share

Recommended Posts

I have script to look at todays date from webpage :

#include <IE.au3>

$oIE = _IEAttach ("Home")
Local $date
Local $oTds = _IETagNameGetCollection($oIE, "li")
For $oTd In $oTds
    If $oTd.className = "nav navbar-btn" Then
        $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd
        ExitLoop
    EndIf
Next

MsgBox(0, "date is", $idate)

It was Find date like :

image.png.da5582a149ebeb397befc8dcea250e99.png.8e0f31ce2d5c306dee3ffddca10b0e26.png

If it is equal or passes my expiry date then it should exit my script

How to make my script stop working after a critain date.

i am trying with this

#include <IE.au3>

$ExpirationDate = '16/04/2019'
$oIE = _IEAttach ("Home")
Local $date
Local $oTds = _IETagNameGetCollection($oIE, "li")
For $oTd In $oTds
    If $oTd.className = "nav navbar-btn" Then
        $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd
        ExitLoop
    EndIf
Next
;~ MsgBox(0, "date is", $idate)
If $idate > $ExpirationDate Then MsgBox(64, 'Info:', "your license has ended")

But it was not working properly, it only follows the date, not month and Year. If the expired date (only date, not month and year) is smaller than the date it has been received get this msg : "your license has ended".  Although there is a big month or year, there is no difference, and the same msg is available.

Link to comment
Share on other sites

6 minutes ago, FrancescoDiMuro said:

@naru

You can't compare two dates like that.

Use _DateDiff() to calclulate the difference between the two dates, and use it in your If statement.

@FrancescoDiMuro

I don't know how to use it in my code, the format of date in _datediff is also different then my date. can you help me please

Edited by naru
Link to comment
Share on other sites

@naru

If you click on _DateDiff() in the previous post, there is the Help file linked, related to that function.

Just adapt your date format with the one of _DateDiff(), and you're done.

One of the many way to format the date for _DateDiff() function:

Global $strNewDate = StringRegExpReplace("17/03/2019", '(\d{2}\/(\d{2}\/(\d{4})', '$3/$2/$1')

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

19 minutes ago, FrancescoDiMuro said:

@naru

If you click on _DateDiff() in the previous post, there is the Help file linked, related to that function.

Just adapt your date format with the one of _DateDiff(), and you're done.

One of the many way to format the date for _DateDiff() function:

Global $strNewDate = StringRegExpReplace("17/03/2019", '(\d{2}\/(\d{2}\/(\d{4})', '$3/$2/$1')

 :)

Not converting date, get same date format :

Captdateure.JPG.a42370937fe6f1495a4018bf167f39a9.JPG

Full code is

include <Date.au3>
#include <IE.au3>
$ExpirationDate = '16/04/2019'
$oIE = _IEAttach ("Home")
Local $date
Local $oTds = _IETagNameGetCollection($oIE, "li")
For $oTd In $oTds
    If $oTd.className = "nav navbar-btn" Then
        $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd
        ExitLoop
    EndIf
Next
Global $strNewDate = StringRegExpReplace($idate, '(\d{2}\/(\d{2}\/(\d{4})', '$3/$2/$1)')
MsgBox(0, "Date", $strNewDate)

 

Link to comment
Share on other sites

First, you added a spurious right parenthesis in the replace string.
Second, the code doesn't work as it has pattern syntax errors.

Try this:

Local $strNewDate = StringRegExpReplace("18/03/2019", '(\d{2})\/(\d{2})\/(\d{4})', '$3/$2/$1')
MsgBox(0, "Date", $strNewDate)

Also note that if you intent to compare dates, for instance using _DateDiff(), then both dates have to use the expected format.

$ExpirationDate = '2019/04/16'

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Oh, I didn't mean to single you out.  We're all prone to make this kind of error, especially while typing trivial code like this on the fly.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd
I know that affirmation wasn't for me .
The problem is always the same... When someone asks for code, without really understanding what the code does, then posts became 5 pages longer because lazy people keep asking for code, and less lazy people keeps giving them, without letting know what the snippet does.

This is what I was meaning :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

32 minutes ago, jchd said:

First, you added a spurious right parenthesis in the replace string.
Second, the code doesn't work as it has pattern syntax errors.

Try this:

Local $strNewDate = StringRegExpReplace("18/03/2019", '(\d{2})\/(\d{2})\/(\d{4})', '$3/$2/$1')
MsgBox(0, "Date", $strNewDate)

Also note that if you intent to compare dates, for instance using _DateDiff(), then both dates have to use the expected format.

$ExpirationDate = '2019/04/16'

 

@jchd Thanks, But i have one more question :

is there any different between this two lines :

Local $strNewDate = StringRegExpReplace("18/03/2019", '(\d{2})\/(\d{2})\/(\d{4})', '$3/$2/$1')   ;~this is your code
$inowdate = StringRegExpReplace($idate, "(\d\d)/(\d\d)/(\d\d\d\d)", "$3/$2/$1")  ;~i found it from in autoit forum

 

Now my full code is :

#include <Date.au3>
#include <IE.au3>

$endDate = "2018/04/17"
$oIE = _IEAttach ("Home")
Local $oTds = _IETagNameGetCollection($oIE, "li")
For $oTd In $oTds
    If $oTd.className = "nav navbar-btn" Then
        $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd
        ExitLoop
    EndIf
Next
$inowdate = StringRegExpReplace($idate, "(\d\d)/(\d\d)/(\d\d\d\d)", "$3/$2/$1")
Local $datediff = _DateDiff('D', $inowdate, $endDate)
MsgBox($MB_SYSTEMMODAL, "", "Number days this year: " & $datediff)
If $datediff > 0 Then
    MsgBox(0, "Running", "this program running", 15)
    Exit
ElseIf $datediff < 0 Then
    MsgBox(0, "Expired", "Sorry, this program has expired, contact ....@gmail.com for an extension.", 15)
    Exit
EndIf

 

Link to comment
Share on other sites

23 minutes ago, naru said:

is there any different between this two lines :

No functional difference, just a matter of style (if you don't count CPU cycles down to nanoseconds).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Depending on the regex engine, there may be is a value of N above which repetition by <pattern>{N} may sometimes be faster than N explicit repeat <pattern><pattern>...<pattern>

Local $d = "123456789 987654321", $s, $t

$t = TimerInit()
For $i = 1 To 1000000
    $s = StringRegExpReplace($d, "(\d{9})\D(\d{9})", "$2 $1")
Next
ConsoleWrite($s & @TAB & TimerDiff($t) & @LF)

$t = TimerInit()
For $i = 1 To 1000000
    $s = StringRegExpReplace($d, "(\d\d\d\d\d\d\d\d\d)\D(\d\d\d\d\d\d\d\d\d)", "$2 $1")
Next
ConsoleWrite($s & @TAB & TimerDiff($t) & @LF)

Escaping / is pointless, I just copied posted code. Besides, it allows the same string to be used in contexts (engines) where patterns are traditionally delimited by /

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...