nzpostaddy

yay maps, something I haven't really used before. Good to try something new.

Using some demo examples from nz post. Examples are printed below.

script to search for addresses.

Gets address from nzpost then displays static map from mapquestapi.

Lookup lat long against high speed internet access.

Create svg files from address and save to folder and add to json object.

Check for pizza options. People need pizza right?

Is this house on the market.

Scan for open wireless networks.

Convert full country name to country code

Give unique code to street that can be looked up

What schools are in the area?

Booking system for school parcel pickup

Send parcels to every school in the country.

How to qualify for Bulk Mail discounts

To qualify for Bulk Mail discounts, there are a few things you’ll need to consider:

Are the addresses in your database accurate against the Postal Address File (PAF)? Refer to validate customer addresses for further information.
Have you used the correct address and envelope format and layout?
Are your items sorted by postcode?

Getting your mail If you want your mail to reach its destination as quickly and accurately as possible, this brochure is for you!

It’s a quick rundown on how to address all your mail so it’s processed and delivered by New Zealand Post in the fastest possible time – and gets delivered to the right address, whether it’s a street address with a suburb and town, Rural Delivery address, New Zealand Post PO Box or Private Bag. The brochure covers every type of postal address, from apartments to farms, and includes handy examples of how to get your addressing right. If you’d like more detailed information on addressing standards, check out our full ‘Address Standards’ publication, which you can find at www.nzpost.co.nz/addressing Addresses in New Zealand – how they work Line Content Examples Reference This contains FreePost or other reference information, such as a customer account number. It’s mandatory for non-approved FreePost mail. Customer 767676 FreePost 2354 Recipient The name of the person and/or organisation to whom you’re addressing the mail. You can split this information over several lines. (See ‘Basic rural addresses’ and ‘PO Box, Private Bag and Counter Delivery addresses’ for situations where this line is mandatory.) Mrs S Jones The Carpet Factory Unit A unit (flat, suite etc) and/or floor. It can also include a building name. This line is mandatory if the floor detail is needed to identify the delivery point. It’s not used for PO Box, Private Bag and Counter Delivery addresses. Level 2, Mason House Suite 10, Mason House Flat 2, Mason House Building name The building name is required on this line by itself, only if there’s no known street number for the address. It’s not used for PO Box, Private Bag and Counter Delivery addresses. Mason House Delivery Mandatory Urban and rural addresses must include the street name. This line can also contain: • a street number and letter (alpha) before the street name • a unit and unit separator ‘/’ before the street number • the street type and/or street direction after the street name. Delivery Service addresses must contain one of ‘PO Box’, ‘Private Bag’, ‘Response Bag’, ‘CMB’ (Community Mail Box), ‘Counter Delivery’, or ‘Poste Restante’. This is followed by the delivery service identifier (usually a number) if New Zealand Post has allocated one. 19A Buckley Road 2B/54 Terrace Street 12 Sydney Street North PO Box 23226 Private Bag 39990 Suburb The suburb line may contain: • the suburb name for an urban address, or • ‘RD’ followed by the RD number for rural or rural CMB addresses, or • the box lobby for a PO Box address, or • the PostShop or PostCentre name for a Counter Delivery address. ‘Basic urban addresses’, ‘Basic rural addresses’ and ‘PO Box, Private Bag and Counter Delivery addresses’ cover situations where the suburb line is mandatory or not used

Sort mail by postcode. Returns all mail that needs to be delivered.

Sort by City, City + Suburb etc..

Lookup by address id

You are loged into system to pickup parcels at 0700 that will be dropped at Wellington depo at 0725. 0730 0755 0800 0825 0830 0855. Have drone at major depos that deliver.

Scan barcode to check parcel out.

Recieve all written mail via email. Postal letters can have barcode on that scans for a doc. gpg encrupt that has passphase/password on that only the person recieving it has.

Give all postal addresses public/private keys to open their mail.

Pace Auckland Zone Chart

Pace - Split smaller towns up.

Track parcel/letter via webcam.

Lat/Lng of postboxes. Delivery drones pickup from postboxes and drop off to major depos.


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [5]:
import json
import shutil
import requests
import svgwrite
import arrow
import bs4

In [ ]:


In [ ]:


In [6]:
opjsres = open('/home/wcmckee/github/nzpostad.json', 'r')

In [7]:
opjrd = opjsres.read()

In [8]:
nzpod = json.loads(opjrd)

In [9]:
nzpod


Out[9]:
{'addresses': [{'address_id': '196111',
   'dpid': '754977',
   'full_address': '19 Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '197147',
   'dpid': '750361',
   'full_address': '23 Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '195925',
   'dpid': '751485',
   'full_address': '7A Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '198893',
   'dpid': '747422',
   'full_address': '8 Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '195986',
   'dpid': '754969',
   'full_address': '9A Queen Alexandra Street, Lansdowne, Masterton 5810'}],
 'success': True}

In [10]:
nzpaddy = nzpod['addresses']

In [11]:
nzplen = len(nzpod['addresses'])

In [12]:
nzplen


Out[12]:
5

In [13]:
streetstc = list()

In [14]:
stbla = list()

In [15]:
for nzp in range(0, nzplen):
    nzitm = (nzpaddy[nzp])
    streetstc.append(nzitm['full_address'])

In [16]:
for sts in streetstc:
    stbla.append(sts.split(','))

In [17]:
strlisz = list()

In [ ]:


In [18]:
for stb in stbla:
    for st in stb:
        print(st)
        strlisz.append(st)


19 Queen Alexandra Street
 Lansdowne
 Masterton 5810
23 Queen Alexandra Street
 Lansdowne
 Masterton 5810
7A Queen Alexandra Street
 Lansdowne
 Masterton 5810
8 Queen Alexandra Street
 Lansdowne
 Masterton 5810
9A Queen Alexandra Street
 Lansdowne
 Masterton 5810

In [19]:
set(strlisz)


Out[19]:
{' Lansdowne',
 ' Masterton 5810',
 '19 Queen Alexandra Street',
 '23 Queen Alexandra Street',
 '7A Queen Alexandra Street',
 '8 Queen Alexandra Street',
 '9A Queen Alexandra Street'}

In [ ]:


In [ ]:


In [20]:
stbla[0][0]


Out[20]:
'19 Queen Alexandra Street'

In [21]:
stbla[0][1]


Out[21]:
' Lansdowne'

In [22]:
stbla[0][2]


Out[22]:
' Masterton 5810'

In [23]:
opsuccessad = open('/home/wcmckee/github/nzpostsuccess.json', 'r')

In [24]:
opsucrd = opsuccessad.read()

In [25]:
opjslo = json.loads(opsucrd)

In [118]:
addypocde = opjslo['address']['postcode']

In [122]:
adpoz = addypocde[0]

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [27]:
opja = opjslo['address']

In [28]:
opja['street_number']


Out[28]:
71

