-
Notifications
You must be signed in to change notification settings - Fork 14
/
glasses_guide.py
85 lines (62 loc) · 2.62 KB
/
glasses_guide.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
75
76
77
78
79
80
81
82
83
84
85
from suds.client import Client
import sys
import argparse
import json
from suds.xsd.doctor import Import, ImportDoctor
from suds.sax.element import Element
from suds.sax.attribute import Attribute
# This script is an example script to lookup vehicle information from Glasses Guide.
# Glases Guide is a paid subscription service by Autovista Group
# (http://www.autovistagroup.com/) and requires a username and password.
#
# In this example, we input an NVIC identifier and retrieve details like vehicle
# make, model, year, and value via a SOAP-based web service.
#
# This script uses suds (0.4) and requests (2.18.4) python libraries
def get_gg_details(nvic, username, password):
url = "http://eurotaxglasswebservices.com.au/GeneralGGWebService.asmx?WSDL"
imp = Import('http://www.w3.org/2001/XMLSchema',
location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://microsoft.com/webservices/')
client = Client(url, doctor=ImportDoctor(imp))
code = Element('Username').setText(username)
pwd = Element('Password').setText(password)
reqsoapheader = Element('AuthHeader').insert(code)
reqsoapheader = reqsoapheader.append(pwd)
reqsoap_attribute = Attribute('xmlns', "http://microsoft.com/webservices/")
reqsoapheader.append(reqsoap_attribute)
client.set_options(soapheaders=reqsoapheader)
# print client # shows the details of this service
result = client.service.GetDetailsSpecificationAll('A', nvic)
details = result.diffgram.NewDataSet.DataSepcDetails
# print details
return details
def lookup_value(nvic):
details = get_gg_details(nvic, '<gg_username>', '<gg_password>')
make = details.ManufacturerName
model = details.FamilyName
variant = details.VariantName
year = details.YearCreate
value = details.Trade
return {'fieldValues': {'vehicle_make': [make],
'vehicle_model': [model],
'vehicle_varient': [variant],
'vehicle_year': [year],
'gg_value': [value],
}
}
def lambda_handler(event, context):
print event
reg_num = event['body-json'][
'exposureCharacteristics']['fieldValues']['nvic'][0]
return lookup_value(reg_num)
def main(argv):
parser = argparse.ArgumentParser(
description='Lookup NVIC Details Test Application')
# Sample NVIC: "123"
parser.add_argument('-n', '--nvic', required=True)
args = parser.parse_args(argv)
value = lookup_value(args.nvic)
print json.dumps(value)
if __name__ == '__main__':
main(sys.argv[1:])