Skip to content

Instantly share code, notes, and snippets.

@dafma
Last active August 8, 2019 22:46
Show Gist options
  • Save dafma/a9e776981d39f75c8ca47275ecd29f76 to your computer and use it in GitHub Desktop.
Save dafma/a9e776981d39f75c8ca47275ecd29f76 to your computer and use it in GitHub Desktop.
""" Guarda un dato como xml
xml = "<myxmldata/>".encode()
f = open("myxmlfile.xml", "wb")
f.write(xml)
f.close()
"""
import pyodbc
# Specifying the ODBC driver, server name, database, etc. directly
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=LPGHCONSULTORES;UID=sa;PWD=')
cursor = cnxn.cursor()
cursor.execute("select movid, documento from cfd where timbrado='1' ")
rows = cursor.fetchall()
for row in rows:
xml = row.documento.encode()
f = open("C:\\basurero\\%s.xml" % row.movid, "wb")
f.write(xml)
f.close()
print("creado")
"""
from sqlalchemy import create_engine
engine = create_engine('mssql+pymssql://sa:@localhost:52865/LPGCONSULTORES')
conn = engine.connect()
rows = conn.execute("select name FROM sys.databases;")
for row in rows:
print(row["name"])
"""
""" Guarda un dato como xml
xml = "<myxmldata/>".encode()
f = open("myxmlfile.xml", "wb")
f.write(xml)
f.close()
"""
import pyodbc
# Specifying the ODBC driver, server name, database, etc. directly
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=ALYSAB;UID=sa;PWD=')
cursor = cnxn.cursor()
#cursor.execute("select movid, documento from cfd where timbrado='1' and moduloid=79247")
cursor.execute("""select LTRIM(RTRIM(cxc.Cliente))+' '+cfd.movid as rds, cfd.documento from cfd join cxc on cfd.ModuloID= cxc.id where cfd.timbrado='1' and cfd.moduloid in (78934,
78977,
79792,
79852)""")
rows = cursor.fetchall()
for row in rows:
xml = row.documento.encode()
f = open("C:\\basurero\\%s.xml" % row.rds, "wb")
f.write(xml)
f.close()
print("creado")
"""
from sqlalchemy import create_engine
engine = create_engine('mssql+pymssql://sa:@localhost:52865/LPGCONSULTORES')
conn = engine.connect()
rows = conn.execute("select name FROM sys.databases;")
for row in rows:
print(row["name"])
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment