Jump to content

Recommended Posts

Hello,

I've created a script for a Bingo / Lottery kind of game in PHP.

Now I want to make this a standalone application in AutoIT.

I really dont know how to do that as i´m just a Autoit-beginner.

Can you help me with it?

In general I have the following files:

data.csv - the "database" where the bingo-numbers are stored, together with the name of the candidate

index.htm - to show the 'program' in a browser

input.php - to take care of input

results.php - to show the winners

numbers.txt - the winning numbers to compare with

I have the following files:

Input.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<link rel=stylesheet href="style.css" TYPE="text/css">
<title>Input</title>
<?php
$sepsign   = '/;/';
$text     = '';
$wnumbers = '';
$counter    = 0;
$filed     = "data.csv";
$fileg     = "numbers.txt";
$in_numbers = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $name = $_POST['name'];
  $in_numbers = $_POST['$in_numbers'];
}

$fd        = fopen($fileg,"r") or die ("Unable to open $file.");
$text     = fread($fd,filesize($fileg));
$wnumbers = preg_split($sepsign,$text); // wnumbers is an array with winning numbers
Fclose($fd);

for ($j = 0; $j < 10; $j++) {
   for ($i = 0; $i < 10; $i++) {
      if ($wnumbers[$i] == $in_numbers[$j])  { $counter++; }
   }
}   // $counter will contain the number of matches on the input

# Append and write the line in a file <number of matches>;<name>;<number 1>;<number 2>; etc

$fdb = fopen($filed,"a+");
fwrite($fdb,$counter . ";" . $name);
for ($i = 0; $i < 10; $i++) {
   fwrite($fdb,";" . $in_numbers[$i]);
}
fwrite($fdb,"\r\n");
fclose($fdb); 
?>
<h2><br>Your input has been stored successfully!</h2>
</body></html>

Results.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML><head>
<meta http-equiv="Content-Type" content="text/HTML; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<title>Result</title>
</head><BODY>
<h2>Result of the draw</h2><hr><br>
<?php
$sepsign   = '/;/';
$text     = '';
$filed     = "data.csv";
$fileg     = "numbers.txt";

$fd = fopen($filed,"r") or die ("unable to open $file.");
$text = fread($fd,filesize($filed));
$lines = preg_split("/\r\n/",$text);    // Will split the file data.csv in lines
$count_reg = count($lines);
fclose($fd);
sort ($lines);
reset($lines);

for ($i = ($count_reg - 1); $i>($count_reg-4); $i--) {  // The three highest scores are showed
   $collums = preg_split($sepsign,$lines[$i]);
   print "<b>Name: " . $collums[1] . "<br>";
   print "Number of matches: " . $collums[0] . "</b><br>";
   print "Input: ";
   for ($j = 2; $j < 12; $j++) {
     print $collums[$j];
     if ($j <> 11 ) { print ", "; }  // to prevent the "," to appear after the last number
   }
   print "<br><br>";
}
$fd    = fopen($fileg,"r") or die ("Unable to open $file.");
$text = fread($fd,filesize($fileg));
$wnumbers = preg_split($sepsign,$text);
Fclose($fd);

print "<br><b>Bingo numbers</b><br><hr>";
for ($j = 0; $j < 11; $j++) {
   print $wnumbers[$j];
   if ($j < 9 ) { print ", "; }  // to prevent the "," to appear after the last number 
}
?>
</body></html>

Index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<title>Bingo game, input numbers.</title>
</head><body>
<form action="input.php" method="post" name="form">
<center>
<h2>Input numbers</h2>
lines  &nbsp; <input type="text" name="lines" size=20 maxlength=50><br><br>
Number &nbsp;1 &nbsp;<input type="text" name="$in_numbers[0]" size=4><br>
Number &nbsp;2 &nbsp;<input type="text" name="$in_numbers[1]" size=4><br>
Number &nbsp;3 &nbsp;<input type="text" name="$in_numbers[2]" size=4><br>
Number &nbsp;4 &nbsp;<input type="text" name="$in_numbers[3]" size=4><br>
Number &nbsp;5 &nbsp;<input type="text" name="$in_numbers[4]" size=4><br>
Number &nbsp;6 &nbsp;<input type="text" name="$in_numbers[5]" size=4><br>
Number &nbsp;7 &nbsp;<input type="text" name="$in_numbers[6]" size=4><br>
Number &nbsp;8 &nbsp;<input type="text" name="$in_numbers[7]" size=4><br>
Number &nbsp;9 &nbsp;<input type="text" name="$in_numbers[8]" size=4><br>
Number 10&nbsp;<input type="text" name="$in_numbers[9]" size=4><br><br>
<input type="submit" value="Submit..."></FORM>
</center>
<p />&nbsp;<p />
</body></html>
Link to post
Share on other sites
  • 1 month later...

Hello friend! Welcome to autoit. While I don't have the time currently to write an example code for you, I can make some reccomendations which you can look up in the help file.

Depending on if you want the app to work offline, there's two different options I see that you have

The first option is to simply embed the webpage into a gui. (create a GUI then use _IECreateEmbedded) This will allow anyone with an internet connection to access the game.

If you don't wish to require an active internet connection, you can start your job by looking up the following information.

1)To store data (data.cvs and numbers.txt) it's reccomended you use SQLite [_SQLite_Open()], although INI files may work, depending on how much data you plan to store [iniwrite()].

2)Use a InputBox() to request input from the user

3)Process the information the same way you did with php.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Exit
      I make plugins for WordPress and am dissatisfied with the built-in editor.
      I'm now looking for a way to format the PHP code like TIDY does in AU3-Editor.
      I've already tried some online tools but they are buggy or have too few formatting options.

      Buggy: http://www.phpformatter.com/
      Missing options: https://homepage-kosten.de/php_beautifier.php
      Here is the code to check if the beautifier is buggy:
      <?php /* Version: 2021.08.08#1 */ exit ( ' Version is: ' . chop ( substr ( file ( __FILE__ ) [ 2 ] , 9 , 13 ) ) ) ; /* Output from PHP Formatter: Format Error on line 5: parse error, unexpected '['([), expecting ')'! Output in Browser: Version is: 2021.08.08#1 */ ?> It would be great if you showed me a link to another beautifier that is not buggy and has options for compression.  
      e.g. do not put comments in a new line. 
      Or even better, a hint as to which PHP editor in WordPress meets these requirements.
      TIA Exit
    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By XGamerGuide
      hey, I'm trying to convert a PNG and a JPG file into a CUR file in Autoit. Does anyone have a role there? I couldn't find anything
×
×
  • Create New...