Skip to content

Commit ffc8d51

Browse files
author
Greg Taylor
committed
More label certification work.
1 parent 2b102f3 commit ffc8d51

File tree

2 files changed

+63
-30
lines changed

2 files changed

+63
-30
lines changed

label_certification/cert_config.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,60 @@
88
# any globally installed versions.
99
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1010
from fedex.config import FedexConfig
11+
from fedex.printers.unix import DirectDevicePrinter
1112

13+
# Change these values to match your testing account/meter number.
1214
CONFIG_OBJ = FedexConfig(key='ZyNQQFdcxUATOx9L',
1315
password='8irpTkULT1zjVLlL8XiVczTex',
1416
account_number='510087780',
1517
meter_number='118501898',
16-
use_test_server=True)
18+
use_test_server=True)
19+
20+
# Change this to whoever should be the contact person for shipments.
21+
SHIPPER_CONTACT_INFO = {'PersonName': 'Gregory Taylor',
22+
'CompanyName': 'International Paper',
23+
'PhoneNumber': '8646336010'}
24+
25+
# The dictionary below should be your office/client's address that shipping
26+
# will be originating from.
27+
SHIPPER_ADDRESS = {'StreetLines': ['155 Old Greenville Hwy', 'Suite 103'],
28+
'City': 'Clemson',
29+
'StateOrProvinceCode': 'SC',
30+
'PostalCode': '29631',
31+
'CountryCode': 'US',
32+
'Residential': False}
33+
34+
# This contains the configuration for your label printer.
35+
LABEL_SPECIFICATION = {
36+
# Specifies the label type to be returned.
37+
# LABEL_DATA_ONLY or COMMON2D
38+
'LabelFormatType': 'COMMON2D',
39+
# Specifies which format the label file will be
40+
# sent to you in.
41+
# DPL, EPL2, PDF, PNG, ZPLII
42+
'ImageType': 'EPL2',
43+
# To use doctab stocks, you must change ImageType above
44+
# to one of the label printer formats (ZPLII, EPL2, DPL).
45+
# See documentation for paper types, there quite a few.
46+
'LabelStockType': 'STOCK_4X6.75_LEADING_DOC_TAB',
47+
# This indicates if the top or bottom of the label comes
48+
# out of the printer first.
49+
# BOTTOM_EDGE_OF_TEXT_FIRST or TOP_EDGE_OF_TEXT_FIRST
50+
'LabelPrintingOrientation': 'BOTTOM_EDGE_OF_TEXT_FIRST'
51+
}
52+
53+
# This should just be a reference to the correct printer class for your
54+
# label printer. You may find these under the fedex.printers module.
55+
# NOTE: This should NOT be an instance. It should just be a reference.
56+
LabelPrinterClass = DirectDevicePrinter
57+
58+
def transfer_config_dict(soap_object, data_dict):
59+
"""
60+
This is a utility function used in the certification modules to transfer
61+
the data dicts above to SOAP objects. This avoids repetition and allows
62+
us to store all of our variable configuration here rather than in
63+
each certification script.
64+
"""
65+
for key, val in data_dict.items():
66+
# Transfer each key to the matching attribute ont he SOAP object.
67+
setattr(soap_object, key, val)

label_certification/international_priority.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
This module prints a label used to certify International Priority shipments.
44
"""
55
import logging
6-
from cert_config import CONFIG_OBJ
6+
from cert_config import CONFIG_OBJ, SHIPPER_CONTACT_INFO, SHIPPER_ADDRESS, LABEL_SPECIFICATION
7+
from cert_config import transfer_config_dict
8+
from cert_config import LabelPrinterClass
79
from fedex.services.ship_service import FedexProcessShipmentRequest
810
from fedex.printers.unix import DirectDevicePrinter
911

@@ -16,18 +18,12 @@
1618
shipment.RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES'
1719

1820
# Shipper contact info.
19-
shipment.RequestedShipment.Shipper.Contact.PersonName = 'Gregory Taylor'
20-
shipment.RequestedShipment.Shipper.Contact.CompanyName = 'International Paper'
21-
shipment.RequestedShipment.Shipper.Contact.PhoneNumber = '8646336010'
21+
transfer_config_dict(shipment.RequestedShipment.Shipper.Contact,
22+
SHIPPER_CONTACT_INFO)
2223

2324
# Shipper address.
24-
shipment.RequestedShipment.Shipper.Address.StreetLines = ['155 Old Greenville Hwy',
25-
'Suite 103']
26-
shipment.RequestedShipment.Shipper.Address.City = 'Clemson'
27-
shipment.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'SC'
28-
shipment.RequestedShipment.Shipper.Address.PostalCode = '29631'
29-
shipment.RequestedShipment.Shipper.Address.CountryCode = 'US'
30-
shipment.RequestedShipment.Shipper.Address.Residential = False
25+
transfer_config_dict(shipment.RequestedShipment.Shipper.Address,
26+
SHIPPER_ADDRESS)
3127

3228
# Recipient contact info.
3329
shipment.RequestedShipment.Recipient.Contact.PersonName = 'Some Guy'
@@ -42,23 +38,9 @@
4238

4339
shipment.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER'
4440

45-
# Specifies the label type to be returned.
46-
# LABEL_DATA_ONLY or COMMON2D
47-
shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'COMMON2D'
48-
49-
# Specifies which format the label file will be sent to you in.
50-
# DPL, EPL2, PDF, PNG, ZPLII
51-
shipment.RequestedShipment.LabelSpecification.ImageType = 'EPL2'
52-
53-
# To use doctab stocks, you must change ImageType above to one of the
54-
# label printer formats (ZPLII, EPL2, DPL).
55-
# See documentation for paper types, there quite a few.
56-
shipment.RequestedShipment.LabelSpecification.LabelStockType = 'STOCK_4X6.75_LEADING_DOC_TAB'
57-
58-
# This indicates if the top or bottom of the label comes out of the
59-
# printer first.
60-
# BOTTOM_EDGE_OF_TEXT_FIRST or TOP_EDGE_OF_TEXT_FIRST
61-
shipment.RequestedShipment.LabelSpecification.LabelPrintingOrientation = 'BOTTOM_EDGE_OF_TEXT_FIRST'
41+
# Label config.
42+
transfer_config_dict(shipment.RequestedShipment.LabelSpecification,
43+
LABEL_SPECIFICATION)
6244

6345
package1_weight = shipment.create_wsdl_object_of_type('Weight')
6446
package1_weight.Value = 10.0
@@ -93,5 +75,5 @@
9375

9476
print shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds
9577

96-
device = DirectDevicePrinter(shipment)
78+
device = LabelPrinterClass(shipment)
9779
device.print_label()

0 commit comments

Comments
 (0)