In [29]:
opja['street']


Out[29]:
'Oregon'

In [30]:
opja['street_type']


Out[30]:
'Street'

In [31]:
opja['suburb']


Out[31]:
'Ocean Grove'

In [32]:
adcit = opja['city']

In [33]:
opja['postcode']


Out[33]:
'9013'

In [34]:
adcit


Out[34]:
'Dunedin'

In [35]:
opja['country']


Out[35]:
'New Zealand'

In [36]:
fulladdress = (str(opja['street_number']) + ' ' + opja['street'] +  ' ' + opja['street_type'] +', ' + opja['suburb'] + ', ' + adcit + ' ' + str(opja['postcode']) + ', ' + opja['country'])

In [37]:
fulladdress


Out[37]:
'71 Oregon Street, Ocean Grove, Dunedin 9013, New Zealand'

In [38]:
opja['depot_name']


Out[38]:
'Dunedin Depot'

In [39]:
latad = opja['latitude']

In [40]:
longad = opja['longitude']

In [41]:
latad


Out[41]:
-45.9041

In [42]:
longad


Out[42]:
170.552

In [43]:
mapk = open('/home/wcmckee/github/mapkey.txt', 'r')


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-43-00eadc1d7da5> in <module>()
----> 1 mapk = open('/home/wcmckee/github/mapkey.txt', 'r')

FileNotFoundError: [Errno 2] No such file or directory: '/home/wcmckee/github/mapkey.txt'

In [44]:
mapkrd = mapk.read()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-44-80e01bd5e334> in <module>()
----> 1 mapkrd = mapk.read()

NameError: name 'mapk' is not defined

In [41]:
reqimg = 'http://www.mapquestapi.com/staticmap/v4/getmap?key=' + mapkrd + '&size=400,200&zoom=10&center=' + str(latad) + ',' + str(longad)

In [42]:
rmnz = reqimg.replace('\n', '')

In [123]:
fuladrm = fulladdress.replace(', ', '')

In [124]:
fulrmno = fuladrm.replace(' ', '')

In [125]:
fulrmno


Out[125]:
'71OregonStreetOceanGroveDunedin9013NewZealand'

In [128]:
opsavl = open('/home/wcmckee/Downloads/nzpost/postcode/' + adpoz + '/' + fulrmno + '.json', 'w')

In [131]:
opsavl.read


Out[131]:
<function TextIOWrapper.read>

In [ ]:


In [46]:
mapdir = '/home/wcmckee/nzpost/maps/'

In [47]:
addysvg = '/home/wcmckee/nzpost/addysvg/'

In [46]:
opserv = open('/home/wcmckee/github/nzpostoption.json', 'r')

In [47]:
optprd = opserv.read()

In [48]:
weighrate = json.loads(optprd)

In [49]:
lenweigh = len(weighrate)

In [50]:
lenweigh


Out[50]:
4

In [51]:
for lenwe in range(0, lenweigh):
    print(weighrate['services'][lenwe]['price_excluding_gst'])


16.31
30.32
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-51-9cbe19e3e5b4> in <module>()
      1 for lenwe in range(0, lenweigh):
----> 2     print(weighrate['services'][lenwe]['price_excluding_gst'])

IndexError: list index out of range

In [ ]:


In [52]:
weighrate


Out[52]:
{'message_id': 'f7d48804-9693-436a-8f45-853fdea97c20',
 'rated_weight': 10,
 'services': [{'addons': [{'addon_code': 'CPSR',
     'description': 'CP Online Sig Rq',
     'mandatory': False,
     'price_excluding_gst': 0.28,
     'price_including_gst': 0.32},
    {'addon_code': 'CPOLRD',
     'description': 'CP Online Rural Delivery',
     'mandatory': True,
     'price_excluding_gst': 0,
     'price_including_gst': 0}],
   'carrier': 'CourierPost',
   'description': 'CP Online Economy',
   'estimated_delivery_time': None,
   'price_excluding_gst': 16.31,
   'price_including_gst': 18.76,
   'service_code': 'CPOLE',
   'signature_included': False,
   'tracking_included': True},
  {'addons': [{'addon_code': 'CPSR',
     'description': 'CP Online Sig Rq',
     'mandatory': False,
     'price_excluding_gst': 0.28,
     'price_including_gst': 0.32},
    {'addon_code': 'CPOLRD',
     'description': 'CP Online Rural Delivery',
     'mandatory': True,
     'price_excluding_gst': 0,
     'price_including_gst': 0}],
   'carrier': 'CourierPost',
   'description': 'CP Online Parcel',
   'estimated_delivery_time': None,
   'price_excluding_gst': 30.32,
   'price_including_gst': 34.87,
   'service_code': 'CPOLP',
   'signature_included': False,
   'tracking_included': True}],
 'success': True}

In [53]:
weicar =  weighrate['services'][0]['carrier']

In [ ]:


In [54]:
weiprg = weighrate['services'][0]['price_including_gst']

In [ ]:


In [55]:
weiprn = weighrate['services'][0]['price_excluding_gst']

In [56]:
waipa = (weicar + ' ' + str(weiprn) + ' ' + str(weiprg))

In [57]:
waipa


Out[57]:
'CourierPost 16.31 18.76'

In [58]:
weighaddon = weighrate['services'][0]['addons']

In [59]:
lenweia = len(weighaddon)

In [60]:
lenweia


Out[60]:
2

In [61]:
for lenwa in range(0, lenweia):
    print (weighaddon[lenwa])


{'mandatory': False, 'addon_code': 'CPSR', 'price_excluding_gst': 0.28, 'description': 'CP Online Sig Rq', 'price_including_gst': 0.32}
{'mandatory': True, 'addon_code': 'CPOLRD', 'price_excluding_gst': 0, 'description': 'CP Online Rural Delivery', 'price_including_gst': 0}

In [62]:
foxaddon = list()

In [63]:
for lenwa in range(0, lenweia):
    weaddonco = (weighaddon[lenwa]['addon_code'])
    weaddondescp = (weighaddon[lenwa]['description'])
    weighaddongst =  (weighaddon[lenwa]['price_including_gst'])
    weighmantor = (weighaddon[lenwa]['mandatory'])
    myflis = (weaddonco + ', ' + weaddondescp + ', ' + str(weighmantor) + ', ' + str(weighaddongst))
    foxaddon.append(myflis)

In [64]:
foxaddon


Out[64]:
['CPSR, CP Online Sig Rq, False, 0.32',
 'CPOLRD, CP Online Rural Delivery, True, 0']

In [65]:
weighcarry = weighrate['services'][0]['carrier']

In [66]:
weighcarry


Out[66]:
'CourierPost'

In [67]:
lengoxa = len(foxaddon)

In [ ]:


In [68]:
derbdict = dict()

In [69]:
for dezba in range(lengoxa):
    print (dezba)
    for dez in foxaddon:
        derbdict.update({dezbd : dez})


