Skip to content

Instantly share code, notes, and snippets.

@easonhan007
easonhan007 / test_http.py
Created December 28, 2013 08:30
how to use python to send request via get and post
import httplib, json, urllib
# get
conn = httplib.HTTPConnection('localhost', 5000)
conn.request('GET', '/')
r1 = conn.getresponse()
print r1.status, r1.reason
data = r1.read()
print json.loads(data)
@easonhan007
easonhan007 / flask_api.py
Last active October 6, 2023 14:15
A simple app of flask json api
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
@easonhan007
easonhan007 / public_function.rb
Created October 19, 2013 07:23
public_function.rb
#encoding: utf-8
def login(browser, user_name, password)
login_url = 'http://localhost/wordpress/wp-login.php'
browser.goto login_url
browser.text_field(:id, 'user_login').set user_name
browser.text_field(:id, 'user_pass').set password
browser.button(:id, 'wp-submit').click
end
@easonhan007
easonhan007 / delete_post_spec.rb
Created October 19, 2013 07:23
delete_post_spec.rb
#encoding: utf-8
require 'watir-webdriver'
require './spec/public_function'
describe 'Delete Post' do
before :all do
puts 'start browser'
@b = Watir::Browser.new :chrome
@password = @user_name = 'admin'
end
@easonhan007
easonhan007 / edit_post_spec.rb
Created October 19, 2013 03:23
edit_post_spec.rb
#encoding: utf-8
require 'watir-webdriver'
describe 'Create Post' do
before :all do
puts 'start browser'
@b = Watir::Browser.new :chrome
# 如何在watir里面使用原生的webdriver
#@b.wd == Selenium::WebDriver.for(:chrome)
@password = @user_name = 'admin'
@easonhan007
easonhan007 / create_post_spec.rb
Created September 11, 2013 14:33
wordpress ui test using watir and rspec
#encoding: utf-8
require 'watir-webdriver'
describe 'Create Post' do
before :all do
puts 'start browser'
@b = Watir::Browser.new :chrome
@password = @user_name = 'admin'
end
@easonhan007
easonhan007 / employee_spec.rb
Last active December 22, 2015 13:49
emplyee pay per month
#encoding: utf-8
class Employee
WORK_DAY_OF_MONTH = 20
DOUBLE = 2
attr_reader :name, :pay_per_day
def initialize name, pay_per_day
@name = name
@pay_per_day = pay_per_day
@pay_off = @over_time = 0
end
@easonhan007
easonhan007 / phone_spec.rb
Created September 8, 2013 02:33
test case of Phone
#encoding: utf-8
class Phone
attr_reader :type, :has_keyboard
def initialize(type, has_keyboard)
# 型号
@type = type
# 键盘
@has_keyboard = has_keyboard
end
@easonhan007
easonhan007 / inter_news_fetcher.rb
Last active December 22, 2015 03:59
从新浪和qq意甲页面获取国米新闻
require 'optparse'
require 'watir-webdriver'
ENV.delete('HTTP_PROXY')
module Inter
def self.parse
opts = {}
opts[:from] = 'qq'
opts[:browser] = 'chrome'
@easonhan007
easonhan007 / inter.rb
Created September 1, 2013 09:07
获取qq意甲板块里国际米兰的相关新闻
#encoding: utf-8
# print all the inter news with waitr-webdriver
require 'watir-webdriver'
url = 'http://sports.qq.com/seriea/'
b = Watir::Browser.new :chrome
b.goto url
b.div(:id, 'inter').div(:class, 'hot_list').links.each do |link|