This file contains 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
def guess_time(s): | |
""" | |
>>> guess_time('20:00') | |
(20, 0) | |
>>> guess_time('23:59') | |
(23, 59) | |
>>> guess_time('20:00foo') | |
(20, 0) | |
>>> guess_time('9pm') |
This file contains 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
### MODEL | |
from gluon.tools import * | |
######################################################################## | |
# Sobrecarga do método send da classe Mail | |
######################################################################## | |
class Mail(Mail): | |
def send( | |
self, |
This file contains 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
# -*- coding: utf-8 -*- | |
# this file is released under public domain and you can use without limitations | |
######################################################################### | |
## This scaffolding model makes your app work on Google App Engine too | |
######################################################################### | |
if request.env.web2py_runtime_gae: # if running on Google App Engine | |
db = DAL('gae') # connect to Google BigTable | |
session.connect(request, response, db = db) # and store sessions and tickets there |
This file contains 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
#python rocks! | |
import os | |
from urllib import urlretrieve | |
for item in ['http://coelba.sma-se.com.br/pdfs/055ECD0A.pdf','http://coelba.sma-se.com.br/pdfs/11E2C46D.pdf']: | |
os.system('mkdir %s' % item.split('/')[-1].replace('.pdf','')) | |
urlretrieve(item,'/home/rochacbruno/%s/%s' % (item.split('/')[-1].replace('.pdf',''), item.split('/')[-1])) | |
This file contains 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
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
import os | |
import sys | |
import unittest | |
sys.path.append(os.path.realpath('../../../')) | |
from gluon import * |
This file contains 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
import myapi | |
orm = myapi.ORM() #database created, migrated, defined | |
company = orm.new_company(name='Google Inc.') #New company created or validation errors returned | |
client = orm.new_client(name='John', company_id=company.id) # new client created | |
# you could call inline | |
client = orm.new_client(name='John', company_id=orm.new_company('Google Inc.')) |
This file contains 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
#--*-- coding: UTF-8 --*-- | |
class Humano(object): | |
"""Human Being""" | |
def __init__(self, nome, pai=None, mae=None): | |
print "alguém fez besteira e colocou mais um ser Humano no mundo \n" | |
self.nome = nome | |
self.pai = pai | |
self.mae = mae | |
self.filhos = 0 |
This file contains 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
#encoding: utf-8 | |
class Humano(object): | |
"""Human Being""" | |
def __init__(self, nome, pai=None, mae=None): | |
print "alguem fez besteira e colocou mais um ser Humano no mundo \n" | |
self.nome = nome | |
self.pai = pai | |
self.mae = mae |
This file contains 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
import subprocess | |
echo = subprocess.Popen(['echo','123'], | |
stdout=subprocess.PIPE, | |
) | |
sudo = subprocess.Popen(['sudo','-S','iptables','-L'], | |
stdin=echo.stdout, | |
stdout=subprocess.PIPE, | |
) |
This file contains 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
def validate_and_update(self, **update_fields): | |
tablename = self.db._adapter.get_table(self.query) | |
response = Row() | |
response.errors = self.db[tablename]._validate(**update_fields) | |
fields = self.db[tablename]._listify(update_fields,update=True) | |
if not fields: | |
raise SyntaxError, "No fields to update" | |
self.delete_uploaded_files(update_fields) | |
if not response.errors: | |
response.updated = self.db._adapter.update(tablename,self.query,fields) |
OlderNewer