Skip to content

Instantly share code, notes, and snippets.

@BrajeshKhare
BrajeshKhare / model-tests-in-tornado.py
Created May 9, 2016 08:51 — forked from didip/model-tests-in-tornado.py
Example on how to tests your model classes in Tornado
import unittest, os, os.path, sys
import tornado.database
import tornado.options
from tornado.options import options
APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(APP_ROOT, '..'))
# import your model module
import your.model as model
@BrajeshKhare
BrajeshKhare / login.html
Created May 13, 2016 07:30 — forked from guillaumevincent/login.html
Basic authentication on Tornado with a decorator
<div id="main-container">
<div id="main">
<h1>
<img alt="scubabook logo" src="{{ static_url("img/logo.png") }}">
</h1>
<div id="login-form">
<form action="/auth/login/" method="post" id="login_form">
<fieldset>
<label for="username">Username</label>
<input autocapitalize="off" autocorrect="off" class="text-input" id="username" name="username" tabindex="1" type="text" value="">
@BrajeshKhare
BrajeshKhare / application
Created May 19, 2016 09:40 — forked from ryancutter/application
Simple Python/Tornado web server tailored for hosting on OpenShift (https://openshift.redhat.com)
#!/usr/bin/python
import os
virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
@BrajeshKhare
BrajeshKhare / payoneer.php
Created May 23, 2016 10:51 — forked from pmoust/payoneer.php
payoneer.php
<?php
/**
* Payoneer API integration
*
* @date 27/11/12
* @name $payoneer
* @author Panagiotis Moustafellos
*/
class Payoneer
{
#news handler, pulls news from mongodb, renders news page
class NewsHandler (tornado.web.RequestHandler):
def get(self, currentPage):
news_content = dict()
coll = self.application.db.news
news = coll.find().sort("_id", DESCENDING)
#pagination code
currentPage = int(currentPage)
newsItemsPerPage = 2
from bs4 import BeautifulSoup
import requests
r = requests.get("http://www.metmuseum.org/collection/the-collection-online/search/36484")
bs = BeautifulSoup(r.content)
imgs = bs.findAll('img', src=True)
for img in imgs:
print img['src']
{% extends "main.html" %}
{% autoescape None %}
{% block body %}
{% for news_item in news%}
<p>
<b>{{str(news_item['datetime_added'])}}</b>
</p>
<p>
{{ news_item.get('text', '') }}
</p>
class MP3UploadHandler(tornado.web.RequestHandler):
def get(self):
self.render('mp3upload.html')
def post(self):
mp3=self.request.files['mp3'][0] #mp3 post data from form
mp3body=mp3['body'] #body of mp3 file
mp3name = mp3['filename'] #mp3 name and path
conn = S3Connection('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY') #amazon s3 connection
bucket = conn.create_bucket('foundsound_mp3') #bucket for images
@BrajeshKhare
BrajeshKhare / animated_brain.py
Created May 24, 2016 06:08 — forked from Zulko/animated_brain.py
Animated brain (Vispy) turned into a video/GIF (MoviePy)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: gallery 2
# Copyright (c) 2014, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
#
# Modified for animation with MoviePy by Zulko
# See result here: http://i.imgur.com/sSCBkFd.gif
#
@BrajeshKhare
BrajeshKhare / odoo_connector.py
Created June 2, 2016 13:47 — forked from dpr-odoo/odoo_connector.py
Odoo Python Connector (JSON RPC)
import httplib2,random, json
odoo_url = 'SERVER_URL'
class OdooConnector:
context = {}
http = False
cookies = ''
def __init__(self):