Create String from CSV Lookup with AppleScript - csv

I am trying to create an applescript that will create a string out of a CSV file. It is very easy to create the string of the entire file, but I'd like to be able to scan the file for a certain organization. Below is my input and desired output.
My CSV:
Org1 Bobby Bob bobbybob#gmail.com
Org1 Wendy Wen wendywen#gmail.com
Org1 Rachel Rach rachelrach#gmail.com
Org2 Timmy Tim ttim#otheremail.com
Org2 Ronny Ron rron#otheremail.com
Org2 Mike Mik mmik#otheremail.com
My AppleScript:
set csv to read csv_input_file as «class utf8»
set text item delimiters to ","
set csvParagraphs to paragraphs of csv
repeat with current_line in paragraphs of csv
set organization to text item 1 of current_line
--THIS IS WHERE I NEED HELP
set others_in_organization to ...
end repeat
Desired Output:
I would like to create a new string that contains a comma separated list of all of the other people in the current organization. For example, the fourth entry's organization is "Org2". So the string would return "Timmy Tim, Ronny Ron, Mike Mik".
Any help would be great! Thank you!

Try this...
set myOrg to "Org1"
set otherPeople to ""
set csv to "Org1,Bobby Bob,bobbybob#gmail.com
Org1,Wendy Wen,wendywen#gmail.com
Org1,Rachel Rach,rachelrach#gmail.com
Org2,Timmy Tim,ttim#otheremail.com
Org2,Ronny Ron,rron#otheremail.com
Org2,Mike Mik,mmik#otheremail.com"
set text item delimiters to ","
repeat with aLine in paragraphs of csv
set textItems to text items of aLine
if item 1 of textItems is not myOrg then
set otherPeople to otherPeople & item 2 of textItems & ", "
end if
end repeat
set text item delimiters to ""
if otherPeople ends with ", " then
set otherPeople to text 1 thru -3 of otherPeople
end if
return otherPeople

Related

SSRS adding extra characters when exporting to CSV

I am creating an expression combining multiple fields into a single field in SSRS. However when I am exporting to CSV, some of the records are being appended with additional double quotes. How do I fix this?
Original Data:
SCode|BuildingNumber|StreetName|City|State|
---------------------------------------------
ABC| |123 Street|New York |NY|
DEF| |456 Street|Los Angeles|CA|
IJK|123|7th Ave |Chicago |IL|
XYZ| |789 Cir |Atlanta |GA|
Expression I am using:
=Fields!SCode.Value & "#" & IIF(IsNothing(Fields!BuildingNumber.Value), Fields!StreetName.Value, Fields!BuildingNumber.Value & "\," & Fields!StreetName.Value) & "#" & Fields!City.Value & "#" & Fields!State.Value"
Data after exporting to CSV:
ABC#123 Street#New York#NY
DEF#456 Street#Los Angeles#CA
"IJK#123, 7th Ave#Chicago#IL"
XYZ#789 Cir#Atlanta#GA
Thanks!
The CSV export should only be adding the text delimiter around a field if there's a delimiter character (a comma) or some sort of return charter.
Text qualifiers are added only when the value contains the delimiter
character or when the value has a line break.
MS Docs
Check you text for commas, return characters, and line feeds.
Your examples don't have a comma but it may still have a return or line feed.
SELECT *
FROM TABLE
WHERE FIELD LIKE '%' + CHAR(13) + '%'
OR FIELD LIKE '%' + CHAR(10) + '%'
The line feed and return characters are character numbers 10 and 13 in ASCII.

colnames() in 2 line / set a table with 2 line header

I have a data frame, assuming as below, and I want to see two line in the header.
head(iris)
colnames(iris) <- c("Sepal.Length", "Sepal.Width", "Petal.Length","Petal.Width", " This is Species but I want to assign here 2 line very long name ")
head(iris)
many thanks in advance,

How can I parse multiple entire lines of text into octave 'matrix'