0
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-69-24881c10416d> in <module>()
      2     print (dezba)
      3     for dez in foxaddon:
----> 4         derbdict.update({dezbd : dez})

NameError: name 'dezbd' is not defined

In [70]:
foxaddon


Out[70]:
['CPSR, CP Online Sig Rq, False, 0.32',
 'CPOLRD, CP Online Rural Delivery, True, 0']

In [71]:
for dez in foxaddon:
    for dezba in range(lengoxa):
        print (dezba)
        derbdict.update({dezba : dez})


0
1
0
1

In [ ]:


In [72]:
derbdict


Out[72]:
{0: 'CPOLRD, CP Online Rural Delivery, True, 0',
 1: 'CPOLRD, CP Online Rural Delivery, True, 0'}

In [73]:
myflis


Out[73]:
'CPOLRD, CP Online Rural Delivery, True, 0'

In [74]:
weighrate['services'][0]


Out[74]:
{'addons': [{'addon_code': 'CPSR',
   'description': 'CP Online Sig Rq',
   'mandatory': False,
   'price_excluding_gst': 0.28,
   'price_including_gst': 0.32},
  {'addon_code': 'CPOLRD',
   'description': 'CP Online Rural Delivery',
   'mandatory': True,
   'price_excluding_gst': 0,
   'price_including_gst': 0}],
 'carrier': 'CourierPost',
 'description': 'CP Online Economy',
 'estimated_delivery_time': None,
 'price_excluding_gst': 16.31,
 'price_including_gst': 18.76,
 'service_code': 'CPOLE',
 'signature_included': False,
 'tracking_included': True}

In [75]:
oppizza = open('/home/wcmckee/github/pizzadelivpost.json', 'r')

In [ ]:


In [ ]:


In [76]:
pizrd = oppizza.read()

In [77]:
nowtime = arrow.now()

In [78]:
str(nowtime.datetime)


Out[78]:
'2015-10-24 15:02:00.595360+13:00'

In [ ]:


In [79]:
adval = dict({'address': fulladdress, 'datetime' : str(nowtime.datetime)})

In [80]:
adval


Out[80]:
{'address': '71 Oregon Street, Ocean Grove, Dunedin 9013, New Zealand',
 'datetime': '2015-10-24 15:02:00.595360+13:00'}

In [81]:
json.loads(pizrd)['requests']


Out[81]:
[{'collectionId': '9ef2a17d-bd70-328d-7ab4-ff404f411a27',
  'data': [{'key': 'accountID', 'type': 'text', 'value': 'phimc2api'},
   {'key': 'accountPW', 'type': 'text', 'value': 'fs112358'},
   {'key': 'version', 'type': 'text', 'value': '2.0'},
   {'key': 'appsource', 'type': 'text', 'value': 'Android'},
   {'key': 'appversion', 'type': 'text', 'value': '2.1.2'},
   {'key': 'request', 'type': 'text', 'value': 'HTMLOrder'},
   {'key': 'data',
    'type': 'text',
    'value': '{"sessionToken":"zDmPoTjzLOd8E8YYLxsFy0MPwQE7LKo19FmFxyZDQFSRRzfRd1LE48xCCj5k3PwC","unitID":"029704","occasion":"C","location_index":-1,"action":"start"}'}],
  'dataMode': 'urlencoded',
  'description': '',
  'headers': '',
  'id': '2b852493-f523-f119-b22e-66189f55d09c',
  'method': 'POST',
  'name': 'getHtmlOrder',
  'time': 1433811561494,
  'timestamp': 0,
  'url': 'https://quikorder.pizzahut.com/phorders3/service.php',
  'version': 2},
 {'collectionId': '9ef2a17d-bd70-328d-7ab4-ff404f411a27',
  'data': [{'key': 'accountID', 'type': 'text', 'value': 'phimc2api'},
   {'key': 'accountPW', 'type': 'text', 'value': 'fs112358'},
   {'key': 'version', 'type': 'text', 'value': '2.0'},
   {'key': 'appsource', 'type': 'text', 'value': 'Android'},
   {'key': 'appversion', 'type': 'text', 'value': '2.1.2'},
   {'key': 'request', 'type': 'text', 'value': 'FindNearByAddress'},
   {'key': 'data', 'type': 'text', 'value': '{"customer_zip": "32820"}'}],
  'dataMode': 'urlencoded',
  'description': '',
  'headers': '',
  'id': '5fc79717-503b-c4eb-f50c-c954bd82313f',
  'method': 'POST',
  'name': 'findNearbyAddress',
  'responses': [],
  'timestamp': 0,
  'url': 'https://quikorder.pizzahut.com/phorders3/service.php',
  'version': 2},
 {'collectionId': '9ef2a17d-bd70-328d-7ab4-ff404f411a27',
  'data': [{'key': 'accountID', 'type': 'text', 'value': 'phimc2api'},
   {'key': 'accountPW', 'type': 'text', 'value': 'fs112358'},
   {'key': 'version', 'type': 'text', 'value': '2.0'},
   {'key': 'appsource', 'type': 'text', 'value': 'Android'},
   {'key': 'appversion', 'type': 'text', 'value': '2.1.2'},
   {'key': 'request', 'type': 'text', 'value': 'GenerateTempAccount'},
   {'key': 'data',
    'type': 'text',
    'value': '{"address":{"street_address":"16873 E. Colonial Dr.","apartment":"","city":"Orlando","state":"FL","zip":"32820"}}'}],
  'dataMode': 'urlencoded',
  'description': '',
  'headers': '',
  'id': '7a719f0b-7a69-7adf-e77f-545f7a824712',
  'method': 'POST',
  'name': 'generateTempAccount',
  'time': 1433809230725,
  'timestamp': 0,
  'url': 'https://quikorder.pizzahut.com/phorders3/service.php',
  'version': 2},
 {'collectionId': '9ef2a17d-bd70-328d-7ab4-ff404f411a27',
  'data': [{'key': 'accountID', 'type': 'text', 'value': 'phimc2api'},
   {'key': 'accountPW', 'type': 'text', 'value': 'fs112358'},
   {'key': 'version', 'type': 'text', 'value': '2.0'},
   {'key': 'appsource', 'type': 'text', 'value': 'Android'},
   {'key': 'appversion', 'type': 'text', 'value': '2.1.2'},
   {'key': 'request', 'type': 'text', 'value': 'GetMenuItems'},
   {'key': 'data',
    'type': 'text',
    'value': '{"unitID":"997","occasion":"D","section":"category","subsection":"APICAROUSEL"}'}],
  'dataMode': 'urlencoded',
  'description': '',
  'headers': '',
  'id': '97358452-70d5-dded-48e0-cd4e9f90285b',
  'method': 'POST',
  'name': 'getCarouselItems',
  'time': 1433040064599,
  'timestamp': 0,
  'url': 'https://quikorder.pizzahut.com/phorders3/service.php',
  'version': 2}]

