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
47 changes: 40 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
3 changes: 3 additions & 0 deletions examples/check.py
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
29 changes: 0 additions & 29 deletions examples/create_pdf.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys, os
sys.path.insert(0, os.path.abspath(__file__+'../../../..'))

import lob
import csv
import sys
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
Make sure to bring this card to receive great savings!<br><br>
</div>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

<body>
</body>
</html>
</html>
3 changes: 3 additions & 0 deletions examples/job.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys, os
sys.path.insert(0, os.path.abspath(__file__+'../../..'))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leore @pon
This looks kinda hacky but it will load the unpacked version before anything else. Is there a better way of doing it? It's completely dependent on the relative path of the file.


import lob
lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own.

Expand Down
3 changes: 3 additions & 0 deletions examples/letter.py
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
3 changes: 3 additions & 0 deletions examples/postcard.py
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down