Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding the simple ones here as well? @ami

- [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)
Expand Down
6 changes: 5 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
48 changes: 48 additions & 0 deletions examples/csv_postcards/create_postcards.py
Original file line number Diff line number Diff line change
@@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above you indented 2 spaces, but here it's 4 spaces. shouldn't that cause errors in python?

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
7 changes: 7 additions & 0 deletions examples/csv_postcards/input.csv
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions examples/csv_postcards/postcard_back.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<html>
<head>
<title>Lob.com Sample 6x11 Postcard Back Template 1</title>
<style>
@font-face {
font-family: 'Arimo';
font-style: normal;
font-weight: 400;
src: url('https://s3-us-west-2.amazonaws.com/lob-assets/Arimo-Regular.ttf') format('truetype');
}

body {
width:11.25in;
height:6.25in;
margin:0;
padding:0;
background-size: 11.25in 6.25in;
}

#left-box {
font-family: Arimo;
font-size: .25in;
background-color: {{background_color}};
width: 5.85in;
height: 5.85in;
position: absolute;
top: 0;
left: 0;
padding: .4in .6in 0 .4in;
}
</style>
</head>

<body>
<div id="left-box">
Hey {{name}},<br><br>
Your {{car}} is due for its {{mileage}} mile service. Schedule an appointment today!<br><br>
Make sure to bring this card to receive great savings!<br><br>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing </body>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - updated

</body>
</html>
27 changes: 27 additions & 0 deletions examples/csv_postcards/postcard_front.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<head>
<title>Lob.com Sample 6x11 Postcard Front</title>
<style>
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

body {
width: 11.25in;
height: 6.25in;
margin: 0;
padding: 0;
/* If using an image, the background image should have dimensions of 1875x1275 pixels. */
background-image: url({{background_image}});
background-size: 11.25in 6.25in;
background-repeat: no-repeat;
}

</style>
</head>

<body>
</body>
</html>