In [82]:
opnzpobook = open('/home/wcmckee/github/nzpostbooking.json', 'r')


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-82-447e306897d8> in <module>()
----> 1 opnzpobook = open('/home/wcmckee/github/nzpostbooking.json', 'r')

FileNotFoundError: [Errno 2] No such file or directory: '/home/wcmckee/github/nzpostbooking.json'

In [83]:
rdnzpobook = opnzpobook.read()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-83-61e657706ca6> in <module>()
----> 1 rdnzpobook = opnzpobook.read()

NameError: name 'opnzpobook' is not defined

Client is school - contact is school email is schools email, phone, fax, website

city is school


In [ ]:


In [84]:
pobookj = json.loads(rdnzpobook)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-84-ba88b48c3010> in <module>()
----> 1 pobookj = json.loads(rdnzpobook)

NameError: name 'rdnzpobook' is not defined

In [85]:
popickad = pobookj['pickup_address']


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-85-bf2c728c5d96> in <module>()
----> 1 popickad = pobookj['pickup_address']

NameError: name 'pobookj' is not defined

In [88]:
popickad


Out[88]:
{'building': 'TestPickupBuilding',
 'city': 'Auckland',
 'company': 'Test Pickup Company Name',
 'email_address': 'glenn.dodd@nzpost.co.nz',
 'floor': '5',
 'instructions': 'TestPickupLocationInstructions',
 'location_contact': 'Test Pickup Address Location Contact',
 'location_phone': '6490000000',
 'postcode': '1010',
 'street_number_name': '151 Victoria Street West',
 'suburb': 'Auckland Central',
 'unit_type': 'Unit',
 'unit_value': '2'}

In [89]:
popickad['location_contact']


Out[89]:
'Test Pickup Address Location Contact'

In [90]:
popickad['company']


Out[90]:
'Test Pickup Company Name'

In [91]:
popickad['building']


Out[91]:
'TestPickupBuilding'

In [92]:
popickad['street_number_name']


Out[92]:
'151 Victoria Street West'

In [93]:
popickad['city']


Out[93]:
'Auckland'

In [94]:
popickad['postcode']


Out[94]:
'1010'

In [95]:
popickad['suburb']


Out[95]:
'Auckland Central'

In [96]:
popickad['location_phone']


Out[96]:
'6490000000'

In [97]:
popickad


Out[97]:
{'building': 'TestPickupBuilding',
 'city': 'Auckland',
 'company': 'Test Pickup Company Name',
 'email_address': 'glenn.dodd@nzpost.co.nz',
 'floor': '5',
 'instructions': 'TestPickupLocationInstructions',
 'location_contact': 'Test Pickup Address Location Contact',
 'location_phone': '6490000000',
 'postcode': '1010',
 'street_number_name': '151 Victoria Street West',
 'suburb': 'Auckland Central',
 'unit_type': 'Unit',
 'unit_value': '2'}

In [98]:
popickad


Out[98]:
{'building': 'TestPickupBuilding',
 'city': 'Auckland',
 'company': 'Test Pickup Company Name',
 'email_address': 'glenn.dodd@nzpost.co.nz',
 'floor': '5',
 'instructions': 'TestPickupLocationInstructions',
 'location_contact': 'Test Pickup Address Location Contact',
 'location_phone': '6490000000',
 'postcode': '1010',
 'street_number_name': '151 Victoria Street West',
 'suburb': 'Auckland Central',
 'unit_type': 'Unit',
 'unit_value': '2'}

In [99]:
popickad['building']


Out[99]:
'TestPickupBuilding'

In [ ]:


In [ ]:


In [100]:
podattim = pobookj['pickup_date_time']

In [101]:
podattim


Out[101]:
'2015-06-16T14:19:50'

In [102]:
arpick = arrow.get(podattim)

In [103]:
str(arpick.weekday())


Out[103]:
'1'

In [104]:
'delieverwhen' : str(arpick.humanize())


  File "<ipython-input-104-7341d44fe6d7>", line 1
    'delieverwhen' : str(arpick.humanize())
                   ^
SyntaxError: invalid syntax

In [105]:
str(arpick.for_json())


Out[105]:
'2015-06-16T14:19:50+00:00'

In [106]:
str(arpick.humanize())


Out[106]:
'4 months ago'

In [107]:
str(arpick.isoweekday())


Out[107]:
'2'

In [108]:
str(arpick.isocalendar())


Out[108]:
'(2015, 25, 2)'

In [109]:
str(arpick.isoformat())


Out[109]:
'2015-06-16T14:19:50+00:00'

In [ ]:


In [110]:
pobookj['caller']


Out[110]:
'Test Caller'

In [111]:
pobookj['client_contact']


Out[111]:
'Test Client Contact'

In [112]:
pobookj['email_address']


Out[112]:
'glenn.dodd@nzpost.co.nz'

In [113]:
arrows.pobookj['message_date_time']


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-113-7ceef1461f12> in <module>()
----> 1 arrows.pobookj['message_date_time']

NameError: name 'arrows' is not defined

In [114]:
pobookj['city']


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-114-64c5f2462694> in <module>()
----> 1 pobookj['city']

KeyError: 'city'

In [115]:
pobokdead = pobookj['delivery_address']

In [116]:
pocom = pobokdead['company']

In [117]:
pobuil = pobokdead['building']

In [118]:
poflo = pobokdead['floor']

In [119]:
postnuma = pobokdead['street_number_name']

In [120]:
posub = pobokdead['suburb']

In [121]:
pocity = pobokdead['city']

In [122]:
popcd = pobokdead['postcode']

In [123]:
poem = pobokdead['email_address']

In [124]:
poinstr = pobokdead['instructions']

In [125]:
poinstr


Out[125]:
'Test Delivery Location Instructions'

In [126]:
poloccon = pobokdead['location_contact']

In [ ]:


In [127]:
polocph = pobokdead['location_phone']

In [128]:
fuldevad = (poloccon + ' ' + pocom + ', ' + pobuil + ' ' + postnuma + ', ' + posub + ', ' + pocity + ' ' + popcd + ', ' + polocph + ', ' + poem + ', ' + poinstr)

In [129]:
fuldevad


Out[129]:
'Test Delivery Location Contact Name Test Delivery Company Name, Test Delivery Building Name 42C Tawa Drive, Albany, Auckland 0632, 6490000000, glenn.dodd@nzpost.co.nz, Test Delivery Location Instructions'

In [ ]:


In [130]:
opcourpo = open('/home/wcmckee/github/nzpostcourbook.json', 'r')

In [131]:
rdcoupo = opcourpo.read()

In [132]:
conrn = rdcoupo.replace('\n', '')

In [133]:
conrn


