-
Notifications
You must be signed in to change notification settings - Fork 0
/
XMLparse_test.py
30 lines (24 loc) · 13.6 KB
/
XMLparse_test.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
class XMLParser(object):
def __init__(self, response): # receives a response as a string or b'string
self.response = response
self.xml_ns = "{http://api.namecheap.com/xml.response}"
self.ssl_tag = 'SSL' # name of the tag with SSL details from xml tree
self.tag_full = self.xml_ns + self.ssl_tag
def root_iter(self, tag):
cert_available = []
# fromstring() parses XML from a string directly into an Element,
# which is the root element of the parsed tree.
resp = b'<?xml version="1.0" encoding="UTF-8"?>\n<ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">\n <Errors/>\n <Warnings/>\n <RequestedCommand>namecheap.ssl.getList</RequestedCommand>\n <CommandResponse Type="namecheap.ssl.getList">\n <SSLListResult>\n <SSL CertificateID="840905" HostName="badhat.com" SSLType="quickssl premium" PurchaseDate="09/14/2015" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="inprogress" ProviderOrderID="2089319" Years="1"/>\n <SSL CertificateID="843251" HostName="www.example.com" SSLType="positivessl" PurchaseDate="11/24/2015" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchaseerror" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="844245" HostName="" SSLType="true businessid with ev multi domain" PurchaseDate="12/18/2015" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="844369" HostName="" SSLType="rapidssl" PurchaseDate="12/24/2015" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="845267" HostName="" SSLType="secure site" PurchaseDate="02/19/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="845558" HostName="bzumby.com" SSLType="premiumssl" PurchaseDate="03/17/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="24209869" Years="1"/>\n <SSL CertificateID="845959" HostName="dropqwer.co" SSLType="positivessl" PurchaseDate="04/07/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="24001950" Years="1"/>\n <SSL CertificateID="857081" HostName="www.nohopeindeeed.me" SSLType="quickssl premium" PurchaseDate="06/20/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="inprogress" ProviderOrderID="2212867" Years="1"/>\n <SSL CertificateID="859044" HostName="dummiqe.co" SSLType="positivessl" PurchaseDate="09/26/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="23865792" Years="1"/>\n <SSL CertificateID="859047" HostName="dummiqe.co" SSLType="quickssl premium" PurchaseDate="09/27/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="2266039" Years="1"/>\n <SSL CertificateID="859057" HostName="dummiqe.co" SSLType="quickssl premium" PurchaseDate="09/27/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="2266154" Years="1"/>\n <SSL CertificateID="859058" HostName="www.nohopeindeeed.me" SSLType="quickssl premium" PurchaseDate="09/28/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="2266515" Years="1"/>\n <SSL CertificateID="859063" HostName="dropqwer.co" SSLType="quickssl premium" PurchaseDate="09/28/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="2266523" Years="1"/>\n <SSL CertificateID="859064" HostName="dropqwer.co" SSLType="quickssl premium" PurchaseDate="09/28/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="2266524" Years="1"/>\n <SSL CertificateID="859073" HostName="example.com" SSLType="quickssl premium" PurchaseDate="09/28/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="inprogress" ProviderOrderID="2266562" Years="1"/>\n <SSL CertificateID="859271" HostName="bestshampoonconditioner.com" SSLType="positivessl" PurchaseDate="10/15/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="cancelled" ProviderOrderID="24525689" Years="1"/>\n <SSL CertificateID="859323" HostName="bestkeywordtoolforlocalgoogleyahooyoutubeamazonebayseo.com" SSLType="positivessl" PurchaseDate="10/21/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="30593240" Years="1"/>\n <SSL CertificateID="866888" HostName="sslss.party" SSLType="positivessl" PurchaseDate="11/11/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="126082773" Years="1"/>\n <SSL CertificateID="866971" HostName="domain.com" SSLType="positivessl multi domain" PurchaseDate="11/14/2016" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="168362245" Years="1"/>\n <SSL CertificateID="868772" HostName="example.com" SSLType="positivessl" PurchaseDate="01/31/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="118848102" Years="1"/>\n <SSL CertificateID="868992" HostName="" SSLType="positivessl wildcard" PurchaseDate="02/09/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="869313" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="02/23/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="74640546" Years="1"/>\n <SSL CertificateID="869800" HostName="bzumby.com" SSLType="positivessl" PurchaseDate="03/13/2017" ExpireDate="3/21/2019" ActivationExpireDate="" IsExpiredYN="false" Status="active" ProviderOrderID="128769106" Years="3"/>\n <SSL CertificateID="869801" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="03/13/2017" ExpireDate="6/7/2020" ActivationExpireDate="" IsExpiredYN="false" Status="replaced" ProviderOrderID="56563257" Years="3"/>\n <SSL CertificateID="870901" HostName="bzumby.com" SSLType="positivessl" PurchaseDate="04/03/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="143906411" Years="1"/>\n <SSL CertificateID="870902" HostName="example.com" SSLType="positivessl" PurchaseDate="04/03/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="118848054" Years="1"/>\n <SSL CertificateID="872051" HostName="example.com" SSLType="positivessl" PurchaseDate="04/18/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="118340435" Years="1"/>\n <SSL CertificateID="872052" HostName="www.q.de" SSLType="positivessl" PurchaseDate="04/18/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="118328803" Years="1"/>\n <SSL CertificateID="874836" HostName="example.com" SSLType="instantssl pro" PurchaseDate="05/17/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="118328322" Years="1"/>\n <SSL CertificateID="886672" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="06/01/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="73091199" Years="1"/>\n <SSL CertificateID="887848" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="06/13/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="74618041" Years="1"/>\n <SSL CertificateID="887851" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="06/13/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="74624834" Years="1"/>\n <SSL CertificateID="887852" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="06/13/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="74625283" Years="1"/>\n <SSL CertificateID="897740" HostName="exampling.com" SSLType="positivessl" PurchaseDate="08/28/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="88459938" Years="1"/>\n <SSL CertificateID="931746" HostName="sslss.party" SSLType="positivessl" PurchaseDate="12/06/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="109381299" Years="1"/>\n <SSL CertificateID="933296" HostName="" SSLType="ev ssl" PurchaseDate="12/28/2017" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="938003" HostName="" SSLType="instantssl" PurchaseDate="01/30/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="938328" HostName="" SSLType="positivessl multi domain" PurchaseDate="01/31/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="950857" HostName="bzumby.com" SSLType="ev ssl" PurchaseDate="02/15/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="143907090" Years="1"/>\n <SSL CertificateID="950858" HostName="example.com" SSLType="premiumssl" PurchaseDate="02/15/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="125181396" Years="1"/>\n <SSL CertificateID="953876" HostName="domain.com" SSLType="positivessl multi domain" PurchaseDate="02/28/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="167948663" Years="1"/>\n <SSL CertificateID="953954" HostName="sslss.party" SSLType="positivessl" PurchaseDate="02/28/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="125181669" Years="1"/>\n <SSL CertificateID="953963" HostName="sslss.party" SSLType="essentialssl" PurchaseDate="02/28/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="125182623" Years="1"/>\n <SSL CertificateID="954061" HostName="bzumby.com" SSLType="positivessl" PurchaseDate="02/28/2018" ExpireDate="2/28/2019" ActivationExpireDate="" IsExpiredYN="false" Status="active" ProviderOrderID="125187521" Years="1"/>\n <SSL CertificateID="955559" HostName="bzumby.com" SSLType="positivessl multi domain" PurchaseDate="03/02/2018" ExpireDate="3/2/2019" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="125564651" Years="1"/>\n <SSL CertificateID="955560" HostName="bzumby.com" SSLType="positivessl multi domain" PurchaseDate="03/02/2018" ExpireDate="3/2/2019" ActivationExpireDate="" IsExpiredYN="false" Status="active" ProviderOrderID="125564651" Years="1"/>\n <SSL CertificateID="1035469" HostName="" SSLType="positivessl free" PurchaseDate="08/27/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="1039196" HostName="areyouever.me" SSLType="positivessl" PurchaseDate="03/13/2017" ExpireDate="12/14/2020" ActivationExpireDate="" IsExpiredYN="false" Status="active" ProviderOrderID="56563257" Years="3"/>\n <SSL CertificateID="1050133" HostName="bzumby.com" SSLType="ev ssl" PurchaseDate="10/24/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="purchased" ProviderOrderID="181089897" Years="1"/>\n <SSL CertificateID="1050922" HostName="" SSLType="positivessl" PurchaseDate="10/27/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="1050923" HostName="" SSLType="positivessl" PurchaseDate="10/27/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="1050924" HostName="" SSLType="positivessl" PurchaseDate="10/27/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="1050925" HostName="" SSLType="positivessl" PurchaseDate="10/27/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n <SSL CertificateID="1050926" HostName="" SSLType="positivessl" PurchaseDate="10/27/2018" ExpireDate="" ActivationExpireDate="" IsExpiredYN="false" Status="newpurchase" ProviderOrderID="" Years="1"/>\n </SSLListResult>\n <Paging>\n <TotalItems>54</TotalItems>\n <CurrentPage>1</CurrentPage>\n <PageSize>100</PageSize>\n </Paging>\n </CommandResponse>\n <Server>611e993f2605</Server>\n <GMTTimeDifference>--5:00</GMTTimeDifference>\n <ExecutionTime>0.338</ExecutionTime>\n</ApiResponse>\n'
# tree_root = ET.fromstring(resp)
tree_root = ET.fromstring(self.response)
for i in tree_root.iter(tag):
cert_data = i.attrib # dict with cert data like 'SSLType': 'ev ssl'
# to get certs we need only
if (not bool(cert_data['HostName']) and # if HostName is empty (literally: if not False == True)
cert_data['SSLType'] == 'positivessl' and # non free, positiveSSL only
cert_data['IsExpiredYN'] == 'false' and # non-expired (this is unnecessary but can save from failing)
not bool(cert_data['ActivationExpireDate']) and
cert_data['Status'] == 'newpurchase' and # only non-activated certs
cert_data['Years'] == '1'): # only 1year certs
cert_available.append(cert_data['CertificateID']) # add ID to list
return cert_available