Skip to content

Commit

Permalink
Create fetchNewArticle.py
Browse files Browse the repository at this point in the history
增加了实时获取新文章推送的API Demo文件
  • Loading branch information
LeLe86 authored Jul 31, 2020
1 parent 46182be commit d3113f7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions fetchNewArticle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os,sys,json
import time,requests
import hashlib,time,urllib
from urllib.request import urlopen
from urllib import parse,request
import urllib.request as urllib2
from pprint import pprint

def SaveFile(fpath,fileContent):
with open(fpath,'w',encoding='UTF-8') as f:
f.write(fileContent)



def run(token,customerid,starttime,bizlist):
nowtime=str(int(time.time()))
url="http://tst.xiaokuake.com/w/fetch/?customerid="+customerid+"&token="+token

postdata = {'customerid': customerid,
'bizlist': bizlist,
'starttime': starttime,
}
poststr = json.dumps(postdata) #转成字符串
headers = {'content-type': "application/json"}
response = requests.post(url, data = poststr, headers = headers) #发送一个post请求
pprint(response.text) #pprint是格式化显示的意思
#SaveFile("a.txt",response.text)


token="93cO7O302oDS" #测试账号固定填这个
customerid = "weiyan" #测试账号固定填这个
starttime = 1591784106 #获取starttime至今的数据,但最多只能获取最近24小时内的
bizlist = [
"MzA5NDc1NzQ4MA==", #差评
"MzUxNjUxMTg3OA==", #占豪
"MjM5MjAxNDM4MA==" #人民日报
]
#测试版的biz列表只能是列表中这几个,正式版也是要提前确定好一批biz,先关注了这些号才能收到其最新推送
#如果公众号不固定,又想做到想查哪个号就立马能查的,需要用到另外的接口,可联系作者获取(但价格会比这种固定一批公众号的贵)
#联系方式 www.xiaokuake.com/w/fetch/

run(token,customerid,starttime,bizlist)

0 comments on commit d3113f7

Please sign in to comment.