From d48f1286f207c9decf7ff0bdf93c025878385855 Mon Sep 17 00:00:00 2001 From: Peter Nagel Date: Fri, 8 May 2015 09:15:58 -0700 Subject: [PATCH 1/5] added HTML, csv example --- examples/csv_postcards/create_postcards.py | 50 ++++++++++++++++++++++ examples/csv_postcards/input.csv | 7 +++ examples/csv_postcards/postcard_back.html | 40 +++++++++++++++++ examples/csv_postcards/postcard_front.html | 27 ++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 examples/csv_postcards/create_postcards.py create mode 100644 examples/csv_postcards/input.csv create mode 100644 examples/csv_postcards/postcard_back.html create mode 100644 examples/csv_postcards/postcard_front.html diff --git a/examples/csv_postcards/create_postcards.py b/examples/csv_postcards/create_postcards.py new file mode 100644 index 0000000..d1fa217 --- /dev/null +++ b/examples/csv_postcards/create_postcards.py @@ -0,0 +1,50 @@ +import lob +import csv +import sys + +lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc' + +skipFirstLine = True + +try: + sys.argv[1] +except IndexError: + print "Please provide an input CSV file as an argument." + sys.exit() + +with open('postcard_front.html', 'r') as frontHtmlFile: + frontHtml = frontHtmlFile.read() + with open('postcard_back.html', 'r') as backHtmlFile: + backHtml = backHtmlFile.read() + with open(sys.argv[1]) as f: + for row in csv.reader(f): + postcard = lob.Postcard.create( + to_address = { + 'name': row[5], + 'address_line1': row[6], + 'address_line2': row[7], + 'address_city': row[8], + 'address_state': row[9], + 'address_zip': row[10], + 'address_country': row[11] + }, + from_address = { + 'name': 'Lob', + 'address_line1': '123 Main Street', + 'address_city': 'San Francisco', + 'address_state': 'CA', + 'address_zip': '94185', + 'address_country': 'US' + }, + setting = 1002, + front = frontHtml, + back = backHtml, + data = { + 'background_image': row[1], + 'background_color': row[2], + 'name': row[0], + 'car': row[3], + 'mileage': row[4] + } + ) + print postcard.url diff --git a/examples/csv_postcards/input.csv b/examples/csv_postcards/input.csv new file mode 100644 index 0000000..bd64a5d --- /dev/null +++ b/examples/csv_postcards/input.csv @@ -0,0 +1,7 @@ +Peter,https://s3-us-west-2.amazonaws.com/lob-assets/df-car2.jpg,LightBlue,Jeep Wrangler,65000,Peter,123 Main Street,Apt. 101,San Francisco,CA,94107,US +Marcus,https://s3-us-west-2.amazonaws.com/lob-assets/df-car.jpg,Bisque,Honda Pilot,65000,Marcus,456 Oak Street ,Apt. 102,San Francisco,CA,94185,US +Leore,https://s3-us-west-2.amazonaws.com/lob-assets/df-car2.jpg,PaleGreen,Jeep Wrangler,50000,Leore,123 Test Street,Apt. 101,San Francisco,CA,94105,US +Harry,https://s3-us-west-2.amazonaws.com/lob-assets/df-car.jpg,Thistle,Jeep Wrangler,50000,Harry,789 Elm Street,Apt. 101,San Francisco,CA,94107,US +Elnaz,https://s3-us-west-2.amazonaws.com/lob-assets/df-car2.jpg,PaleTurqoise,Jeep Wrangler,35000,Elnaz,111 Washington Street,Apt. 101,San Francisco,CA,94112,US +Robin,https://s3-us-west-2.amazonaws.com/lob-assets/df-car.jpg,Wheat,Jeep Wrangler,35000,Robin,888 Jefferson Street,Apt. 101,San Francisco,CA,94197,US +Russell,https://s3-us-west-2.amazonaws.com/lob-assets/df-car2.jpg,WhiteSmoke,Jeep Wrangler,15000,Russell,1212 Fourth Street,Apt. 101,San Francisco,CA,94166,US diff --git a/examples/csv_postcards/postcard_back.html b/examples/csv_postcards/postcard_back.html new file mode 100644 index 0000000..453ab33 --- /dev/null +++ b/examples/csv_postcards/postcard_back.html @@ -0,0 +1,40 @@ + + +Lob.com Sample 6x11 Postcard Back Template 1 + + + + +
+ Hey {{name}},

+ Your {{car}} is due for its {{mileage}} mile service. Schedule an appointment today!

+ Make sure to bring this card to receive great savings!

+
+ diff --git a/examples/csv_postcards/postcard_front.html b/examples/csv_postcards/postcard_front.html new file mode 100644 index 0000000..d023805 --- /dev/null +++ b/examples/csv_postcards/postcard_front.html @@ -0,0 +1,27 @@ + + + Lob.com Sample 6x11 Postcard Front + + + + + + From 13ce9c4052ea5b8b6c8dfd7a55cd9dd8c8ae6d42 Mon Sep 17 00:00:00 2001 From: Peter Nagel Date: Fri, 8 May 2015 09:54:51 -0700 Subject: [PATCH 2/5] updated readme with examples --- README.md | 11 ++++++++--- examples/README.md | 4 ++++ examples/csv_postcards/create_postcards.py | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1405a17..ae07ab5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # lob-python -[![Build Status](https://travis-ci.org/lob/lob-python.svg?branch=master)](https://travis-ci.org/lob/lob-python) -[![PyPI version](https://badge.fury.io/py/lob.svg)](http://badge.fury.io/py/lob) [![Downloads](https://pypip.in/download/lob/badge.svg)](https://pypi.python.org/pypi/lob/) -[![Coverage Status](https://coveralls.io/repos/lob/lob-python/badge.svg?branch=master)](https://coveralls.io/r/lob/lob-python?branch=master) +[![Build Status](https://travis-ci.org/lob/lob-python.svg?branch=master)](https://travis-ci.org/lob/lob-python) +[![PyPI version](https://badge.fury.io/py/lob.svg)](http://badge.fury.io/py/lob) [![Downloads](https://pypip.in/download/lob/badge.svg)](https://pypi.python.org/pypi/lob/) +[![Coverage Status](https://coveralls.io/repos/lob/lob-python/badge.svg?branch=master)](https://coveralls.io/r/lob/lob-python?branch=master) [![Dependency Status](https://gemnasium.com/lob/lob-python.svg)](https://gemnasium.com/lob/lob-python) This is the python wrapper for the Lob.com API. See full Lob.com documentation [here](https://lob.com/docs/python). @@ -64,6 +64,11 @@ We've provided an example script you can run in examples/ that has examples of h We've provided various examples for you to try out [here](https://github.com/lob/lob-python/tree/master/examples). +There are simple scripts to demonstrate how to create all the core Lob objects (checks, letters, postcards. etc.) As well as more complex examples that utilize other libraries and external files: + +- [Verifying Addresses in a CSV](https://github.com/lob/lob-python/tree/master/examples/csv_address_verification) +- [Creating Dynamic Postcards with HTML and Data](https://github.com/lob/lob-python/tree/master/examples/csv_postcards) + ## API Documentation - [Introduction](https://lob.com/docs/python#introduction) diff --git a/examples/README.md b/examples/README.md index bbf1bef..15cf44e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,3 +6,7 @@ Here we have put together a hand full of python examples to help get you started ## /csv_address_verification/ An example showing how to validate and cleanse a CSV spreadsheet full of shipping addresses using Lob's [Address Verifcation API](https://lob.com/verification/address). + +## /csv_postcards/ + +An example showing how to dynamically create postcards from a CSV using HTML, a custom font, variable data, and Lob's [Postcard API](https://lob.com/services/postcards). diff --git a/examples/csv_postcards/create_postcards.py b/examples/csv_postcards/create_postcards.py index d1fa217..42629da 100644 --- a/examples/csv_postcards/create_postcards.py +++ b/examples/csv_postcards/create_postcards.py @@ -7,10 +7,10 @@ skipFirstLine = True try: - sys.argv[1] + sys.argv[1] except IndexError: - print "Please provide an input CSV file as an argument." - sys.exit() + print "Please provide an input CSV file as an argument." + sys.exit() with open('postcard_front.html', 'r') as frontHtmlFile: frontHtml = frontHtmlFile.read() From 1bd08156060e06f7df4253d29c7da9cd2dd62fdf Mon Sep 17 00:00:00 2001 From: Peter Nagel Date: Fri, 8 May 2015 10:38:25 -0700 Subject: [PATCH 3/5] Update create_postcards.py --- examples/csv_postcards/create_postcards.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/csv_postcards/create_postcards.py b/examples/csv_postcards/create_postcards.py index 42629da..4a3d0ef 100644 --- a/examples/csv_postcards/create_postcards.py +++ b/examples/csv_postcards/create_postcards.py @@ -4,8 +4,6 @@ lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc' -skipFirstLine = True - try: sys.argv[1] except IndexError: From 0ec2719e3d053f27cabbd95e5b2b9bd2f9a0ace7 Mon Sep 17 00:00:00 2001 From: Peter Nagel Date: Fri, 8 May 2015 10:49:00 -0700 Subject: [PATCH 4/5] Update postcard_back.html --- examples/csv_postcards/postcard_back.html | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/csv_postcards/postcard_back.html b/examples/csv_postcards/postcard_back.html index 453ab33..418bd69 100644 --- a/examples/csv_postcards/postcard_back.html +++ b/examples/csv_postcards/postcard_back.html @@ -37,4 +37,5 @@ Your {{car}} is due for its {{mileage}} mile service. Schedule an appointment today!

Make sure to bring this card to receive great savings!

+ From 7a9fa7ccb2cb8202d73eae12b146af3a10733860 Mon Sep 17 00:00:00 2001 From: Peter Nagel Date: Fri, 8 May 2015 12:18:34 -0700 Subject: [PATCH 5/5] Update README.md --- examples/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/README.md b/examples/README.md index 15cf44e..48a2877 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,10 +3,10 @@ Here we have put together a hand full of python examples to help get you started. As always feel free to [contact us](https://lob.com/support) directly if you have any questions on implementation. -## /csv_address_verification/ +## csv_address_verification An example showing how to validate and cleanse a CSV spreadsheet full of shipping addresses using Lob's [Address Verifcation API](https://lob.com/verification/address). -## /csv_postcards/ +## csv_postcards An example showing how to dynamically create postcards from a CSV using HTML, a custom font, variable data, and Lob's [Postcard API](https://lob.com/services/postcards).