From 350597a7fe2fe8de3e250004a53e1b3e6a07f811 Mon Sep 17 00:00:00 2001 From: dmlittle Date: Fri, 5 Jun 2015 11:27:24 -0700 Subject: [PATCH] feat(examples): making easier to follow examples --- examples/README.md | 47 ++++++++++++++++--- examples/check.py | 3 ++ examples/create_pdf.py | 29 ------------ .../create_postcards_from_csv.py} | 7 ++- .../input.csv | 0 .../postcard_back.html | 2 +- .../postcard_front.html | 2 +- examples/job.py | 3 ++ examples/letter.py | 3 ++ examples/postcard.py | 3 ++ .../input.csv | 0 .../verify_addresses_from_csv.py} | 2 + 12 files changed, 61 insertions(+), 40 deletions(-) delete mode 100644 examples/create_pdf.py rename examples/{csv_postcards/create_postcards.py => create_postcards_from_csv/create_postcards_from_csv.py} (86%) rename examples/{csv_postcards => create_postcards_from_csv}/input.csv (100%) rename examples/{csv_postcards => create_postcards_from_csv}/postcard_back.html (99%) rename examples/{csv_postcards => create_postcards_from_csv}/postcard_front.html (98%) rename examples/{csv_address_verification => verify_addresses_from_csv}/input.csv (100%) rename examples/{csv_address_verification/verify.py => verify_addresses_from_csv/verify_addresses_from_csv.py} (95%) diff --git a/examples/README.md b/examples/README.md index 4cf2e2c..f9eaa02 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,17 +2,50 @@ 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. +## Getting started +Before running these examples make sure you are in the `examples/` directory. +``` +cd examples/ +``` -## 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). +## Examples -## csv_postcards +### Create postcards from CSV -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). +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). In order to run the program enter: -```python -python create_postcards.py input.csv +``` +cd create_postcards_from_csv/ +python create_postcards_from_csv.py input.csv +``` + +### Verify addresses from CSV + +An example showing how to validate and cleanse a CSV spreadsheet full of shipping addresses using Lob's [Address Verification API](https://lob.com/verification/address). + +``` +cd verify_addresses_from_csv/ +python verify_addresses_from_csv.py input.csv +``` + +### Create a check +``` +python check.py +``` + +### Create a job +``` +python job.py +``` + +### Create a letter +``` +python letter.py +``` + +### Create a postcard +``` +python postcard.py ``` diff --git a/examples/check.py b/examples/check.py index 095ea88..0cc8e95 100644 --- a/examples/check.py +++ b/examples/check.py @@ -1,3 +1,6 @@ +import sys, os +sys.path.insert(0, os.path.abspath(__file__+'../../..')) + import lob lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. diff --git a/examples/create_pdf.py b/examples/create_pdf.py deleted file mode 100644 index 5f5aab9..0000000 --- a/examples/create_pdf.py +++ /dev/null @@ -1,29 +0,0 @@ -import lob -import pdfkit - -lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. - -body = """ - - -
- -

Print with Lob

-
- - -""" - -pdfkit.from_string(body, 'out.pdf', { - 'page-height': '6.25in', - 'page-width': '4.25in', - 'quiet': '' -}) - -example_object = lob.Object.create( - description='Example Object', - file=open('out.pdf', 'rb'), - setting_id=201 -) - -print "Check out the created PDF here: " + example_object.url diff --git a/examples/csv_postcards/create_postcards.py b/examples/create_postcards_from_csv/create_postcards_from_csv.py similarity index 86% rename from examples/csv_postcards/create_postcards.py rename to examples/create_postcards_from_csv/create_postcards_from_csv.py index 4a3d0ef..0db2622 100644 --- a/examples/csv_postcards/create_postcards.py +++ b/examples/create_postcards_from_csv/create_postcards_from_csv.py @@ -1,3 +1,6 @@ +import sys, os +sys.path.insert(0, os.path.abspath(__file__+'../../../..')) + import lob import csv import sys @@ -10,9 +13,9 @@ print "Please provide an input CSV file as an argument." sys.exit() -with open('postcard_front.html', 'r') as frontHtmlFile: +with open(os.path.dirname(__file__) + '/postcard_front.html', 'r') as frontHtmlFile: frontHtml = frontHtmlFile.read() - with open('postcard_back.html', 'r') as backHtmlFile: + with open(os.path.dirname(__file__) + '/postcard_back.html', 'r') as backHtmlFile: backHtml = backHtmlFile.read() with open(sys.argv[1]) as f: for row in csv.reader(f): diff --git a/examples/csv_postcards/input.csv b/examples/create_postcards_from_csv/input.csv similarity index 100% rename from examples/csv_postcards/input.csv rename to examples/create_postcards_from_csv/input.csv diff --git a/examples/csv_postcards/postcard_back.html b/examples/create_postcards_from_csv/postcard_back.html similarity index 99% rename from examples/csv_postcards/postcard_back.html rename to examples/create_postcards_from_csv/postcard_back.html index 418bd69..41efdef 100644 --- a/examples/csv_postcards/postcard_back.html +++ b/examples/create_postcards_from_csv/postcard_back.html @@ -38,4 +38,4 @@ Make sure to bring this card to receive great savings!

- + \ No newline at end of file diff --git a/examples/csv_postcards/postcard_front.html b/examples/create_postcards_from_csv/postcard_front.html similarity index 98% rename from examples/csv_postcards/postcard_front.html rename to examples/create_postcards_from_csv/postcard_front.html index d023805..5bc3bc9 100644 --- a/examples/csv_postcards/postcard_front.html +++ b/examples/create_postcards_from_csv/postcard_front.html @@ -24,4 +24,4 @@ - + \ No newline at end of file diff --git a/examples/job.py b/examples/job.py index 67c7603..d3db834 100644 --- a/examples/job.py +++ b/examples/job.py @@ -1,3 +1,6 @@ +import sys, os +sys.path.insert(0, os.path.abspath(__file__+'../../..')) + import lob lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. diff --git a/examples/letter.py b/examples/letter.py index b93ff3e..11556cd 100644 --- a/examples/letter.py +++ b/examples/letter.py @@ -1,3 +1,6 @@ +import sys, os +sys.path.insert(0, os.path.abspath(__file__+'../../..')) + import lob lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. diff --git a/examples/postcard.py b/examples/postcard.py index 3a3f92c..bb1ab64 100644 --- a/examples/postcard.py +++ b/examples/postcard.py @@ -1,3 +1,6 @@ +import sys, os +sys.path.insert(0, os.path.abspath(__file__+'../../..')) + import lob lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. diff --git a/examples/csv_address_verification/input.csv b/examples/verify_addresses_from_csv/input.csv similarity index 100% rename from examples/csv_address_verification/input.csv rename to examples/verify_addresses_from_csv/input.csv diff --git a/examples/csv_address_verification/verify.py b/examples/verify_addresses_from_csv/verify_addresses_from_csv.py similarity index 95% rename from examples/csv_address_verification/verify.py rename to examples/verify_addresses_from_csv/verify_addresses_from_csv.py index 1785dec..637dd2f 100644 --- a/examples/csv_address_verification/verify.py +++ b/examples/verify_addresses_from_csv/verify_addresses_from_csv.py @@ -1,5 +1,7 @@ # Usage # python verify.py input.csv +import sys, os +sys.path.insert(0, os.path.abspath(__file__+'../../../..')) import lob import csv