I want to import a lot of data from multiple files from multiple sub files. Luckily the data is consistent in its output:
Subpro1/data apples 1
Subpro1/data oranges 1
Subpro1/data banana 1
then
Subpro2/data apples 1
Subpro2/data oranges 1
Subpro2/data banana 1
I want to have a a datafilename array that holds the file names for each set of data I need to read. Then I can extract and store the data in a more local file, process it and eventually compare 'sub1_apples' to 'sub2_apples'
I have tried
fid = fopen ("DataFileNames.txt");
DataFileNames = fgets (fid)
fclose (fid);
But this only gives me the first line of 7.
DataFileNames = dlmread('DataFileNames.txt') gives me a 7x3 array but only 0 0 1 in each line as it reads the name breaks as delimiters and I cant change the file names.
DataFileNames = textread("DataFileNames.txt", '%s')
has all the correct information but still the delimiters split it across multiple lines
data
apples
1
data
oranges
1
...
Is there a %? that I am missing, if so what is it?
I want the output to be:
data apples 1
data oranges 1
data banana 1
With spaces, underscores and everything included so that I can then use this to access the data file.
You can read all lines of the file to a cell array like this:
str = fileread("DataFileNames.txt");
DataFileNames = regexp(str, '\r\n|\r|\n', 'split');
Output:
DataFileNames =
{
[1,1] = data apples 1
[1,2] = data oranges 1
[1,3] = data banana 1
}
In the first option you tried, using fgets you are reading just one line. Also, its better to use fgetl to remove the line end. To read line by line (which is longer) you need to do:
DataFileNames = {};
fid = fopen ("DataFileNames.txt");
line = fgetl(fid);
while ischar(line)
if ~isempty(line)
DataFileNames = [DataFileNames line];
endif
line = fgetl(fid);
endwhile
fclose (fid);
The second option you tried, using dlmread is not good because it is intended for reading numeric data to a matrix.
The third option you tried with textread, is not so good because it treats all white spaces (spaces, line-ends, ...) equally

Extract json data string with applescript

