Created
March 14, 2011 19:21
-
-
Save batok/869691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery.task import task | |
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, select | |
from sqlalchemy.orm import sessionmaker, mapper, clear_mappers | |
import traceback | |
uri = "mssql://{}:{}@{}".format("user", "password", "DSNwhatever") | |
engine = create_engine( uri ) | |
session = sessionmaker( bind = engine )() | |
metadata = MetaData() | |
gixanip_table = Table("gixanip", metadata, autoload = True, autoload_with = engine) | |
class Dummy(object): | |
pass | |
@task | |
def suma( x, y ): | |
print "la suma es " | |
return x + y | |
@task | |
def resta(x,y): | |
print "la resta es " | |
return x - y | |
@task | |
def cuantos_registros(table = "usuarios"): | |
t = Table( table, metadata, autoload = True, autoload_with = engine ) | |
try: | |
clear_mappers() # this will clean all previous mappers if any | |
mapper( Dummy, t ) | |
except: | |
traceback.print_exc() | |
r = "{} records".format( session.query( Dummy ).count() ) | |
print r | |
return r | |
@task( ignore_result = True ) | |
def actualiza_precios(): | |
c = engine.connect().connection | |
sql = """ | |
delete from gixpreciosoferta | |
""" | |
cu = c.cursor() | |
sql2 = """ | |
insert into gixpreciosoferta (fk_etapa, fk_oferta, fk_precio) | |
select o.fk_etapa, o.oferta, p.id from ofertas_compra o | |
join gixpreciosetapa p on o.precio = p.precio and | |
o.preciosustentable = p.sustentable | |
where o.fk_etapa = 48 and p.visible = 1 and p.id <> 10 order by p.tipo | |
""" | |
cu.execute( sql ) | |
c.commit() | |
print "haciendo eliminacion de registros en gixpreciosoferta" | |
cu.execute( sql2 ) | |
print "reconstruyendo gixpreciosoferta" | |
cu.close() | |
c.commit() | |
print "precios de ofertas actualizados" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment