Esempio n. 1
0
 def customers_acct_creds(self, customerID, accountID):
     """r.data = <loginForm>
       <loginField>
         <id>101732001</id>
         <name>Banking Userid</name>
         <value>USERNAME</value>
         <mask>false</mask>
         <displayOrder>1</displayOrder>
       </loginField>
       <loginField>
         <id>101732002</id>
         <name>Banking Password</name>
         <value></value>
         <mask>true</mask>
         <displayOrder>2</displayOrder>
       </loginField>
     </loginForm>
     """
     
     url = "{}/v1/customers/{}/accounts/{}/loginForm".format(url, customerId, accountId)
     r = req.get(url, headers=self.headers)
     if r.status_code == 200:
         return xmtd.parse(r.data)
     else:
         raise ValueError('r.status_code returned: {}'.format(r.status_code))
Esempio n. 2
0
 def recuperar_acuse(self, uuid):
     transaccion_id = get_epoch()
     user_token = self._get_token(transaccion_id)
     if not user_token:
         return ''
     method = 'recuperar_acuse'
     data = {
         'uuid': uuid,
         'rfc': self.rfc,
         'user_token': user_token,
         'transaccion_id': transaccion_id,
     }
     data = self._SOAP[method].format(**data).encode('utf-8')
     headers = {
         'SOAPAction': '"{}"'.format(self._ACTIONS[method]),
         'Content-length': len(data),
         'Content-type': 'text/xml; charset="UTF-8"'
     }
     s = Session()
     req = Request('POST', self.WS['cancelacion'], data=data, headers=headers)
     prepped = req.prepare()
     try:
         response = s.send(prepped, timeout=TIMEOUT)
         res = xml2dict.parse(response.text)
         ok, res = self._check_fault(res)
         if ok:
             return ''
         return res['RespuestaRecuperarAcuse']['AcuseXML'].replace("'", '"')
     except exceptions.Timeout:
         self.error = 'Tiempo de espera agotado'
         print (self.error)
     except Exception as e:
         print ('Recuperar Acuse', e)
     return
Esempio n. 3
0
 def get_estatus(self, data):
     data['emisor_rfc'] = escape(data['emisor_rfc'])
     data['receptor_rfc'] = escape(data['receptor_rfc'])
     data = self._soap.format(**data).encode('utf-8')
     headers = {
         'SOAPAction': '"http://tempuri.org/IConsultaCFDIService/Consulta"',
         'Content-length': len(data),
         'Content-type': 'text/xml; charset="UTF-8"'
     }
     s = Session()
     s.verify = False
     req = Request('POST', self._webservice, data=data, headers=headers)
     prepped = req.prepare()
     try:
         response = s.send(prepped, timeout=5)
         res = xml2dict.parse(response.text)
         ok, res = self._check_fault(res)
         if ok:
             return False
         self.msg = res['ConsultaResponse']['ConsultaResult']['a:Estado']
         return True
     except exceptions.Timeout:
         self.error = 'Tiempo de espera agotado'
     except Exception as e:
         print (e)
     return False
Esempio n. 4
0
 def timbra_xml(self, xml, id_original=0):
     user_token = self._get_token(id_original)
     if not user_token:
         return ''
     method = 'timbra_xml'
     data = {
         'xml': escape(xml.encode('ascii', 'xmlcharrefreplace').decode('utf-8')),
         'rfc': self.rfc,
         'user_token': user_token,
         'transaccion_id': id_original,
     }
     data = self._SOAP[method].format(**data).encode('utf-8')
     headers = {
         'SOAPAction': '"{}"'.format(self._ACTIONS[method]),
         'Content-length': len(data),
         'Content-type': 'text/xml; charset="UTF-8"'
     }
     s = Session()
     req = Request('POST', self.WS['timbrado'], data=data, headers=headers)
     prepped = req.prepare()
     try:
         response = s.send(prepped, timeout=TIMEOUT)
         res = xml2dict.parse(response.text)
         ok, res = self._check_fault(res)
         if ok:
             return ''
         return res['RespuestaTimbraXML']['ComprobanteXML']['DatosXML']
     except exceptions.Timeout:
         self.error = 'Tiempo de espera agotado'
     except Exception as e:
         self.error = str(e)
         log.debug(e)
     return ''
Esempio n. 5
0
    def estatus_cuenta(self):
        transaccion_id = get_epoch()
        user_token = self._get_token()
        if not user_token:
            return ''

        method = 'estatus_cuenta'
        data = {
            'rfc': self.rfc,
            'user_token': user_token,
            'transaccion_id': transaccion_id
        }
        data = self._SOAP[method].format(**data).encode('utf-8')
        headers = {
            'SOAPAction': '"{}"'.format(self._ACTIONS[method]),
            'Content-length': len(data),
            'Content-type': 'text/xml; charset="UTF-8"'
        }
        s = Session()
        req = Request('POST', self.WS['clientes'], data=data, headers=headers)
        prepped = req.prepare()
        try:
            response = s.send(prepped, timeout=TIMEOUT)
            res = xml2dict.parse(response.text)
            ok, res = self._check_fault(res)
            if ok:
                return ''
            return res['RespuestaEstatusCuenta']['Estatus']
        except exceptions.Timeout:
            self.error = 'Tiempo de espera agotado'
            print (self.error)
        except Exception as e:
            print ('Estatus Cuenta', e)
            return ''
Esempio n. 6
0
 def _get_token(self, transaccion_id=0):
     if not transaccion_id:
         transaccion_id = get_epoch()
     method = 'obtener_token'
     data = {
         'rfc': self.rfc,
         'transaccion_id': transaccion_id
     }
     data = self._SOAP[method].format(**data).encode('utf-8')
     headers = {
         'SOAPAction': '"{}"'.format(self._ACTIONS[method]),
         'Content-length': len(data),
         'Content-type': 'text/xml; charset="UTF-8"'
     }
     s = Session()
     req = Request('POST', self.WS['seguridad'], data=data, headers=headers)
     prepped = req.prepare()
     try:
         response = s.send(prepped, timeout=TIMEOUT)
         res = xml2dict.parse(response.text)
         ok, res = self._check_fault(res)
         if ok:
             return ''
         token = res['RespuestaObtenerToken']['Token']
         s = '{}|{}'.format(self.ID_INTEGRADOR, token)
         user_token = hashlib.sha1(s.encode()).hexdigest()
         return user_token
     except exceptions.Timeout:
         self.error = 'Tiempo de espera agotado'
         log.debug(self.error)
         print (self.error)
     except exceptions.RequestException as e:
         log.debug(e)
         print ('TOKEN', e)
     return ''
Esempio n. 7
0
 def get_customer_accts(self, customerID):
     """return all accounts a customer has"""
     
     url = "{}/v1/customers/{}/accounts".format(url, customerID)
     r = req.get(url, headers=self.headers)
     if r.status_code == 200:
         return xmtd.parse(r.data)
     else:
         raise ValueError('get_customer_acct returned {}: {}'.format(r.status_code, r.data))
Esempio n. 8
0
 def get_customer_acct(self, customerID, acctID):
     """ this is a customer account number at an institution not the customer themselves"""
     
     url = "{}/v1/customers/{}/accounts/{}".format(url, customerID, accountID)
     r = req.get(url, headers=self.headers)
     if r.status_code == 200:
         return xmtd.parse(r.data)
     else:
         raise ValueError('get_customer_acct returned {}: {}'.format(r.status_code, r.data))
Esempio n. 9
0
 def get_customers(self, search='*', start=1, limit=25, type=configs['type']):
     """returns all your current customers"""
     url = '{}/v1/customers'.format(config['finicity_url'])
     data = {start:start,
             search:search,
             limit:limit,
             type:type
             }
     r = req.get(url, data=data)
     if r.status_code == 200:
         return xmtd.parse(r.data)
Esempio n. 10
0
  def get_url(self, url, params):
    params["format"] = self.format
    params["version"] = self.version
    params["apiKey"] = self.key

    if self.token is not None:
      params["token"] = self.token
    data = urllib.urlencode(params)
    try:
	print self.protocol + self.host + url + "?" + data
    	f = urllib.urlopen(self.protocol + self.host + url + "?" + data)
	print f.read()
    	x = xml2dict.parse(f.read())
    	return x[x.keys()[0]]
    except urllib2.HTTPError as e:
	error = e.read()
	print error
	return {}
Esempio n. 11
0
 def cancela_multiple(self, uuid):
     transaccion_id = get_epoch()
     user_token = self._get_token(transaccion_id)
     if not user_token:
         return ''
     guid = '<guid xmlns="http://Ecodex.WS.Model/2011/CFDI">{}</guid>'
     if isinstance(uuid, str):
         uuids = guid.format(uuid)
     else:
         uuids = ''.join([guid.format(u) for u in uuid])
     method = 'cancela_multiple'
     data = {
         'uuids': uuids,
         'rfc': self.rfc,
         'user_token': user_token,
         'transaccion_id': transaccion_id,
     }
     data = self._SOAP[method].format(**data).encode('utf-8')
     headers = {
         'SOAPAction': '"{}"'.format(self._ACTIONS[method]),
         'Content-length': len(data),
         'Content-type': 'text/xml; charset="UTF-8"'
     }
     s = Session()
     req = Request('POST', self.WS['cancelacion'], data=data, headers=headers)
     prepped = req.prepare()
     try:
         response = s.send(prepped, timeout=TIMEOUT)
         res = xml2dict.parse(response.text)
         ok, res = self._check_fault(res)
         if ok:
             return ''
         res = res['RespuestaCancelaMultiple']['Resultado']['ResultadoCancelacion']
         if not isinstance(res, list):
             res = [res]
         return res
     except exceptions.Timeout:
         self.error = 'Tiempo de espera agotado'
     except Exception as e:
         print ('Cancelacion', e)
     return
Esempio n. 12
0
 def obtener_timbrado(self, id_original=0, uuid=''):
     transaccion_id = get_epoch()
     user_token = self._get_token()
     if not user_token:
         return ''
     if uuid:
         id_original = 0
     method = 'obtener_timbrado'
     data = {
         'rfc': self.rfc,
         'user_token': user_token,
         'transaccion_id': transaccion_id,
         'transaccion_original': id_original,
         'uuid': uuid,
     }
     data = self._SOAP[method].format(**data).encode('utf-8')
     headers = {
         'SOAPAction': '"{}"'.format(self._ACTIONS[method]),
         'Content-length': len(data),
         'Content-type': 'text/xml; charset="UTF-8"'
     }
     s = Session()
     req = Request('POST', self.WS['timbrado'], data=data, headers=headers)
     prepped = req.prepare()
     try:
         response = s.send(prepped, timeout=TIMEOUT)
         res = xml2dict.parse(response.text)
         ok, res = self._check_fault(res)
         if ok:
             return ''
         return res['RespuestaObtenerTimbrado']['ComprobanteXML']['DatosXML']
     except exceptions.Timeout:
         self.error = 'Tiempo de espera agotado'
         print (self.error)
     except Exception as e:
         print ('Obtener Timbrado', e)
         return ''
Esempio n. 13
0
#!/usr/bin/python3
import xml2dict
import json

# idential to https://github.com/martinblech/xmltodict
print(
    json.dumps(xml2dict.parse('''
    <mydocument has="an attribute">
        <and>
            <many>elements</many>
            <many>more elements</many>
        </and>
        <plus a="complex">
            element as well
        </plus>
    </mydocument>
'''),
               indent=4))

# default functionality
xml = '''
    <list>
        <items>
            <item id="1">A</item>
            <item id="2">B</item>
            <item id="3">C</item>
            <item id="4">D</item>
        </items>
        <date>1.1.2019</date>
    </list>
'''
Esempio n. 14
0
                                  db="bd_reto")
except mysql.connector.Error as er:
    if er.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print("Usuario o contraseña incorrecto.")
        print('')
    elif er.errno == errorcode.ER_BAD_DB_ERROR:
        print("No existe la Base de Datos indicada.")
        print('')
    else:
        print(er)
else:
    exe = cnx.cursor(dictionary=True)

    #XML to dict
    xml = open('extra/downOutput.xml')
    xmldict = xml2dict.parse(xml.read())

    print('--Valores a insertar--')
    for item in xmldict["xml"]["item"]:
        print(item["id_ocM"], item["proveedorM"], item["productoM"],
              item["descproductoM"], item["cantidadM"], item["fechaentregaM"],
              item["precioM"])
        #Asignacion a variables
        data = {
            'id_oc': int(item["id_ocM"]),
            'proveedor': item["proveedorM"],
            'producto': item["productoM"],
            'descproducto': item["descproductoM"],
            'cantidad': int(item["cantidadM"]),
            'fechaentrega': item["fechaentregaM"],
            'precio': float(item["precioM"])
Esempio n. 15
0
def OSSerializeBinary(xml_content):
    parsed = xml2dict.parse(file)
    s = Serialize()
    _OSSerializeBinary(s, parsed)
    return s.binary()