Skip to content

Instantly share code, notes, and snippets.

@wanghuafeng
Created November 25, 2013 07:07
Show Gist options
  • Save wanghuafeng/7637423 to your computer and use it in GitHub Desktop.
Save wanghuafeng/7637423 to your computer and use it in GitHub Desktop.
q
__author__ = 'Administrator'
# -*- coding: utf8 -*-
# import requests
# payload = {'key1': 'value1', 'key2': 'value2'}
#
# # r = requests.get("http://httpbin.org/get", params=payload)
# import time
#
# print time.time()
# print int(time.time())
# print str(int(time.time()))
# def is_text_msg(msg):
# return msg == "hello"
#
# param = "hello"
# if is_text_msg(param):
# print "helloworld"
#
# HELP_MSG = [u"?",u"?",u"帮助"]
# content = u"?"
# def is_help_msg(content):
# if content in HELP_MSG:
# print "yes in list"
#
# if is_help_msg(content):
# print "helloworld"
from decimal import Decimal
# condic = {'testdate': ['hello', 'world', 'tomcat'], 'esn': [u'90003185', u'90003186', u'90003187'],"app":["wechat","weixin","qq"]}
# print condic["testdate"][0]
# print len(condic)
# print
# for i in condic:
# print i
# for n in condic[i]:
# # print "testdate:%s,esn:%s" %condic[i]
# print n
# print len(condic[i])
# value_length = 0
# listarr = []
# arr = []
# n = 0
# for i in condic:
# if n < len(condic[i]):
# print condic[i][n]
# n+=1
# print arr
# print listarr
# print type(k),v
# print "%s ,%s,%s" % tuple(v)
# tup = dict(['hello', 'world', 'tomcat'])
# print "%s ,%s,%s" % tup
# import itertools
# condict = {"numeric":["one","two","three"],"ordinal":["first","second","third"],"numer":["1","2","3"]}
# def value_list():
# arr = []
# for (k,v) in condict.items():
# arr.append(v)
# arrlist = []
# for tup in itertools.imap(lambda *args:args,*arr):
# arrlist.append( tup )
# print arrlist
# return arrlist
# value_list()
# for (k,v) in condict.items():
# print k, condict # print v
# str = ""
# for val in v:
# str_dic = "%s:%s"%(k,val)
# str += str_dic
# str += ","
# print str
# sarr = str_dic.split("\\n")
# sarr += sarr
# import itertools
# d = {"Title":["one","two","three"],"Description":["first","second","third"],"PicUrl":["1","2","3"], "Url":["u1","u2","u3"]}
# def re_dic():
# arr = []
# for (k,v) in d.iteritems():
# arr.append(v)
# print map(None,*arr)
# # re_dic()
#
# NEWS_MSG_ITEM = \
# u"""
# <item>
# <Title><![CDATA[%s]]></Title>
# <Description><![CDATA[%s]]></Description>
# <PicUrl><![CDATA[%s]]></PicUrl>
# <Url><![CDATA[%s]]></Url>
# </item>
# """
# def add_items():
# arr = []
# for k in ["Title","Description","PicUrl","Url"]:
# arr.append(d[k])
# valIterator = itertools.imap(lambda *args:(NEWS_MSG_ITEM)%args, *arr)
# itemVal = ""
# for val in valIterator:
# itemVal +=val
# print itemVal
# return itemVal
# add_items()
# import itertools
# condict = {"numeric":["one","two","three"],"ordinal":["first","second","third"],"number":["1","2","3"]}
# # arr = []
# # for (k,v) in condict.iteritems():
# # arr.append(v)
# # v = iter(arr)
# # print v
# # print(arr)
# def f(x,y,z):
# print x,y,z
# return [x,y,z]
#
# v = itertools.imap(f, condict['numeric'], condict['ordinal'], condict['number'])
# na = []
# for z in v:
# na.append( z )
# print na
# print "****************************************************************"
#截取字符串前后的空格
# print var
# print var.strip()
#***********************
#过滤器的表达
def filter(bool_func,seq):
filtered_seq = []
for eachItem in seq:
if bool_func(eachItem):
filtered_seq.append(eachItem)
return filtered_seq
#"****************************************************************"
#获取上级目录下的文件
# import os
# path = os.path.basename(os.getcwd())
# print path
# path2 = "../" + path
# print path2
# print os.listdir(path2)
# i = 0
# def var():
# i = 10
# print i
# print i
# var()
# print i
#
# import os
# cwd = os.getcwd()
# upload_file = cwd + "/"
# # print os.listdir(upload_file)
# str = "http://imgsrc.baidu.com/baike/pic/item/4e4a20a4462309f725d51ed9730e0cf3d6cad647.jpg"
# print len(str)
#****************************************************************
#数据库返回的value类型为数组,key为数据库字段的信息
# from datetime import date
# from DB import DB
#
# db = DB()
# def db_info_msg():
# sql = "select * from wx_info_msg"
# result = db.query(sql)
# keys = result.keys()
# # print keys
# conarr = result.fetchall()
# data = {}
# for key in keys:
# k = key.encode("utf-8")
# data[k] = []
# for con in conarr:
# for key in keys:
# obj = con[key]
# if isinstance(obj,date):
# data[key].append(obj.isoformat())
# else:
# data[key].append(obj)
# data["cols"] = keys
# print data
# return data
# db_info_msg()
# d = {"Title":["one","two","three"],"Description":["first","second","third"],"PicUrl":" hello ", "Url":["u1","u2","u3"]}
# print d["PicUrl"]
# print d["PicUrl"].strip()
# dic = {'description': [u'\u6b22\u8fce\u70b9\u83dc', u'\u6b22\u8fce\u91c7\u6458', u'\u6b22\u8fce\u56e2\u8d2d'], 'title': [u'\u70b9\u83dc', u'\u91c7\u6458', u'\u56e2\u8d2d'], 'url': [u'http://www.mabotech.com', u'http://www.baidu.com', u'http://mp.weixin.qq.com/wiki/index.php'], 'createdon': [None, None, None], 'cols': [u'id', u'title', u'description', u'picurl', u'url', u'picurlalias', u'lastupdateon', u'lastupdatedby', u'createdon', u'createdby', u'active', u'rowversionstamp'], 'lastupdateon': [None, None, None], 'picurlalias': [None, None, None], 'lastupdatedby': [None, None, None], 'picurl': [u'http://imgsrc.baidu.com/baike/pic/item/4e4a20a4462309f725d51ed9730e0cf3d6cad647.jpg', u'http://pic19.nipic.com/20120220/7031681_092013483000_2.jpg', u'http://pic19.nipic.com/20120307/9464774_183029076333_2.jpg'], 'createdby': [None, None, None], 'active': [1, 1, 1], 'rowversionstamp': [1, 1, 1], 'id': [1, 2, 3]}
# print dic.iteritems()
# def dic_by_content(content):
# sql = "select * from wx_info_msg where id = '{0}'".format(content)
# result = db.query(sql)
# keys = result.keys()
# # print keys
# conarr = result.fetchall()
# data = {}
# for key in keys:
# k = key.encode("utf-8")
# data[k] = []
# for con in conarr:
# for key in keys:
# obj = con[key]
# if isinstance(obj,date):
# data[key].append(obj.isoformat())
# else:
# data[key].append(obj)
# data["cols"] = keys
# print data
# return data
# STR = "hello\n"+"world\n"+"python"
# val =(2,2,3)
# info = u"""云泽谷生态农场向您提供生态食材,促销和优惠活动。
# 会员点菜回复{0}%s
# 应季采摘回复{1}%s
# 公司团购回复{2}%s
# 购买会员卡回复04"""%val#("one","two","three")
#
# print info
# print STR
content = "01"
from DB import DB
db = DB()
sql = """select c.message from wx_command c where c.wxcmd = 'default'"""
sql = "select * from wx_info_msg "
result = db.query(sql)
conarr = result.fetchall()
for i in conarr:
print i
# print str(i).encode("utf-8")
# i = i.encode("utf-8")
# print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment