diff --git a/README.md b/README.md index 1405a17..ae07ab5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # lob-python -[](https://travis-ci.org/lob/lob-python) -[](http://badge.fury.io/py/lob) [](https://pypi.python.org/pypi/lob/) -[](https://coveralls.io/r/lob/lob-python?branch=master) +[](https://travis-ci.org/lob/lob-python) +[](http://badge.fury.io/py/lob) [](https://pypi.python.org/pypi/lob/) +[](https://coveralls.io/r/lob/lob-python?branch=master) [](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..48a2877 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,6 +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 + +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 new file mode 100644 index 0000000..4a3d0ef --- /dev/null +++ b/examples/csv_postcards/create_postcards.py @@ -0,0 +1,48 @@ +import lob +import csv +import sys + +lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc' + +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..418bd69 --- /dev/null +++ b/examples/csv_postcards/postcard_back.html @@ -0,0 +1,41 @@ + +
+