Skip to content

Instantly share code, notes, and snippets.

@Kevinstronger
Kevinstronger / flask_api.py
Created February 19, 2014 09:21
A sample app of flask
from flask import Flask, jsonify, g, request
from sqlite3 import dbapi2 as sqlite3
DATABASE = './db/test.db'
app = Flask(__name__)
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect(DATABASE)
db.row_factory = sqlite3.Row
@Kevinstronger
Kevinstronger / reddit.py
Created February 20, 2014 01:54
Sample for interacting with Reddit using Python 2.7
# reddit27_samp.py
# http://docs.python.org/release/2.5.2/lib/httplib-examples.html
import httplib
url_string = "www.reddit.com"
header_stuff = {"User-Agent":"blah blah blah"}
reddit_feed = "/r/skydiving.json"
conn = httplib.HTTPConnection(url_string)
conn.request(method="GET", url=reddit_feed, headers=header_stuff)
res = conn.getresponse()
import httplib, urllib, json
def makeRequest() :
url = "iphone.kinoafisha.info"
req = "/server.php"
data = {
'method' : "beginSession"
, 'params' : [ {
@Kevinstronger
Kevinstronger / lets_rev_testing.py
Created February 20, 2014 02:06
Solution code for letsrevolutionizetesting.com
from httplib import HTTPConnection
import json
if __name__ == '__main__':
base_url = '/challenge.json'
url = base_url
count = 0
conn = HTTPConnection('www.letsrevolutionizetesting.com')
while count < 100:
conn.request("GET", url)
#coding:utf-8
# Author: --<>
# Purpose:
# Created: 2013/7/3
import sys
import httplib
import json
import urllib
import httplib
import base64
import string
import urllib
host = "api.supertweet.net"
url = "/1.1/statuses/update.json"
username = 'INPUTUSERNAME'
password = 'INPUTPASSWORD'
message = 'Tweet by Python on Raspberry Pi'
import sys
import BaseHTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
from urlparse import parse_qs
import httplib, urllib
import json
PARAMS_STRING = "?redirect_uri=http://127.0.0.1&client_secret=[SECRET]&client_id=[CLIENT_ID]&grant_type=authorization_code&code="
class Handler(BaseHTTPRequestHandler):
@Kevinstronger
Kevinstronger / webminapi.py
Created February 20, 2014 02:49
webmin / virtualmin remote api module webmin api: http://doxfer.webmin.com/Webmin/TheWebminAPI virtualmin api: http://www.virtualmin.com/documentation/developer/cli Examples: webmin = WebminApi('localhost', 'mylogin', 'mypassword') print webmin('user', 'list_users') virtualmin = VirtualminApi('localhost', 'mylogin', 'mypassword') print virtualmi…
import base64, httplib, json, xmlrpclib
class ApiBase(object):
def __init__(self, host, login, password, port=10000, https=True):
self.host = host
self.login = login
self.password = password
self.port = port
self.https = https
@Kevinstronger
Kevinstronger / selenium2_test_case.py
Created February 20, 2014 02:51
Reporting pass/fail status automatically in Selenium 2 tests
class Selenium2TestCase(TestCase):
def report_pass_fail(self):
base64string = base64.encodestring('%s:%s' % (config['username'],
config['access-key']))[:-1]
result = json.dumps({'passed': self._exc_info() == (None, None, None)})
connection = httplib.HTTPConnection(self.config['host'])
connection.request('PUT', '/rest/v1/%s/jobs/%s' % (self.config['username'],
self.driver.session_id),
result,
@Kevinstronger
Kevinstronger / httplibtest3.py
Created February 20, 2014 02:54
饭否实验代码
#!/usr/bin/python
# - * - coding: UTF-8 - * -
import json
import urllib
import oauth2 as oauth
# 此行用于获取 CONSUMER_KEY、CONSUMER_SECRET 等常数
from config import *