iMacros read column .csv from choice of user between 1 to 10 - csv

I have a question that is similar to the following link:
iMacros: user defined variables within !COLn?
I've tried that apply to my script (bellow) but error, like this:
SyntaxError: unterminated string literal, line 12 (Error code: -1001)
line 12 is :
SET col EVAL("var col=eval('[{{row}}]'); col[{{!VAR1}} - 1];")
The following is my full script with the same question, NEED TO ENTRY TEXT FROM .CSV FILE, BUT iMacros READ COLUMN IS FROM CHOICE OF USER BETWEEN 1 to 10.
VERSION BUILD=8871104 RECORDER=FX
TAB T=1
SET !REPLAYSPEED FAST
SET !TIMEOUT_PAGE 10
SET !TIMEOUT_STEP 1
SET !DATASOURCE c:\option\abc.csv
SET !DATASOURCE_LINE 2
PROMPT "Please enter CSV column:\n\n1. Red \n2. Green \n3. Blue \n4.so on" !VAR1
SET row "'{{!COL1}}', '{{!COL2}}', '{{!COL3}}', '{{!COL4}}', '{{!COL5}}', '{{!COL6}}', '{{!COL7}}', '{{!COL8}}', '{{!COL9}}', '{{!COL10}}'"
SET col EVAL("var col=eval('[{{row}}]'); col[{{!VAR1}} - 1];")
EVENT TYPE=MOUSEUP POINT="(679,785)"
EVENTS TYPE=KEYPRESS SELECTOR="#main>FOOTER>DIV:nth-of-type(2)>DIV>DIV>DIV:nth-of-type(2)" CHARS={{col}}

SyntaxError: unterminated string literal is likely a browser issue while parsing the code within the eval, for me your code works 100% out of the box.
Try line 12 like this (by removing [ ]):
SET col EVAL("var col=eval('{{row}}'); col[{{!VAR1}} - 1];")
Else, run your code with a different browser/version.

Related

Check for duplicates when using tab-separated txt file to generate iTunes playlist

I'm using the following code in Applescript to generate iTunes playlists from a tab-separated .txt file. However, I wondered if there is a way of getting it to check if the files are already in the target playlist before adding each file?
set thisTSVFile to (choose file with prompt "Select the CSV file")
readTabSeparatedValuesFile(thisTSVFile)
set theList to readTabSeparatedValuesFile(thisTSVFile)
tell application "iTunes"
set myPlaylist to playlist "InSLtxtLists"
set sourcePlaylist to playlist "Music"
end tell
repeat with i from 2 to number of items in readTabSeparatedValuesFile(thisTSVFile)
--gets first column
set theName to item 1 of item i of theList
--gets second
set theArtist to item 2 of item i of theList
tell application "iTunes"
try
duplicate (some track of sourcePlaylist whose name is theName and artist is theArtist) to myPlaylist
on error the errorMessage
set
end try
end tell
delay 0.1
end repeat
on readTabSeparatedValuesFile(thisTSVFile)
try
set dataBlob to (every paragraph of (read thisTSVFile))
set the tableData to {}
set AppleScript's text item delimiters to tab
repeat with i from 1 to the count of dataBlob
set the end of the tableData to (every text item of (item i of dataBlob))
end repeat
set AppleScript's text item delimiters to ""
return tableData
on error errorMessage number errorNumber
set AppleScript's text item delimiters to ""
error errorMessage number errorNumber
end try
end readTabSeparatedValuesFile
For reference, each line in the .txt file is formatted like this:
'Allo 'Allo! Theme (David Croft & Roy Moore) Jack Emblow 1982

In Octave, how to load variable and value from txt file ?

