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 / prueba_fecha.py
Created January 13, 2012 16:34
Prueba de control de fecha de wx
import wx
from datetime import datetime
class Frame( wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1, "Probando Fecha , wx = {}".format(wx.__version__), size = ( 200,200))
self.panel = wx.Panel(self, -1)
f = datetime.today()
hoy = wx.DateTimeFromDMY(f.day, f.month - 1, f.year)
fecha = wx.DatePickerCtrl( self.panel, -1, wx.DefaultDateTime, wx.DefaultPosition, [140,-1], wx.DP_DROPDOWN|wx.DP_ALLOWNONE )
@batok
batok / ses_test.py
Created November 4, 2011 19:01
A test of ses "AWS" service from python using boot
"""
do ...
pip install boto, turbomail
echo "just a test" > README.txt
... first
"""
import sys
from boto import connect_ses
FROM = "foo@acme.com"
TO = "bar@acme.com"
@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"
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 / 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"
@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 / 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
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 / 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 )
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()