Out[133]:
'{"carrier":"CourierPost","message_id":"Test Message ID","message_date_time":"2015-05-27T14:19:50","account_number":"91327067","pickup_address":{"pickup_address":{        "location_contact":"Test Pickup Address Location Contact",      "location_phone":"6490000000",      "email_address":"glenn.dodd@nzpost.co.nz",      "company":"Test Pickup Company Name",      "unit_type":"Unit",      "unit_value":"2",      "floor":"5",      "building":"TestPickupBuilding",      "street_number_name":"151 Victoria Street West",      "suburb":"Auckland Central",      "city":"Auckland",      "postcode":"1010",      "instructions":"TestPickupLocationInstructions"},"tracking_references":[{"tracking_reference":"2289791234567801GDD001AS"},{"tracking_reference":"2289791234567802GDD001AS"}], "pickup_date_time": "2015-05-28T17:00:00","quantity":"3"}'

In [ ]:


In [134]:
json.loads(conrn)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-134-56c7d04470ae> in <module>()
----> 1 json.loads(conrn)

/usr/lib/python3.4/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    316             parse_int is None and parse_float is None and
    317             parse_constant is None and object_pairs_hook is None and not kw):
--> 318         return _default_decoder.decode(s)
    319     if cls is None:
    320         cls = JSONDecoder

/usr/lib/python3.4/json/decoder.py in decode(self, s, _w)
    341 
    342         """
--> 343         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    344         end = _w(s, end).end()
    345         if end != len(s):

/usr/lib/python3.4/json/decoder.py in raw_decode(self, s, idx)
    357         """
    358         try:
--> 359             obj, end = self.scan_once(s, idx)
    360         except StopIteration as err:
    361             raise ValueError(errmsg("Expecting value", s, err.value)) from None

ValueError: Expecting ',' delimiter: line 1 column 833 (char 832)

In [86]:
import requests
import xmltodict

In [ ]:


In [ ]:


In [87]:
bitcoinconv = requests.get('http://coinmill.com/rss/BTC_NZD.xml')

In [88]:
xmltodict.parse(bitcoinconv.text)


Out[88]:
OrderedDict([('rss',
              OrderedDict([('@version', '2.0'),
                           ('channel',
                            OrderedDict([('selflink',
                                          'http://coinmill.com/rss/BTC_NZD.xml'),
                                         ('title',
                                          'coinmill.com Currency Rates'),
                                         ('link', 'http://coinmill.com'),
                                         ('description',
                                          'Current rates and calculator for currencies'),
                                         ('language', 'en'),
                                         ('pubDate',
                                          'Fri, 23 Oct 2015 00:00:00 EDT'),
                                         ('lastBuildDate',
                                          'Fri, 23 Oct 2015 22:26:54 EDT'),
                                         ('item',
                                          OrderedDict([('title',
                                                        'Bitcoin and New Zealand Dollar'),
                                                       ('link',
                                                        'http://coinmill.com/BTC_NZD.html'),
                                                       ('description',
                                                        '0.0100 BTC = 4.10 NZD<br/>\n1.00 NZD = 0.0025 BTC<br/>\n<a href="http://coinmill.com/BTC_NZD.html">Converter</a>'),
                                                       ('pubDate',
                                                        'Fri, 23 Oct 2015 00:00:00 EDT'),
                                                       ('guid',
                                                        'coinmill.com BTC_NZD 2015-10-23')]))]))]))])

In [89]:
import os

In [90]:
opschrol = ('/home/wcmckee/ccschol/')

In [91]:
os.listdir(opschrol)


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-91-f40d66ab61c0> in <module>()
----> 1 os.listdir(opschrol)

FileNotFoundError: [Errno 2] No such file or directory: '/home/wcmckee/ccschol/'

In [92]:
opstoreloc = open('/home/wcmckee/github/nzpoststoreloc.json', 'r')


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-92-2a166ab2cfd8> in <module>()
----> 1 opstoreloc = open('/home/wcmckee/github/nzpoststoreloc.json', 'r')

FileNotFoundError: [Errno 2] No such file or directory: '/home/wcmckee/github/nzpoststoreloc.json'

In [93]:
nzpstord = opstoreloc.read()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-93-561c99e7e7dc> in <module>()
----> 1 nzpstord = opstoreloc.read()

NameError: name 'opstoreloc' is not defined

In [151]:
nzpstdj = json.loads(nzpstord)

In [ ]:


In [153]:
nzpstdj['address']


Out[153]:
'261 Karori Road, Karori, Wellington 6012'

Give stores an email address and their own domain, nikola blog


In [155]:
nzpstdj['description']


Out[155]:
'Karori PostShop'

In [156]:
nzpstdj['hours']


Out[156]:
[{'close': '17:00', 'day': 0, 'open': '09:00'},
 {'close': '17:00', 'day': 1, 'open': '09:00'},
 {'close': '17:00', 'day': 2, 'open': '09:00'},
 {'close': '17:00', 'day': 3, 'open': '09:00'},
 {'close': '17:00', 'day': 4, 'open': '09:00'},
 {'closed': True, 'day': 5},
 {'closed': True, 'day': 6}]

In [ ]:
nzpstdj

In [157]:
nzpstdj['lat']


Out[157]:
-41.2849296790303

In [161]:
nzpstdj['lng']


Out[161]:
174.737167954445

In [163]:
nzpstdj['kiwibank_personal_region']


Out[163]:
56

In [ ]:


In [94]:
reqkinrt = requests.get('https://www.kiwibank.co.nz/locations/indexes/northland')

In [95]:
rdkiwiloc = reqkinrt.text

In [96]:
bskiwloc = bs4.BeautifulSoup(rdkiwiloc)


/usr/local/lib/python3.4/dist-packages/bs4/__init__.py:166: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "lxml")

  markup_type=markup_type))

In [97]:
kiwitrre = bskiwloc.find_all('tr')

Parse the locations href string.

id : 58062

slug : dargaville-postshop

title : Dargaville PostShop

lat : 45

long : 130.5323432

ipaddress : 192.168.5.10 (firewall) - list of all machines and ipaddress. Get hostnames from colour-lovers

email : dargaville-postshop@nzpost.co.nz

website : dargaville-postshop.nzpost.co.nz

publickey : SSH-RSA AAAAA345332463454323432

cointwaller : RRSAAEEEE453635435235 (bitcoin wallet) - wallet details

openhours : 0700 2100 7 DAYS


In [ ]:


In [ ]:


In [100]:
kiwitrre


