def create(self, postData, accessToken):
postUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s" % accessToken
if isinstance(postData, unicode):
postData = postData.encode('utf-8')
urlResp = urllib.urlopen(url=postUrl, data=postData)
#print urlResp.read()
log.info(urlResp.read())
python类info()的实例源码
def query(self, accessToken):
postUrl = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s" % accessToken
urlResp = urllib.urlopen(url=postUrl)
#print urlResp.read()
log.info(urlResp.read())
def delete(self, accessToken):
postUrl = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s" % accessToken
urlResp = urllib.urlopen(url=postUrl)
#print urlResp.read()
log.info(urlResp.read())
#???????????
def get_current_selfmenu_info(self, accessToken):
postUrl = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s" % accessToken
urlResp = urllib.urlopen(url=postUrl)
#print urlResp.read()
log.info(urlResp.read())
def update_product(fournisseur_product_infos, incwo_product_infos):
update_infos = {}
try:
PRODUCT_ID = incwo_product_infos["id"]
PRODUCT_REF = fournisseur_product_infos["reference"]
except KeyError:
log.error("Incwo product with no ID or ref associated")
raise ValueError()
try:
# Si produit considere comme vitrine : on annule la comparaison prix et category en mettant les champs aux memes valeurs
if not compareValues(incwo_product_infos["product_category_id"],VITRINE_CATEGORY_ID):
log.warning("Pas de mise a jour du prix du produit {} (Produit categorisé comme en vitrine)".format(PRODUCT_REF))
incwo_product_infos["product_category_id"] = fournisseur_product_infos["product_category_id"]
fournisseur_product_infos["price"] = incwo_product_infos["price"]
except KeyError:
log.error("Incwo product with no category_ID associated")
raise ValueError()
for key in INCWO_PARAMS:
if not key in fournisseur_product_infos:
log.error("Product "+fournisseur_product_infos["name"]+" : fournisseur info incomplete! Missing "+key)
raise ValueError()
elif not key in incwo_product_infos:
if key != 'barcode':
log.debug("incwo info incomplete, updating "+key)
update_infos[key]=fournisseur_product_infos[key]
elif (compareValues(fournisseur_product_infos[key],incwo_product_infos[key])):
log.debug("incwo info outdated, updating {}".format(key))
log.debug("Picata {} ; incwo_product_infos {}".format(fournisseur_product_infos[key], incwo_product_infos[key]))
update_infos[key]=fournisseur_product_infos[key]
if len(update_infos) > 0 :
log.debug("Update needed for product "+str(PRODUCT_ID))
xml = prepare_xml_product(update_infos)
url = "https://www.incwo.com/"+str(ID_USER)+"/customer_products/"+str(PRODUCT_ID)+".xml";
send_request('put', url, xml)
# else :
# log.debug("Product {} (id {}) infos up to date".format(fournisseur_product_infos["name"],PRODUCT_ID))
manage_stock_movement(fournisseur_product_infos, PRODUCT_ID, incwo_product_infos["product_category_id"])
def get(self):
'''
the import handle
'''
try:
webData = self.request.body
#print "WxShowHandler Get webdata is ", webData
log.info("WxShowHandler Get webdata is %s" % (webData))
id = self.get_argument('id', '')
showidstr = self.get_argument('showid', '')
if len(id) == 0 or len(showidstr) == 0:
self.write('parameter error!')
# get sign ticket for weixin jsapisdk
ticket = DataCenter().get_jsapi_ticket()
urlall = self.request.uri
#print self.request.path /wx/show
#print self.request.uri /wx/show?id=oLN9QxI-YpdNJkSIXQkppJDHuvZM&showid=15
sign = Sign(ticket, test_urlhead + urlall)
sign_data = sign.sign()
#print 'weixin_JSAPI_ticket: '
#print sign_data
log.info('weixin_JSAPI_ticket: %s'%(sign_data))
timestamp = sign_data['timestamp']
nonceStr = sign_data['nonceStr']
signature = sign_data['signature']
# get_param id
showid = long(showidstr)
userdata = DataCenter().get_data_by_id(showid)
if len(userdata) == 0:
self.write("no data")
return
data_dict = userdata[0]
#print data_dict
log.debug(data_dict)
title_info = data_dict['title']
sub_info = data_dict['aidata'].split(test_split_str)
all_info = data_dict['originaldata'].split(test_split_str)
createtime = data_dict['createtime'].strftime('%Y-%m-%d %H:%M:%S')
author = ''
authorinfo = data_dict['author']
datasource = data_dict['datasource']
_userid = data_dict['userid']
if authorinfo == '':
author = datasource
elif datasource == '':
author = authorinfo
else :
author = authorinfo + ' | ' + datasource
self.render("index.html", title=title_info, allinfo=all_info, subjects=sub_info, author=author, \
createtime=createtime, appid=test_weixin_appid, timestamp=timestamp, nonceStr=nonceStr, \
userid=_userid, signature=signature)
except Exception, Argument:
log.error(Argument)
self.write(Argument)
def main():
# deal Ctrl-C
signal.signal(signal.SIGINT, signal_handler)
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(application)
#?????
http_server.listen(options.port)
#???????(???????????)
#http_server.bind(options.port)
#http_server.start(0)
#print 'Development server is running at http://127.0.0.1:%s/' % options.port
#print 'Quit the server with Control-C'
log.info('Development server is running at http://127.0.0.1:%s/' % options.port)
log.info('Quit the server with Control-C')
# nlpproc init
nlp_global_obj = NlpProc()
nlp_global_obj.init_nlpta()
# datacenter init
data_global_obj = DataCenter()
data_global_obj.connect_db("127.0.0.1:3306",'testdb', 'root', 'password')
# log in iflytek
ifly_tek = IflyTek()
# start get access token timer
get_access_token_instance = WeixinClient()
get_access_token_instance.get_access_token() #get first time
tornado.ioloop.PeriodicCallback(get_access_token_instance.get_access_token, period).start() # start scheduler
get_himalaya_access_token_ins = Himalaya()
tornado.ioloop.PeriodicCallback(get_himalaya_access_token_ins.get_access_token, period).start()
# test
#tornado.ioloop.PeriodicCallback(like_cron, 10000).start() # start scheduler
# start tornado ioloop
tornado.ioloop.IOLoop.instance().start()
def get_recommendation_tmp(self, os_type, pack_id):
recommendation = {'code': 0}
#??????
res = self.categories_human_recommend(os_type, pack_id)
for item in res:
#print "===>> category:", item['category_name'].encode("utf-8"), item['id']
if item['id'] != 8:
continue
category_id = item['id']
category_name = item['category_name']
print "====>>>> categor name, id:", category_name, category_id
#log.info("category_name:%s, category_id:%d"%(category_name, category_id))
#????tag
res = self.tags_list(os_type, pack_id, 0, category_id)
tag_names = []
for item in res:
tag_names.append(item['tag_name'])
# category + tag ????
recommendation['recommendation'] = []
recommendation['code'] = 0
cnt = 0
for item in tag_names:
"""
if cmp(item, u"????"):
#print "===>>> tag_name:", item.encode('utf-8')
print "===>>> tag_name:", item
continue
"""
print "===>>> tag_name:", item
res = self.albums_list(os_type, pack_id, category_id, item, 3)
if res.has_key('albums'):
tmp_list = res['albums']
for track in tmp_list:
print "==>>>album: ", track['album_title']
else:
pass
else:
recommendation = {'code': 0}
recommendation['error'] = 'no data'
return json.dumps(recommendation, ensure_ascii = False).encode('utf-8')