Jump to content

Autoit and CSV files


Recommended Posts

I'm in the process of setting up an online store.

My supplier has provided me with a .csv pricelist which contains everything I need to load my inventory.

The supplier provides a location where the image file is stored with imagename.

So in my csv file I have a column with something like.

https\thesupplier.com\images\image1.jpg

https\thesupplier.com\images\image2.jpg

https\thesupplier.com\images\image3.jpg

https\thesupplier.com\images\image4.jpg

https\thesupplier.com\images\image5.jpg

https\thesupplier.com\images\image6.jpg

https\thesupplier.com\images\image7.jpg

https\thesupplier.com\images\image8.jpg

https\thesupplier.com\images\image9.jpg

https\thesupplier.com\images\image10.jpg

How can I loop through each row in the csv and save the image to my local drive as is?

Thanks

Steve

Link to comment
Share on other sites

Basicly you just want to read the file to an array and then check the array and use InetGet().

for a better example, you could help us by posting a couple of complete lines from your csv file. Then, and only then, can we be sure that we give you the proper directions for parsing the lines.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

OK - Here is 3 rows - Sorry if this to much - image url is the last field, There are about 9200 rows

ProdNum,Category,ShortDescrip,LongDescrip,Inventory,ListPrice,YourCost,ImageName,RetailPrice,imagelo

cation

10001,LIGHTS - SPOT/FLOOD/UNDERWATER,ACR RCL-100D REMOTE CONTROL SEARCHLIGHT 12V,"<b>Product No. 1930.3 (12V)/ 1931.3 (24V)<br><br>Remote Controlled Searchlight</b><br><ul><li>200,000 candela</li><br> <li>Internal, elevation mechanism, provides pitch control of spotlight beam; protects elevation mechanism from weather<br> <li>Includes a fingertip remote control Point Pad; up to three remote Point Pad units may be installed on system; surface/flush mount options included<br> <li>Rugged triple-primed and sealed, marine grade aluminum housing<br> <li>Wiring harness 15 ft (4.57 m) length<br> <li>Salt water-resistant construction with nylon and phenolic washers, aluminized stainless steel screws with insulating lubricant<br> <li>Application: Sport yachts, mega-yachts, sport fish and commercial vessels</li></ul><br><b>Size:</b><br><li>8.0 x 9.0 x 8.0 in (20.3 x 22.9 x 20.3 cm)</li><br><br><b>Weight:</b><br><li>7.2 lbs (3.2 kg)</li><br><br><b>Material:</b><br><li>Rugged triple-primed and sealed, marine grade aluminum housing</li><br><br><b>Color:</b><br><li>White</li><br><br><b>Operation:</b><br><li>Remote controlled</li><br><br><b>Accessories:</b><br><li>Universal Remote Control Point Pad for remote control with install kit - P/N 9283.3<br><li>55W/12V Halogen lamp - P/N 6001<br><li>55W/24V Halogen lamp - P/N 6003<br><li>12V searchlight only - P/N 1925<br><li>24V searchlight only - P/N 1926</li><br><br><b>Beam Angle:</b><br><li>5° vertical, 7° horizontal</li><br><br><b>Elevation Angle:</b><br><li>9° up, 17° down</li><br><br><b>Rotation:</b><br><li>360°</li><br><br><b>Rotation Speed:</b><br><li>Fast 28° per second, Slow 18° per second</li><br><br><b>Elevation Speed:</b><br><li>2°-7° per second - (12VDC) 5°-8° per second - (24VDC)</li><br><br><b>Lamp:</b><br><li>High intensity 55W Halogen</li><br><br><b>Limited Warranty:</b><br><li>1 year</li><br><br><b>Carton Dimensions:</b><br><li>13.0 x 21.0 x 10.0 in (33.0 x 53.0 x 25.4 cm)</li><br><br><b>Units per Carton:</b><br><li>1</li><br><br><b>Carton Weight:</b><br><li>14.0 lbs (6.3 kg)</li><br>",5,1708,822.51,10001.gif,"1,028.14",https://images.xxxx.com/product/images/10001.gif