I have almost the same problem.
I'm using the following syntax:
set LINK to ("https://XXXXXXXXXXXXXXXXXXXX.com")
set api to ("XXXXXXXXXXXX")
set secret to ("XXXXXXXXXXX")
set RR to do shell script "curl -u '" & api & ":" & secret & "' https:/XXXXXXXurl='" & LINK & "'"
tell application "JSON Helper"
set RRR to (read JSON from RR)
end tell
and I get this :
{results:{{tagging_id:missing value,
image:"https://XXXXXXXXXXXXXXXXX.com",
tags:{{tag:"symbol", confidence:26.962820053101}, {tag:"art",
confidence:26.631685256958}, {tag:"graphic",
confidence:26.29425239563}, {tag:"design",
confidence:25.914730072022}, {tag:"icon", confidence:21.400810241699},
{tag:"cartoon", confidence:20.534477233887}, {tag:"drawing",
confidence:18.931232452393}, {tag:"decoration",
confidence:18.834970474243}, {tag:"silhouette",
confidence:17.404066085815}, {tag:"shape",
confidence:14.910034179688}, {tag:"element",
confidence:14.898452758789}, {tag:"sign", confidence:14.306094169617},
{tag:"ornament", confidence:13.806978225708}, {tag:"human",
confidence:13.510297775269}, {tag:"black",
confidence:13.444707870483}, {tag:"logo", confidence:13.409428596497},
{tag:"pattern", confidence:13.006916999817}, {tag:"retro",
confidence:12.30048751831}, {tag:"star", confidence:11.705702781677},
{tag:"color", confidence:11.694045066834}, {tag:"card",
confidence:11.57892036438}, {tag:"gold", confidence:11.519770622253},
{tag:"banner", confidence:11.03851890564}, {tag:"heat",
confidence:10.58930683136}, {tag:"blaze", confidence:10.454214096069},
{tag:"circle", confidence:10.329438209534}, {tag:"power",
confidence:10.084959030151}, {tag:"decorative",
confidence:10.032000541687}, {tag:"bright",
confidence:10.019249916077}, {tag:"orange", confidence:9.9829454422},
{tag:"concepts", confidence:9.782785415649}, {tag:"style",
confidence:9.65638256073}, {tag:"outline", confidence:9.480903625488},
{tag:"character", confidence:9.435729026794}, {tag:"floral",
confidence:9.367718696594}, {tag:"flower", confidence:9.236577987671},
{tag:"heraldry", confidence:9.019858360291}, {tag:"curve",
confidence:8.756514549255}, {tag:"love", confidence:8.692363739014},
{tag:"colorful", confidence:8.608165740967}, {tag:"leaf",
confidence:8.568987846375}, {tag:"3d", confidence:8.527961730957},
{tag:"fire", confidence:8.443150520325}, {tag:"hand",
confidence:8.4037733078}, {tag:"clip art", confidence:8.348271369934},
{tag:"heart", confidence:8.291186332703}, {tag:"backdrop",
confidence:8.250628471375}, {tag:"figure", confidence:8.186657905579},
{tag:"person", confidence:8.040968894958}, {tag:"yellow",
confidence:7.957674980164}, {tag:"colors", confidence:7.941210269928},
{tag:"frame", confidence:7.811089992523}, {tag:"golden",
confidence:7.745839118958}, {tag:"wallpaper",
confidence:7.666860580444}, {tag:"head", confidence:7.567168235779},
{tag:"paisley", confidence:7.478963375092}, {tag:"vintage",
confidence:7.451002120972}, {tag:"light", confidence:7.361023902893},
{tag:"ornate", confidence:7.328865528107}, {tag:"fantasy",
confidence:7.22393655777}, {tag:"cute", confidence:7.183915138245},
{tag:"holiday", confidence:7.175530433655}, {tag:"science",
confidence:7.122048377991}, {tag:"animal", confidence:7.087336540222},
{tag:"spring", confidence:7.072511672974}, {tag:"medical",
confidence:7.06857919693}}}}}
My problem is : I'm a newbie and I just want to get tags that have a confidence greater than 12. I would like to get something like this :
symbol,art,graphic,design,icon,cartoon,drawing,decoration,[...]retro
What should I add at the end of my syntax ?
Thx for your help!
Please try this, I added comments to the lines, the result is in the variable filteredTags which is a list of strings.
set resultDict to {results:{{tagging_id:missing value, image:"https://XXXXXXXXXXXXXXXXX.com", tags:{{tag:"symbol", confidence:26.962820053101}, {tag:"art", confidence:26.631685256958}, {tag:"graphic", confidence:26.29425239563}, {tag:"design", confidence:25.914730072022}, {tag:"icon", confidence:21.400810241699}, {tag:"cartoon", confidence:20.534477233887}, {tag:"drawing", confidence:18.931232452393}, {tag:"decoration", confidence:18.834970474243}, {tag:"silhouette", confidence:17.404066085815}, {tag:"shape", confidence:14.910034179688}, {tag:"element", confidence:14.898452758789}, {tag:"sign", confidence:14.306094169617}, {tag:"ornament", confidence:13.806978225708}, {tag:"human", confidence:13.510297775269}, {tag:"black", confidence:13.444707870483}, {tag:"logo", confidence:13.409428596497}, {tag:"pattern", confidence:13.006916999817}, {tag:"retro", confidence:12.30048751831}, {tag:"star", confidence:11.705702781677}, {tag:"color", confidence:11.694045066834}, {tag:"card", confidence:11.57892036438}, {tag:"gold", confidence:11.519770622253}, {tag:"banner", confidence:11.03851890564}, {tag:"heat", confidence:10.58930683136}, {tag:"blaze", confidence:10.454214096069}, {tag:"circle", confidence:10.329438209534}, {tag:"power", confidence:10.084959030151}, {tag:"decorative", confidence:10.032000541687}, {tag:"bright", confidence:10.019249916077}, {tag:"orange", confidence:9.9829454422}, {tag:"concepts", confidence:9.782785415649}, {tag:"style", confidence:9.65638256073}, {tag:"outline", confidence:9.480903625488}, {tag:"character", confidence:9.435729026794}, {tag:"floral", confidence:9.367718696594}, {tag:"flower", confidence:9.236577987671}, {tag:"heraldry", confidence:9.019858360291}, {tag:"curve", confidence:8.756514549255}, {tag:"love", confidence:8.692363739014}, {tag:"colorful", confidence:8.608165740967}, {tag:"leaf", confidence:8.568987846375}, {tag:"3d", confidence:8.527961730957}, {tag:"fire", confidence:8.443150520325}, {tag:"hand", confidence:8.4037733078}, {tag:"clip art", confidence:8.348271369934}, {tag:"heart", confidence:8.291186332703}, {tag:"backdrop", confidence:8.250628471375}, {tag:"figure", confidence:8.186657905579}, {tag:"person", confidence:8.040968894958}, {tag:"yellow", confidence:7.957674980164}, {tag:"colors", confidence:7.941210269928}, {tag:"frame", confidence:7.811089992523}, {tag:"golden", confidence:7.745839118958}, {tag:"wallpaper", confidence:7.666860580444}, {tag:"head", confidence:7.567168235779}, {tag:"paisley", confidence:7.478963375092}, {tag:"vintage", confidence:7.451002120972}, {tag:"light", confidence:7.361023902893}, {tag:"ornate", confidence:7.328865528107}, {tag:"fantasy", confidence:7.22393655777}, {tag:"cute", confidence:7.183915138245}, {tag:"holiday", confidence:7.175530433655}, {tag:"science", confidence:7.122048377991}, {tag:"animal", confidence:7.087336540222}, {tag:"spring", confidence:7.072511672974}, {tag:"medical", confidence:7.06857919693}}}}}
-- get the value for key `results`
set theResults to resultDict's results
-- check if the array is not empty
if (count theResults) = 0 then return
-- get the value for key `tags` of the first item of `theResults`
set theTags to theResults's first item's tags
-- create the list for the result
set filteredTags to {}
-- in the repeat loop get the value for key `confidence` and
-- add the tag to the result list if the value > 12
repeat with aTag in theTags
if aTag's confidence > 12.0 then set end of filteredTags to aTag's tag
end repeat

