Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
griffithben committed Oct 31, 2014
0 parents commit 5f22d48
Show file tree
Hide file tree
Showing 9 changed files with 6,697 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Styles
The style repository that can be found at brewerwall.com/api/v1/styles. Feel free to fork and use however. If you see a mistake or would like to add any missing styles, submit a pull request with the modifications/additions.

## Updating Styles
If you would like to update styles, update `styles_master.json`. Once the file has been updated run:
```bash
./generate
```

This command will generate a CSV and MYSQL file, along with copying over the master JSON file to another json file. This is merely a bash script that calls a php file, so you must have php available.
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"data":"styles"
}
Binary file added formats/.DS_Store
Binary file not shown.
142 changes: 142 additions & 0 deletions formats/styles.csv

Large diffs are not rendered by default.

3,176 changes: 3,176 additions & 0 deletions formats/styles.json

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions formats/styles.mysql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions generate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
php lib/generate_formats.php
46 changes: 46 additions & 0 deletions lib/generate_formats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

//CONFIG
$config = json_decode(file_get_contents("config.json"), true);

// SCRIPTS VARS
$master_file = $config['data']."_master.json";
$json = file_get_contents($master_file);
$array = json_decode($json, true);

// CONVERT MASTER FILE TO CSV
$f_csv = fopen('formats/'.$config['data'].'.csv', 'w');

$keys_set = false;
foreach ($array as $line){
if(!$keys_set){
fputcsv($f_csv, array_keys($line));
$keys_set = true;
}
fputcsv($f_csv, $line);
}

//CONVERT MASTER FILE TO MYSQL INSERT STATEMENTS
$f_mysql = fopen('formats/'.$config['data'].'.mysql', 'w');

$keys_set = false;
foreach ($array as $line){
if(!$keys_set){
fwrite($f_mysql, "INSERT INTO ".$config['data']." (".implode(',',array_keys($line)).")\nVALUES\n");
$keys_set = true;
}

//Wrap strings in quotes.
$line = array_map(function($obj){
if(!is_numeric($obj))
return "'".addslashes($obj)."'";
else
return $obj;
}, $line);

$insert_values[] = "(".implode(',',$line).")";
}
fwrite($f_mysql, implode(",\n", $insert_values));

// COPY MASTER FILE TO FORMATS
copy($master_file, "formats/".$config['data'].".json");
3,176 changes: 3,176 additions & 0 deletions styles_master.json

Large diffs are not rendered by default.

0 comments on commit 5f22d48

Please sign in to comment.