Skip to content

Instantly share code, notes, and snippets.

View pythononwheels's full-sized avatar

khz pythononwheels

View GitHub Profile
@pythononwheels
pythononwheels / pow_backup_migration_job.py
Created March 29, 2013 21:30
# PythonOnWheels migration to backup a DB Table # Using the Model's to_json method. # Usage: python do_migrate -j pow_backup_migration_job.py -d up # will backup a Posts Table in this example. # Replace the Post with any other model and it will backup # your model. (make sure you backup linked data (like external stored BLOBS) # as well. # date …
#
#
# PythonOnWheels migration to backup a DB Table
# Using the Model's to_json method.
# Usage: python do_migrate -j pow_backup_migration_job.py -d up
# will backup a Posts Table in this example.
# Replace the Post with any other model and it will backup
# your model. (make sure you backup linked data (like external stored BLOBS)
# as well.
@pythononwheels
pythononwheels / Post_blog.tmpl
Created March 29, 2013 22:38
Example basic Mako Template for a PythonOnWheels Blog view. Uses Post Model (columns: title, content) Just copy this to your views directory. (filename Post_blog.tmpl)
##
##
## This file was autogenerated by python_on_wheels.
## But you can safely edit this file. It will only be overwritten
## if you use the -f (--force) option on generate_scaffold.
##
## 2013-03-29
##
## inherits the layout defined in config/pow.py as default_layout
@pythononwheels
pythononwheels / datetime_json_serializer.py
Last active August 29, 2015 14:03
Python helper function and json.JSONEncoder to serialize datetime objects into json
#
# Info: python 3.x
# datetime json serializer
# author: khz june/2014
# www.pythononwheels.org
#
#
import datetime
import json
@pythononwheels
pythononwheels / csv_to_json.py
Created August 12, 2014 11:10
Short python utility that converts a given csv to the according json. Fieldnames are taken from the first line of the csv.
import csv
import json
import sys
#
#
# converts csv to json
# fieldnames are taken from the first line of the csv input file
#
# khz / 2014
@pythononwheels
pythononwheels / test_string_comparison.py
Created April 16, 2016 20:32
compare tuples of strings with a given pattern in python using difflib.
#
# Test string comparison of string tuples
# python 3.4
# using difflib.
#
# see also: http://stackoverflow.com/questions/36643618/scoring-consistency-within-dataset
# khz 04/2016
#
import difflib
import random
@pythononwheels
pythononwheels / data_classes.py
Last active August 31, 2022 21:08
python cerberus dataclass support proposal / idea
# -*-: coding utf-8 -*-
"""
This module is a proposal to add python's dataclass support to cerberus.
See Issue: #397
https://github.com/pyeve/cerberus/issues/397
And road-map:
1.3
Checklist:
The module dataclasses is implemented. This may get postponed 'til a following minor release. (#397)
@pythononwheels
pythononwheels / json2cerberus.py
Created November 14, 2018 21:05
Convert given JSON input (file.json) to a basic cerberus schema
#
# convert json data to a cerberus schema.
# Cerberus types see here: http://docs.python-cerberus.org/en/stable/validation-rules.html#type
#
# sampledata: https://www.json-generator.com/
#
# this uses the first data element in a given json file to create
# a model(cerberus) schema from it. Trying to guess the right types (without too much effort)
#
schema = {
'title' : { 'type' : 'string', 'maxlength' : 35 },
'text' : { 'type' : 'string' },
'tags' : { 'type' : 'list', "default" : [] },
"votes" : { "type" : "integer", "default" : 0 }
}
@relation.has_many("subtasks")
@relation.setup_sql_schema()
class Task(Base):
schema = {
'title' : { 'type' : 'string', 'maxlength' : 35 },
'text' : { 'type' : 'string' },
"votes" : { "type" : "integer", "default" : 0 }
}
@app.add_rest_routes("task")
class Task(BaseHandler):
#
# every pow handler automatically gets these RESTful routes
# when you add the : app.add_rest_routes() decorator.
#
# 1 GET /todo #=> list
# 2 GET /todo/<uuid:identifier> #=> show
# 3 GET /todo/new #=> new
# 4 GET /todo/<uuid:identifier>/edit #=> edit