Skip to content

Instantly share code, notes, and snippets.

@Kevinstronger
Kevinstronger / urlparse_test.py
Created February 27, 2014 05:51
How to use urlparse
#coding:utf-8
import urlparse
URLscheme = "http"
URLlocation = "www.python.org"
URLpath = "lib/module-urlparse.html"
modList = ("urllib", "urllib2", "httplib", "cgilib")
#coding=UTF-8
import httplib, json
class CityCode(object):
#将城市代码存入字典中
valid_code = {
101010300: '朝阳',
101011000: '石景山',
101010900: '丰台'
@Kevinstronger
Kevinstronger / baidu_tran_noapi.py
Created February 20, 2014 03:15
get Baidu Translation without API
# -*- coding: utf-8 -*-
import urllib2
import urllib
import json
import httplib
def savefile(filename,data):
fdata = open(filename,'wb')
fdata.write(data)
fdata.close
@Kevinstronger
Kevinstronger / post_stuff.py
Created February 20, 2014 02:59
Example script to send an HTTPS POST via httplib
import sys
import httplib
from httplib import HTTPException
import json
DEBUG = False
BOUNDARY = '--------Boundary'
def post_stuff(host, post_url, field_dict):
@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 *
@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 / 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
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):
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'
#coding:utf-8
# Author: --<>
# Purpose:
# Created: 2013/7/3
import sys
import httplib
import json
import urllib