how to store text containing escape sequences in ms access

When i try to store text containing 'C' code in MS ACCESS table (programatically). It replaces escape sequences ('\n', '\t') with some question-mark symbol.
Example :
code to store :
#include<stdio.h>
int main()
{
printf("\n\n\t Hi there...");
return 0;
}
When i see MS-Access table for above inserted code it shows every newline and '\t' character replaced with a '?' kind of symbol.
My question "is there any other data type for MS-Access filed which stores code as it is without replacing escape sequences with some symbol?"
and
"Is 'raw' data type present in other DBMS like MYSQL will do my job? "
This is how it shows in access-07 :
It looks like the line breaks in your source text are not the Windows-standard CRLF (carriage return, line feed). Find out the character codes of those mystery characters.
Using the procedure below, I can feed it a text string, and it will list the code of each character. Here is an example from the Immediate window.
AsciiValues "a" & vbcrlf & "b"
position Asc AscW
1 97 97
2 13 13
3 10 10
4 98 98
If I want to examine the value stored in a table text field, I can use DLookup to fetch that value and feed it to the function.
AsciiValues DLookup("memo_field", "tblFoo", "id=1")
position Asc AscW
1 108 108
2 105 105
3 110 110
4 101 101
5 32 32
Once you determine the codes of the problem characters, you can execute an UPDATE statement to replace the problem character codes with suitable alternatives.
UPDATE YourTable
SET YourField = Replace(YourField, Chr(x), Chr(y));
And this is the procedure ...
Public Sub AsciiValues(ByVal pInput As String)
Dim i As Long
Dim lngSize As Long
lngSize = Len(pInput)
Debug.Print "position", "Asc", "AscW"
For i = 1 To lngSize
Debug.Print i, Asc(Mid(pInput, i, 1)), AscW(Mid(pInput, i, 1))
Next
End Sub
I'd say it's probably that you're lacking the whole newline. A newline in Access consists of a Carriage Return (ASCII 13) AND a Line Feed (ASCII 10). This is abbreviated as CRLF. You probably only have one or the other, but not both.
Use HansUp's AsciiValues procedure to take a look.