Out[100]:
[<tr>
 <th class="first" scope="col">Name</th>
 <th scope="col">Type</th>
 <th scope="col">Address</th>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58062/dargaville-postshop">Dargaville PostShop</a></td>
 <td>Kiwibank</td>
 <td>80 Victoria Street, Dargaville 0310</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58125/kaikohe-postshop">Kaikohe PostShop</a></td>
 <td>Kiwibank</td>
 <td>144 Broadway, Kaikohe 0405</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58127/kaitaia-postshop">Kaitaia PostShop</a></td>
 <td>Kiwibank</td>
 <td>104 Commerce Street, Kaitaia 0410</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58129/kamo-postshop">Kamo PostShop</a></td>
 <td>Kiwibank</td>
 <td>519 Kamo Road, Kamo 0112</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58132/kawakawa-central-postshop">Kawakawa Central PostShop</a></td>
 <td>Kiwibank</td>
 <td>54 Gillies Street, Kawakawa 0210</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58334/kensington-postshop">Kensington PostShop</a></td>
 <td>Kiwibank</td>
 <td>4 Kensington Avenue, Kensington, Whangarei 0112</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58135/kerikeri-postshop">Kerikeri PostShop</a></td>
 <td>Kiwibank</td>
 <td>6 Hobson Avenue, Kerikeri 0230</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65109/kiwibank-atm/110-onerahi-road-onerahi-whangarei-0110">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>110 Onerahi Road, Onerahi, Whangarei 0110</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65067/kiwibank-atm/144-broadway-kaikohe-0405">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>144 Broadway, Kaikohe 0405</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65116/kiwibank-atm/2-williams-road-paihia-0200">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>2 Williams Road, Paihia 0200</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/58408/kiwibank-atm/25-gillies-street-kawakawa-0210">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>25 Gillies Street, Kawakawa 0210</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/58411/kiwibank-atm/kerikeri-road">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>Kerikeri Road</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65038/kiwibank-atm/80-victoria-street-dargaville-0310">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>80 Victoria Street, Dargaville 0310</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65069/kiwibank-atm/104-commerce-street-kaitaia-0410">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>104 Commerce Street, Kaitaia 0410</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/85975/kiwibank-atm/otaika-shopping-centre-otaika-rd-raumanga">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>Otaika Shopping Centre Otaika Rd,  Raumanga</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65149/kiwibank-atm/1-117-maunu-road-woodhill-whangarei-0110">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>1/117 Maunu Road, Woodhill, Whangarei 0110</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65168/kiwibank-atm/199-rodney-street-wellsford-0900">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>199 Rodney Street, Wellsford 0900</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65071/kiwibank-atm/519-kamo-road-kamo-0112">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>519 Kamo Road, Kamo 0112</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/65172/kiwibank-atm/16-rathbone-street-whangarei-0110">Kiwibank ATM</a></td>
 <td>ATM</td>
 <td>16 Rathbone Street, Whangarei 0110</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/atm/58406/kiwibank-atm-within-new-world-kaikohe-/5-marino-place">Kiwibank ATM (within New World Kaikohe)</a></td>
 <td>ATM</td>
 <td>5 Marino Place</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58156/mangonui-postshop">Mangonui PostShop</a></td>
 <td>Kiwibank</td>
 <td>118 Waterfront Drive, Mangonui 0420</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58118/otaika-postshop">Otaika PostShop</a></td>
 <td>Kiwibank</td>
 <td>136-138 State Highway 1, Raumanga, Whangarei 0110</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58209/paihia-central-postshop">Paihia Central PostShop</a></td>
 <td>Kiwibank</td>
 <td>2 Williams Road, Paihia 0200</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58275/te-mai-west-postshop">Te Mai West PostShop</a></td>
 <td>Kiwibank</td>
 <td>1/117 Maunu Road, Woodhill, Whangarei 0110</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58316/wellsford-postshop">Wellsford PostShop</a></td>
 <td>Kiwibank</td>
 <td>199 Rodney Street, Wellsford 0900</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/business_banking_centre/60802/whangarei-business-banking-centre">Whangarei Business Banking Centre</a></td>
 <td>Business Banking Centre</td>
 <td>120 Bank Street, Whangarei 0110</td>
 </tr>, <tr class="result" style="">
 <td class="first"><a href="/locations/kiwibank/58323/whangarei-central-postshop">Whangarei Central PostShop</a></td>
 <td>Kiwibank</td>
 <td>16 Rathbone Street, Whangarei 0110</td>
 </tr>]

Lookup lat/lng of kiwibank atm/postshop results.


In [ ]:


In [113]:
for kiwiz in kiwitrre:
    print(kiwiz.text)
    kifinl = (kiwiz.find_all('a'))
    
    for kif in kifinl:
        print(kif.text)
        print(kif)


Name
Type
Address


Dargaville PostShop
Kiwibank
80 Victoria Street, Dargaville 0310

Dargaville PostShop
<a href="/locations/kiwibank/58062/dargaville-postshop">Dargaville PostShop</a>

Kaikohe PostShop
Kiwibank
144 Broadway, Kaikohe 0405

Kaikohe PostShop
<a href="/locations/kiwibank/58125/kaikohe-postshop">Kaikohe PostShop</a>

Kaitaia PostShop
Kiwibank
104 Commerce Street, Kaitaia 0410

Kaitaia PostShop
<a href="/locations/kiwibank/58127/kaitaia-postshop">Kaitaia PostShop</a>

Kamo PostShop
Kiwibank
519 Kamo Road, Kamo 0112

Kamo PostShop
<a href="/locations/kiwibank/58129/kamo-postshop">Kamo PostShop</a>

Kawakawa Central PostShop
Kiwibank
54 Gillies Street, Kawakawa 0210

Kawakawa Central PostShop
<a href="/locations/kiwibank/58132/kawakawa-central-postshop">Kawakawa Central PostShop</a>

Kensington PostShop
Kiwibank
4 Kensington Avenue, Kensington, Whangarei 0112

Kensington PostShop
<a href="/locations/kiwibank/58334/kensington-postshop">Kensington PostShop</a>

Kerikeri PostShop
Kiwibank
6 Hobson Avenue, Kerikeri 0230

Kerikeri PostShop
<a href="/locations/kiwibank/58135/kerikeri-postshop">Kerikeri PostShop</a>

Kiwibank ATM
ATM
110 Onerahi Road, Onerahi, Whangarei 0110

Kiwibank ATM
<a href="/locations/atm/65109/kiwibank-atm/110-onerahi-road-onerahi-whangarei-0110">Kiwibank ATM</a>

Kiwibank ATM
ATM
144 Broadway, Kaikohe 0405

Kiwibank ATM
<a href="/locations/atm/65067/kiwibank-atm/144-broadway-kaikohe-0405">Kiwibank ATM</a>

Kiwibank ATM
ATM
2 Williams Road, Paihia 0200

Kiwibank ATM
<a href="/locations/atm/65116/kiwibank-atm/2-williams-road-paihia-0200">Kiwibank ATM</a>

Kiwibank ATM
ATM
25 Gillies Street, Kawakawa 0210

Kiwibank ATM
<a href="/locations/atm/58408/kiwibank-atm/25-gillies-street-kawakawa-0210">Kiwibank ATM</a>

Kiwibank ATM
ATM
Kerikeri Road

Kiwibank ATM
<a href="/locations/atm/58411/kiwibank-atm/kerikeri-road">Kiwibank ATM</a>

Kiwibank ATM
ATM
80 Victoria Street, Dargaville 0310

Kiwibank ATM
<a href="/locations/atm/65038/kiwibank-atm/80-victoria-street-dargaville-0310">Kiwibank ATM</a>

Kiwibank ATM
ATM
104 Commerce Street, Kaitaia 0410

Kiwibank ATM
<a href="/locations/atm/65069/kiwibank-atm/104-commerce-street-kaitaia-0410">Kiwibank ATM</a>

Kiwibank ATM
ATM
Otaika Shopping Centre Otaika Rd,  Raumanga

Kiwibank ATM
<a href="/locations/atm/85975/kiwibank-atm/otaika-shopping-centre-otaika-rd-raumanga">Kiwibank ATM</a>

Kiwibank ATM
ATM
1/117 Maunu Road, Woodhill, Whangarei 0110

Kiwibank ATM
<a href="/locations/atm/65149/kiwibank-atm/1-117-maunu-road-woodhill-whangarei-0110">Kiwibank ATM</a>

Kiwibank ATM
ATM
199 Rodney Street, Wellsford 0900

Kiwibank ATM
<a href="/locations/atm/65168/kiwibank-atm/199-rodney-street-wellsford-0900">Kiwibank ATM</a>

Kiwibank ATM
ATM
519 Kamo Road, Kamo 0112

Kiwibank ATM
<a href="/locations/atm/65071/kiwibank-atm/519-kamo-road-kamo-0112">Kiwibank ATM</a>

Kiwibank ATM
ATM
16 Rathbone Street, Whangarei 0110

Kiwibank ATM
<a href="/locations/atm/65172/kiwibank-atm/16-rathbone-street-whangarei-0110">Kiwibank ATM</a>

Kiwibank ATM (within New World Kaikohe)
ATM
5 Marino Place

Kiwibank ATM (within New World Kaikohe)
<a href="/locations/atm/58406/kiwibank-atm-within-new-world-kaikohe-/5-marino-place">Kiwibank ATM (within New World Kaikohe)</a>

Mangonui PostShop
Kiwibank
118 Waterfront Drive, Mangonui 0420

Mangonui PostShop
<a href="/locations/kiwibank/58156/mangonui-postshop">Mangonui PostShop</a>

Otaika PostShop
Kiwibank
136-138 State Highway 1, Raumanga, Whangarei 0110

Otaika PostShop
<a href="/locations/kiwibank/58118/otaika-postshop">Otaika PostShop</a>

Paihia Central PostShop
Kiwibank
2 Williams Road, Paihia 0200

Paihia Central PostShop
<a href="/locations/kiwibank/58209/paihia-central-postshop">Paihia Central PostShop</a>

Te Mai West PostShop
Kiwibank
1/117 Maunu Road, Woodhill, Whangarei 0110

Te Mai West PostShop
<a href="/locations/kiwibank/58275/te-mai-west-postshop">Te Mai West PostShop</a>

Wellsford PostShop
Kiwibank
199 Rodney Street, Wellsford 0900

Wellsford PostShop
<a href="/locations/kiwibank/58316/wellsford-postshop">Wellsford PostShop</a>

Whangarei Business Banking Centre
Business Banking Centre
120 Bank Street, Whangarei 0110

Whangarei Business Banking Centre
<a href="/locations/business_banking_centre/60802/whangarei-business-banking-centre">Whangarei Business Banking Centre</a>

Whangarei Central PostShop
Kiwibank
16 Rathbone Street, Whangarei 0110

Whangarei Central PostShop
<a href="/locations/kiwibank/58323/whangarei-central-postshop">Whangarei Central PostShop</a>

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [187]:
import xmltodict

In [ ]:


In [198]:
opstorehr = open('/home/wcmckee/github/auspostdelivtime.xml', 'r')

In [199]:
stordz = opstorehr.read()

In [200]:
stordz


Out[200]:
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<DeliveryTimeslots \n    xmlns="http://api.auspost.com.au/DeliveryTimeslots:v1">\n    <DayTimeslot>\n        <Weekday>2</Weekday>\n        <WeekdayDescription>Tuesday</WeekdayDescription>\n        <TimePeriod>\n            <StartTime>07:00:00</StartTime>\n            <EndTime>12:00:00</EndTime>\n            <Duration>PT5H</Duration>\n            <TimePeriodName>AM</TimePeriodName>\n        </TimePeriod>\n        <TimePeriod>\n            <StartTime>12:00:00</StartTime>\n            <EndTime>17:00:00</EndTime>\n            <Duration>PT5H</Duration>\n            <TimePeriodName>PM</TimePeriodName>\n        </TimePeriod>\n        <TimePeriod>\n            <StartTime>09:00:00</StartTime>\n            <EndTime>11:00:00</EndTime>\n            <Duration>PT2H</Duration>\n            <TimePeriodName>9 AM - 11 AM</TimePeriodName>\n        </TimePeriod>\n        <TimePeriod>\n            <StartTime>11:00:00</StartTime>\n            <EndTime>13:00:00</EndTime>\n            <Duration>PT2H</Duration>\n            <TimePeriodName>11 AM - 1 PM</TimePeriodName>\n        </TimePeriod>\n        <TimePeriod>\n            <StartTime>13:00:00</StartTime>\n            <EndTime>15:00:00</EndTime>\n            <Duration>PT2H</Duration>\n            <TimePeriodName>1 PM - 3 PM</TimePeriodName>\n        </TimePeriod>\n        <TimePeriod>\n            <StartTime>15:00:00</StartTime>\n            <EndTime>17:00:00</EndTime>\n            <Duration>PT2H</Duration>\n            <TimePeriodName>3 PM - 5 PM</TimePeriodName>\n        </TimePeriod>\n        <TimePeriod>\n            <StartTime>17:00:00</StartTime>\n            <EndTime>19:00:00</EndTime>\n            <Duration>PT2H</Duration>\n            <TimePeriodName>5 PM - 7 PM</TimePeriodName>\n        </TimePeriod>\n    </DayTimeslot>\n</DeliveryTimeslots>\n'

In [201]:
opsth = xmltodict.parse(stordz)

In [207]:
daydevly = opsth['DeliveryTimeslots']['DayTimeslot']

In [209]:
daydevly['Weekday']


Out[209]:
'2'

In [211]:
daydevly['WeekdayDescription']


Out[211]:
'Tuesday'

In [214]:
datimeper = daydevly['TimePeriod']

In [218]:
numdetim = len(datimeper)

In [225]:
for numd in range(0, numdetim):
    print(datimeper[numd]['StartTime'])
    
    print(datimeper[numd]['EndTime'])


07:00:00
12:00:00
12:00:00
17:00:00
09:00:00
11:00:00
11:00:00
13:00:00
13:00:00
15:00:00
15:00:00
17:00:00
17:00:00
19:00:00

