Skip to content

Instantly share code, notes, and snippets.

View batok's full-sized avatar

Domingo Aguilera batok

  • Consultant
  • Guadalajara, Mexico
  • X @batok
View GitHub Profile
@batok
batok / gist:658657
Created November 1, 2010 18:36
turbomail_gooble.py
def email(to, subject, body, filenames = []):
try:
usuario, password = get_google_account()
source = usuario
if "@" in usuario:
#if usuario.split("@")[-1] == "gmail.com":
#usuario = usuario.split("@")[:-1]
pass
else:
return False
def preview(event):
prt = PrintTable()
regs = []
for anotacion in model.session.query( model.Anotacion ).filter( model.Anotacion.relacion == self.data).order_by( model.Anotacion.fecha_elaboracion.desc()):
regs.append([ anotacion.fecha_local, unicode( anotacion.anotacion )])
prt.data = regs
prt.left_margin = 0.5
prt.set_column = [2.0, 5.0]
prt.label = ["Fecha",u"Anotación"]
Tabla = getattr(model, anotacion.fuente)
def paridad_dolar_dof(dia, mes, year ):
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
url = "http://dof.gob.mx/indicadores_detalle.php?cod_tipo_indicador=158&dfecha={0:02d}%2F{1:02d}%2F{2}&hfecha={0:02d}%2F{1:02d}%2F{2}".format( dia, mes, year)
contents = urlopen(url).read()
soup = BeautifulSoup( contents )
first = soup.find("tr", "Celda 1 ")
second = first.findAll("td")
return second[-1].renderContents()
@batok
batok / paridad.py
Created November 12, 2010 02:23
Esta funcion contacta al web server del Diario Oficial de la Federación y trae la paridad del peso frente al dólar de acuerdo al día.
def paridad_dolar_dof(dia, mes, year ):
""" funcion python para extraer tipo de cambio del colar
segun el Diario Oficial de la Federacion
Autor : @jdaguilera
"""
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
url = "http://dof.gob.mx/indicadores_detalle.php?cod_tipo_indicador=158&dfecha={0:02d}%2F{1:02d}%2F{2}&hfecha={0:02d}%2F{1:02d}%2F{2}".format( dia, mes, year)
contents = urlopen(url).read()
soup = BeautifulSoup( contents )
import time
import boto
from boto.s3.connection import Location
#
# create a couple of strings with our very minimal web content
#
index_html = """
<html>
<head><title>My S3 Webpage</title></head>
@batok
batok / mako_pisa_example.py
Created February 25, 2011 16:54
En example of using mako and pisa to generate pdf. Python 2.6 o 2.7 needed $ virtualenv --no-site-packages yourenv $ cd yourenv $ source bin/activate $pip install mako pypdf html5lib reportlab pisa $python mako_pisa_example.py
import os, sys, subprocess
from mako.template import Template
from mako.runtime import Context
from cStringIO import StringIO #needed as buffer for mako
try:
from mako.util import FastEncodingBuffer #new kind of buffer that is faster ( version 0.4) than StringIO
except:
pass
from ho import pisa as pisa
@batok
batok / foo.html
Created February 25, 2011 17:02
A mako template used for testing http://gist.github.com/844077
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
html {
font-family: "Verdana";
font-size: 8px;
}
</style>
</head>
<body>
@batok
batok / gist:869678
Created March 14, 2011 19:12
celeryconfig.py
from celery.schedules import crontab
CELERY_IMPORTS = ( "tasks", )
CELERY_RESULT_BACKEND = "redis"
REDIS_HOST = "localhost"
REDIS_PORT = 6379
REDIS_DB = 8
REDIS_CONNECT_RETRY = True
BROKER_BACKEND = "redis"
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)
@batok
batok / celery_task.py
Created October 21, 2011 17:19
When using clear_mappers is executed , celery mappings also got cleared
@task
def columns( table = "usuarios"):
try:
t = Table( table , metadata, autoload = True, autoload_with = engine)
try:
clear_mappers() # this clean all previous mappers if any
mapper( Dummy, t )
except:
traceback.print_exc()
return "error"