10002,VHF HANDHELD,ACR SURVIVAL RADIO VHF MULTI CHANNEL GMDSS,"<b>Product No. 2727</b><br>Multi-Channel VHF GMDSS Survival Radio<br><ul><li>All maritime Simplex channels, including weather<br> <li>Automatic selection of channel 16 upon switch-on<br> <li>Floats to allow retrieval if lost overboard unlike other radios<br> <li>Simple touch pad operation for unskilled users or gloved hands<br> <li>Highly visible yellow case waterproof to 10 ft (3.3 m)<br> <li>Can be packed in life rafts/lifeboats<br> <li>Coiled lanyard, belt clip and adjustable wrist lanyard<br> <li>Antenna, circuitry and power are tuned for maximum range<br> <li>Reflective tip on antenna<br> <li>Comes with user-replaceable lithium battery - rechargeable battery with charger available<br> <li>Operating life: 8 hours continuous (lithium), up to 6 hours (rechargeable)</li></ul><br><b>Size:</b><li>2.6 x 1.7 x 7.6 in (6.6 x 4.3 x 19.0 cm)</li><br><br><b>Weight:</b><br><li>1.0 lb (453 g) including lithium battery</li><br><br><b>Material:</b><br><li>Isoplast</li><br><br><b>Color:</b><br><li>Yellow</li><br><br><b>Operation:</b><br><li>Correctly position or press ""ON/OFF"" switch, channel up or down<br><br><b>Waterproof:</b><br><li>Up to 10 ft (3.3 m)</li><br><br><b>Frequency:</b><br><li>VHF FM</li><br><br><b>Battery Type:</b><br><li>User-replaceable lithium battery</li><br><br><b>Modulation:</b><br><li>FM</li><br><br><b>Certification:</b><br><li>Complies with GMDSS, SOLAS/IMO A.605(15), FCC Approved; CE</li><br><br><b>Limited Warranty:</b><br><li>1 year</li><br><br><b>Operational Life:</b><br><li>Multi-channel - 8 hours continuous (lithium), up to 6 hours (rechargeable) 16/6 - 8 hours @ - 20C (-4F), longer in temperate waters</li><br> ",2,600,320.86,10002.gif,401.08,https://images.xxxx.com/product/images/10002.gif

10003,EPIRBS,ACR RAPIDFIX 406 MHZ EPIRB GPS INTERFACE CATEGORY 2,"<b>RapidFix 406</b><br><br><br>406 MHz EPRIB with GPS Interface Category II (Manually Deployable)<br><br><ul><li>GPS Interface optical data interface via Infrared diode (NMEA 0183): New, flashing LED in GPS optical interface confirms data transmission from GPS; downloaded GPS coordinates confirmed by flashing LEDs within three seconds of completing self-test sequence<br> <li>Fastest means available of delivering GPS position<br> <li>Patented proprietary electronics package for faster, more stable 406 frequency transmission; full functional self-test including battery voltage and internal circuitry<br> <li>Field programmable at BRC equipped with FPR-100, FPR-10<br> <li>Lanyard coil retained with all around cover for non-tangling deployment<br> <li>Universal usage illustrations; English and French languages<br> <li>Built-in strobe for enhanced location in poor visibility conditions<br> <li>Single, three-position switch for easy test and operation. Steady green LED indicates unit has passed full functional test, flashing red LED indicates unit is ON <br> <li>Transmits on 406 MHz (COSPAS-SARSAT) with your registered, digitally-coded distress signal, and 121.5 MHz (SAR homing frequency)<br> <li>Can be manually activated; self-buoyant no external float collar to lose<br> <li>Exclusive, polycarbonate blend designed for maximum resistance to UV and chemicals; maximum durability when exposed to extreme temperatures or shock<br> <li>5-year limited warranty<br> <li>5-year replacement life (11-year useful life) lithium battery<br> <li>Operating life 48 hours @ -40C (-40F)</li></ul><br><br><br><b>Size:</b><br><li>3.7 x 7.2 x 4.3 in (9.4 x 18.3 x 10.9 cm)</li><br><br><b>Antenna:</b> <br><li>7.4 in (18.8 cm)</li><br><br><b>Weight:</b><br><li>2 lbs. (900 g)</li><br><br><b>Material:</b><br><li>High impact polycarbonate blend case</li><br><br><b>Color:</b><br><li>Hi-Viz Yellow</li><br><br><b>Deployment:</b><br><li>Manual</li><br><br><b>Operation:</b><br><li>Lift switch up, slide left, push back and down fully, breaking tab; water activated when out of bracket</li><br><br><b>Waterproof:</b><br><li>33 ft (10 m)</li><br><br><b>Accessories:</b><br><li>1096 Battery replacement kit <i>(available to BRCs only)</i><br><br><b>Certification:</b><br><li>Approved by COSPAS-SARSAT, FCC, USCG, other International approvals</li><br><br><b>Limited Warranty:</b><br><li>5 years</li><br><br><b>Carton Dimensions:</b><br><li>4.5 x 5.2 x 8.2 in (11.5 x 13.0 x 21.0 cm)</li><br><br><b>Units Per Carton:</b><br><li>1</li><br><br><b>Carton Weight:</b><br><li>2.10 lbs. (1 kg)</li><br><br><b>Frequency:</b><br><li>406 MHz, 121.5 MHz</li><br><br><b>Battery Type:</b><br><li>Lithium 5-year replacement life (11-year storage life)</li><br><br><b>Modulation:</b><br><li>AM</li><br><br><b>Radiated Power:</b><br><li>5 watts 2dB (406 MHz) 50 mW 3dB (121.5 MHz)</li><br><br><b>Operational Life:</b><br><li>48 hours @ -40C (-40F)</li><br><br> ",0,880,498.91,10003.gif,623.64,https://images.xxxx.com/product/images/10003.gif

