'Aggiorna archivio lotto di Spaziometria (Ramco)_apr2026
'estrazioni prelevate direttamente dalla fonte Lottomatica
Option Explicit
Sub Main
Dim sDirTemp,sDirZip
Dim sLink
Dim sCData,nSalvate,sFileBd
Dim sDataEstr,sDataLastEstr
Dim nEstrTot,id,z,b
Dim aRighe,k
Dim sData,sSigla
Dim aEstr,r,c
Dim aCampi
Dim sCmd,sDestDir
Dim oShell,oFSO
' --- Percorsi file ---
sFileBd = GetDirectoryAppData & "BaseDati.dat"
sDirZip = GetDirectoryTemp & "storico.zip"
sDirTemp = GetDirectoryTemp & "storico.txt"
' --- Pulizia file temporanei ---
Call EliminaFile(sDirZip)
Call EliminaFile(sDirTemp)
' --- Download dello zip ufficiale BrightStar/LottoItalia ---
sLink = "https://www.brightstarlottery.it/STORICO_ESTRAZIONI_LOTTO/storico.zip"
Call Messaggio("Download archivio ufficiale in corso...")
If Not DownloadFromWeb(sLink,sDirZip) Then
Call Scrivi("ERRORE: impossibile scaricare il file zip dal sito LottoItalia.",True,,,vbRed)
Exit Sub
End If
' --- Decompressione zip -> storico.txt tramite PowerShell ---
Call Messaggio("Decompressione archivio...")
sDestDir = GetDirectoryTemp
' Rimuove eventuale backslash finale per PowerShell
If Right(sDestDir,1) = "\" Then sDestDir = Left(sDestDir,Len(sDestDir) - 1)
sCmd = "powershell -NoProfile -Command ""Expand-Archive -Force -LiteralPath '" & sDirZip & "' -DestinationPath '" & sDestDir & "'"""
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
oShell.Run sCmd,0,True
Set oShell = Nothing
If Not oFSO.FileExists(sDirTemp) Then
Call Scrivi("ERRORE: il file storico.txt non trovato dopo la decompressione.",True,,,vbRed)
Call Scrivi("Verificare che PowerShell sia disponibile e che lo zip contenga 'storico.txt'.",True)
Set oFSO = Nothing
Exit Sub
End If
Set oFSO = Nothing
' --- Lettura righe del file TXT ---
ReDim aRighe(0)
If Not LeggiRigheFileDiTesto(sDirTemp,aRighe) Then
Call Scrivi("ERRORE: impossibile leggere storico.txt.",True,,,vbRed)
Exit Sub
End If
Call EliminaFile(sDirZip)
Call EliminaFile(sDirTemp)
' --- Dati archivio corrente ---
nEstrTot = EstrazioniArchivio
sDataLastEstr = DataEstrazione(nEstrTot,,,"/")
' sDataLastEstr e' in formato GG/MM/AAAA
' Convertiamo in AAAA/MM/GG per confronto con il file
z = Right(sDataLastEstr,4) & "/" & Mid(sDataLastEstr,4,2) & "/" & Left(sDataLastEstr,2)
id = IndiceAnnuale(nEstrTot)
b = False
' --- Loop sulle righe del file ---
' Formato riga: AAAA/MM/GG [TAB] SIGLA [TAB] n1 [TAB] n2 [TAB] n3 [TAB] n4 [TAB] n5
' 11 righe consecutive con la stessa data = 1 estrazione
' Ordine sigle nel file: BA CA FI GE MI NA PA RM RN TO VE
' Ordine richiesto da Spaziometria (r=1..11): BA CA FI GE MI NA PA RO TO VE NZ
' Rimappatura necessaria: RM->r=8(RO), RN->r=11(NZ), TO->r=9, VE->r=10
ReDim aEstr(11,5)
sCData = ""
For k = 0 To UBound(aRighe)
If ScriptInterrotto Then Exit For
' Salta righe vuote
If Trim(aRighe(k)) = "" Then
' Se avevamo una estrazione in corso con tutti i dati, la salviamo
Else
' Splitta la riga per TAB
aCampi = Split(aRighe(k),vbTab)
If UBound(aCampi) >= 6 Then
sData = Trim(aCampi(0)) ' AAAA/MM/GG
sSigla = Trim(aCampi(1)) ' BA, CA, ... RM, RN, TO, VE
' --- Nuova data = nuova estrazione ---
If sData <> sCData Then
' Salva l'estrazione precedente solo se b=True E non e' quella di z
If b = True Then
If sCData <> "" Then
If Left(sCData,4) <> Left(sData,4) Then
id = 0
End If
id = id + 1
' Converti sCData da AAAA/MM/GG a GG/MM/AAAA
sDataEstr = Right(sCData,2) & "/" & Mid(sCData,6,2) & "/" & Left(sCData,4)
If SalvaEstrazione(aEstr,sDataEstr,id,sFileBd) Then
nSalvate = nSalvate + 1
Call Messaggio(nSalvate)
Else
ColoreTesto 2
Call Scrivi("ATTENZIONE: errore salvataggio estrazione " & sCData,True)
ColoreTesto 0
End If
End If
End If
' Se la data che STIAMO PER LEGGERE e' z, non ancora b=True
' b diventa True DOPO aver letto z, cioe' alla data successiva
If sCData = z Then b = True
' Reset matrice per nuova data
ReDim aEstr(11,5)
sCData = sData
End If
' --- Popola la riga corretta della matrice in base alla sigla ---
' Rimappatura sigle -> indice ruota Spaziometria
If sSigla = "BA" Then r = 1
If sSigla = "CA" Then r = 2
If sSigla = "FI" Then r = 3
If sSigla = "GE" Then r = 4
If sSigla = "MI" Then r = 5
If sSigla = "NA" Then r = 6
If sSigla = "PA" Then r = 7
If sSigla = "RM" Then r = 8 ' RM nel file = Roma = r=8 in Spaziometria
If sSigla = "TO" Then r = 9
If sSigla = "VE" Then r = 10
If sSigla = "RN" Then r = 11 ' RN nel file = Nazionale = r=11 in Spaziometria
' Popola i 5 estratti (Format2 restituisce stringa a 2 cifre)
For c = 1 To 5
aEstr(r,c) = Format2(CInt(Trim(aCampi(c + 1))))
Next
End If
End If
Call AvanzamentoElab(0,UBound(aRighe),k)
Next
' --- Salva l'ultima estrazione del file (se b=True) ---
If b = True Then
If sCData <> "" Then
id = id + 1
sDataEstr = Right(sCData,2) & "/" & Mid(sCData,6,2) & "/" & Left(sCData,4)
If SalvaEstrazione(aEstr,sDataEstr,id,sFileBd) Then
nSalvate = nSalvate + 1
End If
End If
End If
' --- Riepilogo ---
If nSalvate > 0 Then
AllineaArchivi
Call Scrivi()
Call Scrivi("Script per Spaziometria - Aggiornamento da LottoItalia/BrightStar",True,,,vbBlue)
Call Scrivi()
Call Scrivi("Sono state aggiunte " & nSalvate & " estrazioni")
Call Scrivi()
Call Scrivi("Estrazioni totali: " & EstrazioniArchivio)
Call Scrivi()
Call Scrivi("Fonte: www.lotto-italia.it (archivio ufficiale BrightStar)")
Call Scrivi()
Call Scrivi("RAMCOLOTTO",True,,,vbBlue)
Else
Call Scrivi("NON HO TROVATO NUOVE ESTRAZIONI !",1,,,2)
End If
End Sub