In [141]:
response = requests.get(rmnz, stream=True)
with open(mapdir + fulrmno + '.png', 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response


---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, **response_kw)
    543                                                   timeout=timeout_obj,
--> 544                                                   body=body, headers=headers)
    545 

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
    348         # urllib3.request. It also calls makefile (recv) on the socket.
--> 349         conn.request(method, url, **httplib_request_kw)
    350 

/usr/lib/python3.4/http/client.py in request(self, method, url, body, headers)
   1089         """Send a complete request to the server."""
-> 1090         self._send_request(method, url, body, headers)
   1091 

/usr/lib/python3.4/http/client.py in _send_request(self, method, url, body, headers)
   1127             body = body.encode('iso-8859-1')
-> 1128         self.endheaders(body)
   1129 

/usr/lib/python3.4/http/client.py in endheaders(self, message_body)
   1085             raise CannotSendHeader()
-> 1086         self._send_output(message_body)
   1087 

/usr/lib/python3.4/http/client.py in _send_output(self, message_body)
    923             message_body = None
--> 924         self.send(msg)
    925         if message_body is not None:

/usr/lib/python3.4/http/client.py in send(self, data)
    858             if self.auto_open:
--> 859                 self.connect()
    860             else:

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py in connect(self)
    154     def connect(self):
--> 155         conn = self._new_conn()
    156         self._prepare_conn(conn)

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py in _new_conn(self)
    133             conn = connection.create_connection(
--> 134                 (self.host, self.port), self.timeout, **extra_kw)
    135 

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     63     err = None
---> 64     for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
     65         af, socktype, proto, canonname, sa = res

/usr/lib/python3.4/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    529     addrlist = []
--> 530     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    531         af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

ProtocolError                             Traceback (most recent call last)
/usr/local/lib/python3.4/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    369                     retries=self.max_retries,
--> 370                     timeout=timeout
    371                 )

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, **response_kw)
    596             retries = retries.increment(method, url, error=e, _pool=self,
--> 597                                         _stacktrace=sys.exc_info()[2])
    598             retries.sleep()

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    244             if read is False:
--> 245                 raise six.reraise(type(error), error, _stacktrace)
    246             elif read is not None:

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/packages/six.py in reraise(tp, value, tb)
    308         if value.__traceback__ is not tb:
--> 309             raise value.with_traceback(tb)
    310         raise value

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, **response_kw)
    543                                                   timeout=timeout_obj,
--> 544                                                   body=body, headers=headers)
    545 

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
    348         # urllib3.request. It also calls makefile (recv) on the socket.
--> 349         conn.request(method, url, **httplib_request_kw)
    350 

/usr/lib/python3.4/http/client.py in request(self, method, url, body, headers)
   1089         """Send a complete request to the server."""
-> 1090         self._send_request(method, url, body, headers)
   1091 

/usr/lib/python3.4/http/client.py in _send_request(self, method, url, body, headers)
   1127             body = body.encode('iso-8859-1')
-> 1128         self.endheaders(body)
   1129 

/usr/lib/python3.4/http/client.py in endheaders(self, message_body)
   1085             raise CannotSendHeader()
-> 1086         self._send_output(message_body)
   1087 

/usr/lib/python3.4/http/client.py in _send_output(self, message_body)
    923             message_body = None
--> 924         self.send(msg)
    925         if message_body is not None:

/usr/lib/python3.4/http/client.py in send(self, data)
    858             if self.auto_open:
--> 859                 self.connect()
    860             else:

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py in connect(self)
    154     def connect(self):
--> 155         conn = self._new_conn()
    156         self._prepare_conn(conn)

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py in _new_conn(self)
    133             conn = connection.create_connection(
--> 134                 (self.host, self.port), self.timeout, **extra_kw)
    135 

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     63     err = None
---> 64     for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
     65         af, socktype, proto, canonname, sa = res

/usr/lib/python3.4/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    529     addrlist = []
--> 530     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    531         af, socktype, proto, canonname, sa = res

ProtocolError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
<ipython-input-141-f770437820ab> in <module>()
----> 1 response = requests.get(rmnz, stream=True)
      2 with open(mapdir + fulrmno + '.png', 'wb') as out_file:
      3     shutil.copyfileobj(response.raw, out_file)
      4 del response

/usr/local/lib/python3.4/dist-packages/requests/api.py in get(url, params, **kwargs)
     67 
     68     kwargs.setdefault('allow_redirects', True)
---> 69     return request('get', url, params=params, **kwargs)
     70 
     71 

/usr/local/lib/python3.4/dist-packages/requests/api.py in request(method, url, **kwargs)
     48 
     49     session = sessions.Session()
---> 50     response = session.request(method=method, url=url, **kwargs)
     51     # By explicitly closing the session, we avoid leaving sockets open which
     52     # can trigger a ResourceWarning in some cases, and look like a memory leak

/usr/local/lib/python3.4/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    463         }
    464         send_kwargs.update(settings)
--> 465         resp = self.send(prep, **send_kwargs)
    466 
    467         return resp

/usr/local/lib/python3.4/dist-packages/requests/sessions.py in send(self, request, **kwargs)
    571 
    572         # Send the request
--> 573         r = adapter.send(request, **kwargs)
    574 
    575         # Total elapsed time of the request (approximately)

/usr/local/lib/python3.4/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    413 
    414         except (ProtocolError, socket.error) as err:
--> 415             raise ConnectionError(err, request=request)
    416 
    417         except MaxRetryError as e:

ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

In [142]:
dwg = svgwrite.Drawing(addysvg + fulrmno)
dwg.add(dwg.text(adcit, insert=(0, 0.2), fill='black'))
dwg.save()

In [143]:
opjsf = dict({'FullAddress' : fulladdress, 'AddressMap' : mapdir + fulrmno + '.png', 'AddressLong' : latad, 'AddressLat' : longad, 'AddressText' : addysvg + fulrmno + '.svg', 'delieverwhen' : str(arpick.humanize()), 'fulldeliver' : fuldevad})

In [144]:
opjsf


Out[144]:
{'AddressLat': 170.552,
 'AddressLong': -45.9041,
 'AddressMap': '/home/wcmckee/nzpost/maps/71OregonStreetOceanGroveDunedin9013NewZealand.png',
 'AddressText': '/home/wcmckee/nzpost/addysvg/71OregonStreetOceanGroveDunedin9013NewZealand.svg',
 'FullAddress': '71 Oregon Street, Ocean Grove, Dunedin 9013, New Zealand',
 'delieverwhen': '4 months ago',
 'fulldeliver': 'Test Delivery Location Contact Name Test Delivery Company Name, Test Delivery Building Name 42C Tawa Drive, Albany, Auckland 0632, 6490000000, glenn.dodd@nzpost.co.nz, Test Delivery Location Instructions'}