Skip to content

Commit

Permalink
List of cocktails
Browse files Browse the repository at this point in the history
A csv file with ingredients
a script to convert csv to json
(the generated file is in ...\frontend\static\cocktail_22.json )
  • Loading branch information
romainGuiet committed Feb 10, 2018
1 parent a56db42 commit e2fcc78
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cocktails_list/cocktails.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Name;shaker;Whisky;Gin;Rhum blanc;Rhum Ambr�;Vodka;Tequila;Cura�ao bleu;Cointreau;Martini;Ananas;Lait de Coco;Passion;Orange;Citron Vert;Citron;Cranberry;Coca;Perrier;Tonic;melon;Grenadine;canne;orgeat;;Angostura bitters
pina colada;x;;;4;2;;;;;;12;4;;;;;;;;;;;;;;
margarita;x;;;;;;5;;3;;;;;;2;;;;;;;;;;;
cosmopolitan;x;;;;;4;;;2;;;;;;1;;2;;;;;;;;;
Blue Lagon;x;;;;;4;;3;;;;;;;;2;;;;;;;;;;
Tequila Sunrise;;;;;;;6;;;;;;;12;;;;;;;;2;;;;
Cuba Libre;;;;;6;;;;;;;;;;4;;;15;;;;;;;;
Daiquiri;x;;;4;;;;;;;;;;;2;;;;;;;;1;;;
Gin Fizz;x;;6;;;;;;;;;;;;4;;;;12;;;;2;;;
Zombie;x;;;3;3;;;;;;6;;;;2;;;;;;;0.5;1.5;;;
Ti-Punch;;;;6;;;;;;;;;;;;;;;;;;;2;;;
Long island Iced Tea;x;;1.5;1.5;;1.5;1.5;;1.5;;;;;;;1;;3;;;;;;;;
Aphrodisiaque;x;;2;;;;;;2;;;;;;;;;;;;;;;;;
Blue Hawaiian;x;;;4;;;;2;;;8;4;;;;;;;;;;;;;;
Mai Tai;x;;;3;3;;;;3;;;;;;3;;;;;;;;1;1;;
Dry Martini;;;5;;;;;;;1;;;;;;;;;;;;;;;;
Gin Tonic;;;3;;;;;;;;;;;;;;;;;6;;;;;;
Cocaine Liquide;;;;;;2;2;2;;;;;;;;;;;;;;;;;;
Planter-s Punch;;;;;6;;;;;;;;;2;;2;;;;;;1;;;;
Rainbow Shot the Sheriff;x;;;;;3;;2;;;;;;10;;;;;;;;3;;;;
kamikaze;;;;;;2;;;2;;;;;2;;;;;;;;;;;;
Aquarium;;;;4;;;4;4;;4;;;;;;;;;;;;;4;;;
Hurricane;;;;3;3;;;;;;;;1;;1.5;;;;;;;;;;;
94 changes: 94 additions & 0 deletions cocktails_list/csv_to_json.ijm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* This script runs in ImageJ (https://imagej.nih.gov/ij/index.html)
*
* Asks you a csv,
* re-print it within the imagej log to a json 'like' format
* compatible with our application for bar-o-matic
*
* NB : you will have to modify ' by " ( with a text editor, ie NOTEPAD++ )
*
* NB : check the columnSperator (either ; or , )
*
*/

print ("\\Clear")

path = File.openDialog("Select a csv file")
columnSperator = ";" ; // depending of regional parameter can be ","


// open the selected file as a string
file = File.openAsString(path)
// slipt the lines
lines=split(file,"\n")
// first line corresponds to colums name
columnName = split(lines[0],columnSperator);

print ("{");
print ("'recipes': [");

// iterates the rows of the csv file
for (i_Line = 1 ; i_Line < lengthOf(lines) ; i_Line++){

currentColumns=split(lines[i_Line],columnSperator);
print ("{");
print ("'name':'"+currentColumns[0]+"',");
print ("'description':'',");
print ("'imageUrl':'',");

if (currentColumns[1]=="x") print("'shakeYourBody': true,");
else print("'shakeYourBody': false,");

print ("'items': [");
// count the nbr of ingredients
// to write the last ingredient in the list without ","
ingredient_counter = 0;
for (i_Col = 2 ; i_Col<lengthOf(currentColumns) ;i_Col++){
if ( !isNaN(currentColumns[i_Col])) ingredient_counter++;
}

// now writes each entry
ingredient_total = ingredient_counter;
ingredient_counter = 0;
for (i_Col = 2 ; i_Col<lengthOf(currentColumns) ;i_Col++){
if ( !isNaN(currentColumns[i_Col])){
ingredient_counter++;
print ("{");
print("'ingredientId':'"+(i_Col-1)+"',");
print("'ml':"+ (parseInt(currentColumns[i_Col])*10));

// the last print should be without ,
if (ingredient_counter < ingredient_total) print ("},");
else print ("}");
}
}
// close recipe
print ("]");

// last or next recipe
if (i_Line < lengthOf(lines)-1) print ("},");
else print ("}");
}
// close recipes list
print ("],");

// start ingredient
print ("'ingredients': [");

for (i_Col = 2 ; i_Col<lengthOf(columnName) ;i_Col++){

print ("{");
print("'id':"+(i_Col-1)+",");
print("'name':'"+columnName[i_Col]+"',");
print("'type': 'TBD',");
print("'manual': false,");
print("'color': 'TBD'");

// next ingredient or last one
if (i_Col < lengthOf(columnName)-1) print ("},");
else print ("}");
}
// close ingredient list
print ("]");
// end of document
print ("}");
2 changes: 2 additions & 0 deletions cocktails_list/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A first list of cocktails was established from recipe on 1001cocktails.com
http://www.1001cocktails.com/cocktails/recettes-popularite-0.html

0 comments on commit e2fcc78

Please sign in to comment.