Skip to content

Instantly share code, notes, and snippets.

@gwpl
Created October 12, 2016 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/2cce1cdb9a22927df9d04903d1638e8f to your computer and use it in GitHub Desktop.
Save gwpl/2cce1cdb9a22927df9d04903d1638e8f to your computer and use it in GitHub Desktop.
glabels-3-fetch_and_print.sh # wrapper around https://github.com/barcode-utils/glabels-3-templates fetching from given google_spreadsheets sheet
#!/bin/bash
# Usage:
# optionally you can provide .csv file as parameter
# if GLABELS3TEMPLATESDIR= is pointing to directory with glabels-3-templates, then it's copied from there
orig_dir="$PWD"
tmpdir="$(mktemp -d)"
if [ -r "$1" ]; then
cp -v "$1" "$tmpdir"/57x32.csv
fi
cd "$tmpdir" || exit
echo 'Currently only supporting 57x32 stickers sheet'
echo 'and hard coded two templates: code128title2L57x32.glabels and code128title57x32.glabels'
if [ ! -r "57x32.csv" ]; then
curl -o '57x32.csv' 'https://docs.google.com/spreadsheets/d/HERE_YOUR_GOOGLE_SPREADHEET_SHEET_URL_PUBLISHED_TO_PUBLIC_WITH_FORMAT_CSV/pub?gid=757693982&single=true&output=csv'
fi
function csvgrep(){
grep_criteria="$1"
matchcolumn="$2"
python2 -c "import csv, sys
rows = list(csv.reader(sys.stdin))
writer = csv.writer(sys.stdout)
writer.writerow(rows[0])
for row in rows[1:]:
if row[${matchcolumn}] == '${grep_criteria}':
writer.writerow(row)"
}
csvgrep 'code128title2L57x32' '-1' < 57x32.csv > code128title2L57x32_2print.csv
csvgrep 'code128title57x32' '-1' < 57x32.csv > code128title57x32_2print.csv
if [ -d "$GLABELS3TEMPLATESDIR" ]; then
mkdir glabels-3-templates
cp -v "$GLABELS3TEMPLATESDIR"/*.glabels glabels-3-templates
cp -v "$GLABELS3TEMPLATESDIR"/Makefile glabels-3-templates
else
git clone 'https://github.com/barcode-utils/glabels-3-templates.git'
fi
cp code128title2L57x32_2print.csv glabels-3-templates
cp code128title57x32_2print.csv glabels-3-templates
cd glabels-3-templates
make code128title2L57x32_2print.pdf code128title57x32_2print.pdf
cp -iv code128title2L57x32_2print.pdf "$orig_dir"
cp -iv code128title57x32_2print.pdf "$orig_dir"
cd "$orig_dir"
set -x
rm -rf "$tmpdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment