I have an mp3.txt file which contains URLs to download. How do I read the contents to then download the URLs? I tried this but it's not working:
Func _downloader($link)
Local $dwnarrayread[3] = [IniRead(#ScriptDir & "\mp3.txt", "file_links", "link_1", Default), IniRead(#ScriptDir & "\mp3-2.txt", "file_links", "link_2", Default), IniRead(#ScriptDir & "\mp3-3.txt", "file_links", "link_3", Default)]
$dwnlink = InetGet($dwnarrayread[$link], #ScriptDir & "PSU-04.mp3", 1, 1)
Do
Sleep(50)
$prc = Round(InetGetInfo($dwnlink, 0) / (InetGetInfo($dwnlink, 1)) * 100)
GUICtrlSetData($progressbar1, $prc)
Until InetGetInfo($dwnlink, $INET_DOWNLOADCOMPLETE)
EndFunc
mp3.txt file :
[files_links]
link_1=https://ftp.psu.ac.th/pub/demo/mp3/PSU-04.mp3
link_2=http://somesite.com/files/file2.zip
link_3=http://somesite.com/files/file3.zip
How do I read the contents to then download the URLs?
Example (as per additional requirement):
_Download('mp3.txt', 'files_links', #DesktopDir & '\')
Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
Local Const $aFile = IniReadSection($sFileIni, $sSection)
For $i1 = 1 To $aFile[0][0]
InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)))
Next
EndFunc
Example as per GUICtrlSetData() -attempt:
#include <AutoItConstants.au3>
#include <InetConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
_Download('mp3.txt', 'files_links', #DesktopDir & '\')
Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
Local Const $aFile = IniReadSection($sFileIni, $sSection)
Local $aDownload[$aFile[0][0] + 1]
$aDownload[0] = $aFile[0][0]
For $i1 = 1 To $aFile[0][0]
$aDownload[$i1] = InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)), $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Next
Local Const $iWidth = 400, _
$iHeight = 20
Local $hWnd = GUICreate(#ScriptName, $iWidth, $iHeight * $aDownload[0])
Local $aHnd[$aDownload[0] + 1]
For $i1 = 1 To $aDownload[0]
$aHnd[$i1] = GUICtrlCreateProgress(0, ($i1 - 1) * $iHeight, $iWidth, $iHeight)
GUICtrlSetTip($aHnd[$i1], $aFile[$i1][1])
Next
GUISetState(#SW_SHOW, $hWnd)
Local $aInfo
While Not (GUIGetMsg() = $GUI_EVENT_CLOSE)
For $i1 = 1 To $aDownload[0]
$aInfo = InetGetInfo($aDownload[$i1])
GUICtrlSetData($aHnd[$i1], ($aInfo[$INET_DOWNLOADCOMPLETE] Or $aInfo[$INET_DOWNLOADSUCCESS]) ? 100 : $aInfo[$INET_DOWNLOADSIZE] / $aInfo[$INET_DOWNLOADREAD])
Next
If InetGetInfo() Then ContinueLoop
MsgBox($MB_OK, #ScriptName, 'No more running downloads.', 0, $hWnd)
ExitLoop
WEnd
For $i1 = 1 To $aDownload[0]
InetClose($aDownload[$i1])
Next
EndFunc
Related
I'm having trouble identifying and opening the file that contains the data of an application programmed in old VB.
I found in source code a subroutine that opens location and data upload files:
***** LOCATION SUBJECT AND LOADING TEST DATA *********
LOADING:
GoSub ABREARQ
If Val(BAKCP$) >= Val(NI$) And Val(BAKCP$) <= Val(NF$) Then
GoSub LIMPA
Else
GoSub LIMPA
Get #1, 1, GEALL: ORD1& = Val(GEALL.FB)
EX& = 0
Open Path$ + "NSALL.IND" For Random Shared As #5 Len = Len(NSALL)
NR& = LOF(5) / Len(NSALL)
If ORD1& > (NR& + 2) Then
For IX& = ORD1& - 1 To NR& + 2 Step -1
Get #1, IX&, GEALL
If Val(BAKCP$) >= Val(GEALL.NI) And Val(BAKCP$) <= Val(GEALL.NF) Then
EX& = IX&: IX& = NR& + 2
End If
Next
End If
If EX& = 0 Then
BR& = 1: TR& = NR&
Do Until (TR& < BR&)
MR& = Int((TR& + BR&) / 2)
Get #5, MR&, NSALL
If Val(BAKCP$) >= NSALL.NSI And Val(BAKCP$) <= NSALL.NSF Then
EX& = NSALL.RE
Exit Do
ElseIf Val(BAKCP$) > NSALL.NSI Then
BR& = MR& + 1
Else
TR& = MR& - 1
End If
Loop
End If
Close #5
If EX& <> 0 Then
Get #1, EX&, GEALL
FB$ = GEALL.FB: NI$ = GEALL.NI: NF$ = GEALL.NF: NP$ = GEALL.NP: NP0$ = GEALL.NP
REGDT& = EX& - 1: REGRS& = Val(GEALL.RS)
GoSub CARGADT
MSG$ = ""
Else
For Y = 1 To 12: For X = 1 To DT%(0, Y): DT$(X, Y) = "": Next: Next
FB$ = "": NI$ = "": NF$ = "": NP$ = "": NP0$ = ""
REGDT& = 0: REGRS& = 0
MSG$ = " N„o cadastrado/inex.! "
BAKCP$ = " ": Close: Return
End If
End If
Here is the routine that opens the files:
ABREARQ:
Open Path$ + "GEALL.ENS" For Random Shared As #1 Len = Len(GEALL)
Open Path$ + "DTALL.ENS" For Random Shared As #2 Len = Len(DTALL)
Open Path$ + "RSALL.ENS" For Random Shared As #3 Len = Len(DR)
Open Path$ + "CFALL.ENS" For Random Shared As #4 Len = 1080
FIELD #4, 1075 AS CFALL$, 5 AS PROX$
Return
I think the memory files are those with .ENS extension, but when I open them in text format, random and messy numbers appear.
Is there another way to open these ENS files?
Thanks in advance
I try to split a string into a multidimensional array, but it is not working the way I want. I just split a string to some arrays where one 2 dimensional array should represent a table. I can see the array using _ArrayDisplay() but I cannot work with the array elements itself. The Line:
For $j = 1 To $aTable1Row[$i][0]
reports "incorrect number of subscripts". But if I do:
MsgBox(1, "TEST", UBound($aTable1Row[$i]))
it shows this array has 8 elements. So they are there but I somehow cannot access them. Full source code:
#include <Array.au3>
$string = "az#1:y#2:x#3:w#4:v#5:u#6:t#7-bz#1:y#2:x#3:w#4:v#5:u#6:t#7-cz#1:y#2:x#3:w#4:v#5:u#6:t#7"
$aTable1 = StringSplit($string, '-',1)
_ArrayDisplay($aTable1)
;3
;az#1:y#2:x#3:w#4:v#5:u#6:t#7
;bz#1:y#2:x#3:w#4:v#5:u#6:t#7
;cz#1:y#2:x#3:w#4:v#5:u#6:t#7
Local $aTable1Row[$aTable1[0]+1]
$aTable1Row[0] = $aTable1[0]
For $i = 1 To $aTable1Row[0]
$aTable1Row[$i] = StringSplit($aTable1[$i], ':',1)
_ArrayDisplay($aTable1Row[$i])
;7
;az#1
;y#2
;x#3
;w#4
;v#5
;u#6
;t#7
;do stuff
For $j = 1 To $aTable1Row[$i][0]
$aTable1Row[$i][$j] = StringTrimLeft(($aTable1Row[$i])[$j], StringInStr(($aTable1Row[$i])[$j], '#'))
Next
Next
… this array has 8 elements.
That For -loop addresses a 1 dimensional array as if it were a 2 dimensional one, hence the Array variable has incorrect number of subscripts or subscript dimension range exceeded. -error.
Declare a 2 dimensional array first. Example (no error-checking):
#include <StringConstants.au3>
#include <Array.au3>
Global Const $g_sString = 'az#1:y#2:x#3:w#4:v#5:u#6:t#7-bz#1:y#2:x#3:w#4:v#5:u#6:t#7-cz#1:y#2:x#3:w#4:v#5:u#6:t#7'
Global Const $g_sDelimRow = '-'
Global Const $g_sDelimCol = ':'
Global Const $g_aArray2D = StringSplitToArray2D($g_sString, $g_sDelimRow, $g_sDelimCol)
_ArrayDisplay($g_aArray2D, #ScriptName)
Func StringSplitToArray2D(Const $sString, Const $sDelimiterRow, Const $sDelimiterCol)
Local $aArray1DRows = StringSplit($sString, $sDelimiterRow, $STR_ENTIRESPLIT)
Local $aArray1DCols = StringSplit($aArray1DRows[1], $sDelimiterCol, $STR_ENTIRESPLIT)
Local $aArray2D[ $aArray1DRows[0] + 1 ][ $aArray1DCols[0] + 1 ]
For $i1 = 1 To $aArray1DRows[0]
$aArray1DCols = StringSplit($aArray1DRows[$i1], $sDelimiterCol, $STR_ENTIRESPLIT)
For $i2 = 1 To $aArray1DCols[0]
$aArray2D[$i1][$i2] = $aArray1DCols[$i2]
Next
Next
Return $aArray2D
EndFunc
Consider _FileReadToArray() if stored as text/CSV file. Related.
#include <StringConstants.au3>
#include <Array.au3>
Global Const $g_sString = 'az#1:y#2:x#3:w#4:v#5:u#6:t#7-bz#1:y#2:x#3:w#4:v#5:u#6:t#7-cz#1:y#2:x#3:w#4:v#5:u#6:t#7'
Global Const $g_sDelimRow = '-'
Global Const $g_sDelimCol = ':'
Global Const $g_aArray2D = StringSplit2D($g_sString, $g_sDelimCol, $g_sDelimRow)
_ArrayDisplay($g_aArray2D, #ScriptName)
Func StringSplit2D($sMatches = "Hola-2-5-50-50-100-100|Hola-6-200-200-100-100", Const $sDelim_Item = "-", Const $sDelim_Row = "|")
Local $iValDim_1, $iValDim_2 = 0, $iColCount
Local $aSplit_1 = StringSplit($sMatches, $sDelim_Row, $STR_NOCOUNT + $STR_ENTIRESPLIT)
$iValDim_1 = UBound($aSplit_1, $UBOUND_ROWS)
Local $aTmp[$iValDim_1][0], $aSplit_2
For $i = 0 To $iValDim_1 - 1
$aSplit_2 = StringSplit($aSplit_1[$i], $sDelim_Item, $STR_NOCOUNT + $STR_ENTIRESPLIT)
$iColCount = UBound($aSplit_2)
If $iColCount > $iValDim_2 Then
$iValDim_2 = $iColCount
ReDim $aTmp[$iValDim_1][$iValDim_2]
EndIf
For $j = 0 To $iColCount - 1
$aTmp[$i][$j] = $aSplit_2[$j]
Next
Next
Return $aTmp
EndFunc ;==>StringSplit2D
It is a very stable function and it was used in massive projects, tested millions of times.
Result
I created a python script to pull the data from facebookads API and create a file in google cloud storage by using google app engine.
getting the following error while writing the data to google cloud storage but data is displaying properly on web browser:
IOError: Buffer is closed.
After some research I understood that, this error will come when not able to recognize end of the lin ("\n") , so it treats the entire file as a single line and raise "Buffer is Closed" error.
So I added following code and now displaying rows properly on web browser but still getting error while writing into gcs.
data1=data.replace("\n", "<br />")
Code:
class get_region_insights(webapp.RequestHandler):
_apptitle = None
_projectid = None
_projectnumber = None
def get(self):
#bucket_name = os.environ.get('BUCKET_NAME', app_identity.get_default_gcs_bucket_name())
cfg=appsettings()
for i in cfg._templates:
id=int(i['_id'])
if id == 7:
### Read variables from config file
bucket_name = i['_gcsbucket']
bucket = '/' + bucket_name
filename = bucket + '/' + i['_filename'] + str(time.strftime("%d_%m_%Y")) + ".csv"
ad_acct=i['_ad_acct']
app_id = i['_app_id']
app_secret = i['_app_secret']
access_token = i['_access_token']
needed_keys=ast.literal_eval(i['_needed_keys'])
self.tmp_filenames_to_clean_up = []
u = date.today()
sub_days = 1
s = u - timedelta(sub_days)
until = str(u)
since = str(s)
params = {
'fields': [
FBAdsInsights.Field.account_id,
FBAdsInsights.Field.campaign_id,
FBAdsInsights.Field.campaign_name,
FBAdsInsights.Field.adset_id,
FBAdsInsights.Field.adset_name,
FBAdsInsights.Field.impressions,
FBAdsInsights.Field.spend,
FBAdsInsights.Field.actions,
FBAdsInsights.Field.action_values,
],
'filtering': [
{
'field': 'action_type',
'operator': 'IN',
'value': ["link_click","comment", "post_reaction", "post", "offsite_conversion.fb_pixel_purchase"] #custom rule filter
},
],
'level': 'adset',
'time_range': {
'since': since, #user input field
'until': until #specify dynamic date range between (today() - (days_entered)) and today()
},
'time_increment': 1,
'breakdowns': ['region'],
'action_breakdowns': ['action_type'],
}
### Initializing Google cloud Storage Object
write_retry_params = _gcs.RetryParams(backoff_factor=1.1)
gcs_file=_gcs.open(filename, 'w', content_type='text/plain',retry_params=write_retry_params)
### Facebook Initialization
session=FacebookSession(app_id,app_secret,access_token)
api=FacebookAdsApi(session)
FacebookAdsApi.set_default_api(api)
ad_account = FBAdAccount(ad_acct)
stats = ad_account.get_insights(params=params,async=True)
stats.remote_read()
while stats[AdReportRun.Field.async_percent_completion] < 100:
time.sleep(1)
stats.remote_read()
time.sleep(1)
stats1 = stats.get_result()
x = [x for x in stats1]
### Printing the result and writing to Google Cloud Storage
for i in x:
for k in i['actions']:
if k['action_type'] == "offsite_conversion.fb_pixel_purchase":
Purchase_Facebook_Pixel = k['value']
if k['action_type'] == "comment":
post_comment= k['value']
if k['action_type'] == "link_click":
link_click=k['value']
if k['action_type'] == "post":
post_share=k['value']
if k['action_type'] == "post_reaction":
post_reaction=k['value']
for m in i['action_values']:
if m['action_type'] == "offsite_conversion.fb_pixel_purchase" :
Purchase_Conversion_Value_Facebook_Pixel=m['value']
data=(i['account_id'] + "," + i['adset_id'] + "," + i['campaign_id'] + "," + i['date_start'] + "," + i['date_stop'] + ","+ i['impressions']+ "," + i['region'] + ","+ i['spend']+ "," + link_click + "," + Purchase_Facebook_Pixel + "," + Purchase_Conversion_Value_Facebook_Pixel+"\n")
data1=data.replace("\n", "<br />")
self.response.write(data.replace("\n", "<br />"))
#self.response.write("\n"+i['account_id'] + "," + i['adset_id'] + "," + i['adset_name'] + "," + i['age'] + "," + i['campaign_id'] + "," +i['campaign_name'] + "," + i['date_start'] + "," + i['date_stop'] + ","+i['gender'] + ","+ i['impressions']+","+ i['spend']+ "," + link_click + "," + post_comment + "," + post_share + "," + post_reaction + "," + Purchase_Facebook_Pixel + "," + Purchase_Conversion_Value_Facebook_Pixel+"\n")
gcs_file.write(data1.encode('utf-8'))
gcs_file.close()
self.tmp_filenames_to_clean_up.append(filename)
You are opening the cloud storage file outside your loop, but then you close inside the loop.
### Initializing Google cloud Storage Object
write_retry_params = _gcs.RetryParams(backoff_factor=1.1)
gcs_file=_gcs.open(filename, 'w', content_type='text/plain',retry_params=write_retry_params)
### Facebook Initialization
...
### Printing the result and writing to Google Cloud Storage
for i in x:
# do stuff with data
...
gcs_file.write(data1.encode('utf-8'))
gcs_file.close() # <-- closing the file buffer
self.tmp_filenames_to_clean_up.append(filename)
If you want to write one file for each loop iteration, open and close the file inside the loop.
If you want to to write all the data to a single file, open and close the file outside the loop.
I need some help with storing image form elements in a array.
I have tried to use As Object/Variant and I've run out of logical options to try
As you can see below, the names of the images are I_Monday, I_Tuesday etc.
Current code:
Dim I_Day(0 To 4) As Image
I_Day(0) = I_Monday
I_Day(1) = I_Tuesday
I_Day(2) = I_Wednesday
I_Day(3) = I_Thursday
I_Day(4) = I_Friday
The elements with be accessed in a for loop.
For i = 0 To 4
If sht.Cells(nameRow, weekNum + i).Value = "Pass" Then
I_Day(i).BackColor = RGB(0, 255, 0)
ElseIf sht.Cells(nameRow, weekNum + i).Value = "Fail" Then
I_Day(i).BackColor = RGB(255, 0, 0)
Else
I_Day(i).BackColor = RGB(0, 0, 255)
End If
Next i
Thanks for any help.
Edit: Should probably mention the error message:
Run time error 91:
Object variable or with block not set
Because they are objects, you need to use Set when assigning them:
Dim I_Day(0 To 4) As Image
Set I_Day(0) = I_Monday
Set I_Day(1) = I_Tuesday
Set I_Day(2) = I_Wednesday
Set I_Day(3) = I_Thursday
Set I_Day(4) = I_Friday
So here's my current code:
Local $source = "C:\Users\EXAMPLE\Documents\EXAMPLE"
Local $password = "Example"
Local $array = _FileListToArrayRec($source, "*", 1, , 1, 2); LOADS ALL FILES FROM $source AS AN ARRAY
I don't know how to continue from there because what I want to do is take all of the files in that array and encrypt them all. But that's where another problem arises, how do I encrypt all of the files and save them in the SAME LOCATION?
Example: _Crypt_EncryptFile($sSourceFile, $sDestinationFile, $vCryptKey, $iALG_ID) takes a file and saves the unencrypted version to another location, how do I make it so that it overrides the original file with the encrypted version? I'm VERY stumped here and have Googled multiple subjects and can't find anything that would help me, so I came here hoping I could find my answer. Anyways thanks in advance.
#include <Crypt.au3>
#include <File.au3>
Local $sSource = "C:\Users\EXAMPLE\Documents\EXAMPLE"
Local $sPassword = "Example"
Local $aArray = _FileListToArrayRec($sSource, "*", 1, 1, 1, 2); LOADS ALL FILES FROM $sSource AS AN ARRAY AND AS A FULLPATH
If Not #error Then
For $i = 1 To $aArray[0]
If Not _Crypt_EncryptFile($aArray[$i], $aArray[$i], $sPassword, $CALG_AES_256) Then
ConsoleWrite("Error: " & #error & ", " & $aArray[$i] & #CRLF)
EndIf
Next
EndIf
If you need file encryption for AutoIt consider the solution listed here
https://www.autoitscript.com/forum/topic/178131-autoit-string-files-encryption/
It uses polymorphic (random) encryption on the file and generates the output code in AutoIt with the file contents encrypted:
; encrypted with https://www.stringencrypt.com (v1.0.0) [AutoIt]
#include <Array.au3>
; $Label = "Fast & easy AutoIt string and file encryption."
Global $Label[47] = [ 0xC254, 0xC273, 0xC261, 0xC260, 0xC212, 0xC236, 0xC202, 0xC24B, _
0xC253, 0xC281, 0xC277, 0xC20C, 0xC22B, 0xC277, 0xC27E, 0xC27D, _
0xC21B, 0xC280, 0xC22A, 0xC281, 0xC27E, 0xC25A, 0xC237, 0xC232, _
0xC255, 0xC21C, 0xC24F, 0xC22A, 0xC24E, 0xC214, 0xC248, 0xC247, _
0xC23E, 0xC237, 0x3E0A, 0xC233, 0xC234, 0xC251, 0xC27C, 0xC227, _
0xC282, 0xC280, 0xC247, 0xC27D, 0xC224, 0xC23E, 0x3D92 ];
For $SYdIB = 0 to 46
$fWyHA = $Label[$SYdIB];
$fWyHA += $SYdIB;
$fWyHA = BitNOT($fWyHA);
$fWyHA = BitXOR($fWyHA, $SYdIB);
$fWyHA += $SYdIB;
$fWyHA -= $SYdIB;
$fWyHA = BitXOR($fWyHA, $SYdIB);
$fWyHA = $fWyHA - 1;
$fWyHA = BitXOR($fWyHA, $SYdIB);
$fWyHA = $fWyHA + 1;
$fWyHA += $SYdIB;
$fWyHA = BitXOR($fWyHA, 0xC212);
$fWyHA = BitNOT($fWyHA);
$fWyHA += $SYdIB;
$Label[$SYdIB] = ChrW(BitAND($fWyHA, 0xFFFF));
Next
$Label = _ArrayToString($Label, "")
ConsoleWrite($Label);
It's also pretty hard to overcome by deobfuscators because of the complex and random decryption code.