Link to comment
Share on other sites

$CSV = "test.csv"
$SavePath = @ScriptDir

$string = FileRead($CSV)
$array = StringRegExp($string, "(http.*\.gif)",3)
If IsArray($array) Then
    For $X = 0 to Ubound($array)-1
        ConsoleWrite("["&$X&"]: " & $array[$X] & @CRLF)
        
        $FileName = StringTrimLeft($array[$X],StringInStr($array[$X], "/", 0,-1))
        ConsoleWrite($FileName & @CRLF)
        
        InetGet($array[$X],$SavePath & "\" & $FileName)
    Next
Else
    ConsoleWrite("No image links found")
EndIf

Link to comment
Share on other sites

Since Its the last item it's straight forward

#include<File.au3>
$File = "path\My_File.csv"
$fArray = ""
 _FileReadToArray($file, $fArray)
For $I = 2 To Ubound($fArray)-1
   If NOT StringInStr($fArray[$I], "images/") Then ContinueLoop
   $adata = StringSplit($fArray[$I], ",")
   $fLoc = $adata[Ubound($adata)-1]
   InetGet($fLoc);; You may want to specify a folder\filename here.  See the helpfile.
   While @InetGetActive <> 0
      Sleep(50)
   Wend
Next

Now if you wait patiently I'm sure someone will come along with a method of parsing the file using StringRegExpr() which will be much faster.

Edit:

Instead of using the stringsplit like I showed you could also use;

#include<File.au3>
$File = "path\My_File.csv"
$fArray = ""
 _FileReadToArray($file, $fArray)
For $I = 2 To Ubound($fArray)-1
   If NOT StringInStr($fArray[$I], "images/") Then ContinueLoop
   $fLoc = StringMid($fArray[$I], StringInStr($fArray[$I], "http"))
   InetGet($fLoc);; You may want to specify a folder\filename here.  See the helpfile.
   While @InetGetActive <> 0
      Sleep(50)
   Wend
Next
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, since none of the regex experts junped in, I had to do it myself

;
$File = "path\myfile.csv"
$srxOut = StringRegExp(FileRead($File), "(?i)http.*\r\n|\z", 3)
For $I = 0 To Ubound($srxOut)-1
   If $srxOut[$i] = "" Then ContinueLoop
   InetGet($srxOut[$I]);; You may want to specify a folder\filename here.  See the helpfile.
   While @InetGetActive
      Sleep(50)
   Wend
Next
;
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, since none of the regex experts junped in, I had to do it myself

;
 $File = "path\myfile.csv"
 $srxOut = StringRegExp(FileRead($File), "(?i)http.*\r\n|\z", 3)
 For $I = 0 To Ubound($srxOut)-1
    If $srxOut[$i] = "" Then ContinueLoop
    InetGet($srxOut[$I]);; You may want to specify a folder\filename here.  See the helpfile.
    While @InetGetActive
       Sleep(50)
    Wend
 Next
;
You missed post #4...
Link to comment
Share on other sites

You missed post #4...

I did so, and the RegEx is better too. :)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Btw; Yours is slightly syntacticly incorrect.

http.*\.gif says that there may or may not be characters after http.

http.+?\.gif says that there will be characters after http.

:)

Of course that makes mine incorrect as well.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...