First of all, thanks for helping me.
My question, lets say I have readme.txt file, and inside looks like below
a1 3
b2 4
c3 -2.3
d23 55.6
Now, how can I make a function to load this txt file, so that in the Octave, I will directly have
a1=3
b2=4
c3=-2.3
d23=55.6
Allow me say this again, DIRECTLY. Once I use this function "readFunction("readme.txt")", all those variables will be load, and ready to use.
I tried [name, num] = textread ("readme.txt", "%s %f"), "num" is the numbers, but I don't know how to convert the cell "name" to variable name. e.g it's wrong if I do char(name(1)) = b(1). (trying to do a1 = 3).
Or maybe my way is just completely wrong? Thanks for the help.
First, the idea:
Read line by line the file
Replace the space with and = symbol
Optionally add a ; symbol at the end of each line
eval the string.
Second, a simple code example:
filename="file.txt";
fid=fopen(filename);
line=fgetl(fid);
while line != -1
eval(strrep(line, ' ', '='));
line=fgetl(fid);
endwhile
fclose(fid);

Splitting CSV column data into new CSV file using VBScript

I have a CSV file where 2 columns contain several different text values e.g.
Column 1: Reptiles, Health, Hygiene
Column 2: Purity
I need to use VBscript to split these columns into a new CSV file without changing the current file, expected output in new CSV file shown below:
Column 1 Column 2
Reptiles Reptiles
Health Health
Hygiene Hygiene
Purity Purity
Unfortunately(?) it must be done with VB Script and nothing else.
Here is an example of how the data looks (of course the data consistently repeats with some extra entries through the same columns in file 1.
And here is an example of how it needs to look but it needs to repeat down until all unique entries from Column 1 and 2 in the original file have been input as a single entry to Column 1 in the new file and copied to Column 2 in the same new file. e.g.
Examples in text format as requested:
Original file:
Column 1,Column 2
"Reptiles, Health, Hygiene",Purity
New File:
Column 1,Column 2
Reptiles,Reptiles
Health,Health
Hygiene,Hygiene
Purity,Purity
I think this is a simple matter of using the FileSystemObject with Split function.
Assuming each input line is just one set of data you can remove the double quotes and process from there
Try this VB script out (edited to process header line separately):
Const Overwrite = True
Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set ObjOutFile = ObjFso.CreateTextFile("My New File Path", Overwrite)
Set ObjInFile = ObjFso.OpenTextFile("My Old File Path")
' Skip processing first header line and just write it out as is
strLine = ObjInFile.ReadLine
ObjOutFile.WriteLine strLine
Do Until ObjInFile.AtEndOfStream
' Remove all double quotes to treat this as one set of data
strLine = Replace(ObjInFile.ReadLine, """","")
varData = Split(strLine,",")
' Write out each element twice into its own line
For i = 0 to uBound(varData)
ObjOutFile.WriteLine varData(i) & "," & varData(i)
Next i
Loop
ObjInFile.Close
ObjOutFile.Close

Arrow Character Issue

I receive excel files in a specified folder for inventory upload. When these upload my system is throwing an error of invalid InventoryId. The last row of data comes with an arrow character that when copied and pasted shows a blank space.
Does anyone know what this right arrow character is?
It is not HTML, ASCII, or Unicode.
I need to create a validation on that character not to bring the row if this is present.
You could do something like the following to remove the Unicode characters.
Dim Str As String = "My Stȟring of ChaǕracters"
Str = System.Text.RegularExpressions.Regex.Replace(Str, "[^\u0000-\u007F]", "")
or if you wanted to identify Strings then do something
Dim Str As String = "My String of Characters"
Dim UniCodeCollection As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(Str, "[^\u0000-\u007F]")
If UniCodeCollection.Count > 0 Then
'Add code to do somthing here
End If
As the right-arrow character has been passed via a string, it must be a Unicode character.
If the program into which you paste the suspect character is not capable of displaying it, e.g. it is using a font without a visible representation of it, then it may well appear as a blank.
You need to track down what the code is for the character.
The character will probably be able to be shown in Visual Studio, so copy-and-paste the offending string in place of "Crème brûlée →" in the following code and examine the output for anything which stands out:
Module Module1
Sub Main()
Dim s = "Crème brûlée →"
For i = 0 To s.Length - 1
Console.WriteLine(AscW(s(i)))
Next
Console.ReadLine()
End Sub
End Module
Outputs:
67
114
232
109
101
32
98
114
251
108
233
101
32
8594
In the above, 8594 (which is &H2192) stands out as being very different. You now just need to check if s.IndexOf(ChrW(8594)) >= 0, which indicates that the character is in the string.
Solved the issue!
What I did was find what the Character was using the following code:
AscW(CurrentRecord(0).ToString) = Variable
Once I found what the character was I used the same line in an if statement to solve the issue. See Below.
If Not AscW(CurrentRecord(0).ToString) = "26" Then
If Not CurrentRecord(0).ToString = "InventoryId" Then
NewRow("InventoryId") = CurrentRecord(0)
NewRow("Quantity") = CurrentRecord(1)
NewRow("CostCentre") = CurrentRecord(2)
NewRow("UsageDate") = CurrentRecord(3)
InventoryLoad.Tables(0).Rows.Add(NewRow)
NewRow = InventoryLoad.Tables("Load").NewRow
End If
ElseIf AscW(CurrentRecord(0).ToString) = "26" Then
Else
CommonFunctions.ErrorEmail("ProductId " & CurrentRecord(0).ToString & " was not recognized", "LoadInventory - ProductId")
End If

AppleScript parse HTML

Goal: Long list of purchase orders that I need to refund if they contain the word "From:" and each purchase has a order number and I have been trying to parse or loop, not sure of right word Search HTML doc for instance of the word "From:" and if found, then get other number and print to a text file.
So far, I was able to learn, sort of how to use text item delimiters, but when I tried making it loop or repeat, I just got the same order number over and over. This is before even trying to implement the part that says IF order details include word "from" then get order number.
set astid to AppleScript's text item delimiters
set x to 2
set startHere to "p class=\"webOrderNumber\">"
set stopHere to "</p>"
set entireText to (do shell script "curl file:///Users/Michael/Desktop/StorePurchases.webarchive")
set AppleScript's text item delimiters to startHere
set blurb1 to text item x of entireText
repeat with i from 2 to (count of blurb1)
set thisItem to item i of blurb1
set AppleScript's text item delimiters to stopHere
set blurb2 to text item 1 of blurb1
set AppleScript's text item delimiters to astid
set writeFile to ((path to desktop as text) & "test_output") --
set writeData to blurb2
set success to appendDataToFile(writeData, writeFile)
end repeat
on appendDataToFile(myData, aFile)
set OA to (open for access aFile with write permission)
try
write (myData & (ASCII character 10)) as text to OA starting at eof
close access OA
return true
on error
try
close access OA
end try
return false
end try
end appendDataToFile
Here is an excerpt of the HTML:
</td>
<td class="OrderNumber">
<p class="webNumber">BHWL123456</p>
</p>
<td class="OrderNumber">
<p class="details">
Full Version: Get all Activities & Remove ads! [From: Pony Resort: MakeverMagic] </p>
</td>
This is going to be used when there are hundreds of orders that would take too long to physically search for the word FROM and write the order number.
Try:
set resultNumbers to {}
set myText to read file ((path to temporary items as text) & "test.txt") as «class utf8»
set {TID, text item delimiters} to {text item delimiters, "<p class=\"webNumber\">"}
set webOrderNumbers to text items 2 thru -1 of myText
set AppleScript's text item delimiters to "</p>"
repeat with wNumber in webOrderNumbers
set end of resultNumbers to text item 1 of wNumber
end repeat
set text item delimiters to TID
return resultNumbers
This question was asked and solved afaik on Macscripter.net with the use of a Applescript Script library and additional Applescript I provided in this thread.
The scripting library uses NSRegularExpresion to search between two text targets and return all occurrences in one go.
I can post the code here if anyone is interested or you can visit the thread.