-
Notifications
You must be signed in to change notification settings - Fork 5
/
address_to_fedex.py
executable file
·74 lines (50 loc) · 2.43 KB
/
address_to_fedex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
## address_to_fedex.py
##-------------------------------------------------------------------------
## We simply iterate through the selected contacts in Address Book. For
## each contact we fill out a dictionary based upon the contact's field
## values. We then call fill_safari() from the module paste_to_fedex.py
## which must be in the same directory or in the Python path.
import string, sys, time, shutil
from appscript import *
import os
import paste_to_fedex
def process_ab_selection():
AB = app(u'/Applications/Contacts.app')
clients = AB.selection.get()
order_data = {}
for client in clients:
# normally this will only run once but I figured I'd make it so you can do more than one person
order_data['last'] = client.last_name.get()
if order_data['last'] == k.missing_value:
order_data['last'] = ""
order_data['first'] = client.first_name.get()
if order_data['first'] == k.missing_value:
order_data['first'] = ""
order_data['company'] = client.name.get()
if order_data['company'] == k.missing_value:
order_data['company'] = "Unknown"
order_data['address'] = client.addresses.get()[0].street.get()
if order_data['address'] == k.missing_value:
order_data['address'] = ""
order_data['city'] = client.addresses.get()[0].city.get()
if order_data['city'] == k.missing_value:
order_data['city'] = ""
order_data['state'] = client.addresses.get()[0].state.get()
if order_data['state'] == k.missing_value:
order_data['state'] = ""
order_data['zip'] = client.addresses.get()[0].zip.get()
if order_data['zip'] == k.missing_value:
order_data['zip'] = ""
try:
order_data['telephone'] = client.phones.items[1].value.get()
if order_data['telephone'] == k.missing_value:
order_data['telephone'] = "801-655-1996"
except:
order_data['telephone'] = "801-655-1996"
paste_to_fedex.fill_safari( order_data )
if __name__ == '__main__':
if len(sys.argv) == 1:
process_ab_selection()
# change to 0 for success, 1 for (partial) failure
sys.exit(0)