kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

微信公众平台获取网页授权(测试号)

https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html

https://blog.csdn.net/luopotaotao/article/details/50611317

1.登陆微信公众号后台,左下角找到

2.进入之后,会看到测试号的一些基本信息,用你的微信号扫描二维码关注测试号

3.网页账号权限处,右侧点击修改,此处填入你的网页域名

确认之后,后台配置就完成了,此时,再按照微信开发者文档中所写的流程便可正确获得授权,跳转到你的网页了.

后台获取到code,向微信服务器交换到openId,可以将该openId放到当前request的session中,此时用户在你开发的页面上的操作,都可以用session中的openId来确定用户了

微信公众号自定义菜单

https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html

basic.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
# filename: basic.py
import urllib
import time
import json
class Basic:
	def __init__(self):
		self.__accessToken = ''
		self.__leftTime = 0
	def __real_get_access_token(self):
		appId = ""    # TODO
		appSecret = ""    # TODO
		postUrl = ("https://api.weixin.qq.com/cgi-bin/token?grant_type="
			   "client_credential&appid=%s&secret=%s" % (appId, appSecret))
		urlResp = urllib.urlopen(postUrl)
		urlResp = json.loads(urlResp.read())
		self.__accessToken = urlResp['access_token']
		self.__leftTime = urlResp['expires_in']
	def get_access_token(self):
		if self.__leftTime < 10:
			self.__real_get_access_token()
		return self.__accessToken
	def run(self):
		while(True):
			if self.__leftTime > 10:
				time.sleep(2)
				self.__leftTime -= 2
			else:
				self.__real_get_access_token()

menu.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
# filename: menu.py
import urllib
from basic import Basic

class Menu(object):
	def __init__(self):
		pass
	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()

	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()

	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()

	#获取自定义菜单配置接口
	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()

if __name__ == '__main__':
	myMenu = Menu()
	appid = ""    # TODO
	uri = ""  # TODO exp: http://www.abcxyz.xyz/ci/wx/openid
	postJson = """
	{
		"button":
		[
			{
		"type": "view",
		"name": "openid",
		"url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
			},
			{
				"type": "view",
				"name": "测试",
				"url": "http://www.abcxyzkk.xyz/rs/wxmsg/test"
			}
		  ]
	}
	""" % (appid, uri)
	accessToken = Basic().get_access_token()
	#myMenu.delete(accessToken)
	myMenu.create(postJson, accessToken)

Python & tushare 实现命令行盯盘

https://blog.csdn.net/u011323949/article/details/102937856

依赖

1
2
pip install tushare
pip install pandas

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding:utf-8 -*-
import tushare as ts
import os
import threading
import time
from datetime import datetime

codes = ['000756', '601288', '601988', '601319', '600929']

while 1:
	try:
		df = ts.get_realtime_quotes(codes);
	except:
		print "get err\n";
		time.sleep(3);
		continue;

	os.system("clear")
	print datetime.now()
	for k in range(0, len(codes)):
		p1 = float(df['price'][k])
		p2 = float(df['pre_close'][k])
		print "%s %s %.3f %.3f %.3f%%" % (df['code'][k], df['name'][k], p1, p2, (p1 - p2) / p2 * 100)

	time.sleep(10);