# text_living.pyclass TextLiving:
def __init__(self, match_info, **kwargs):
self.home_team = match_info['home_team']
self.visit_team = match_info['visit_team']
self.period_cn = match_info['period_cn']
self.live_text = kwargs['live_text']
self.home_score = kwargs['home_score']
self.visit_score = kwargs['visit_score']def __repr__(self):
return '{self.home_team} {self.home_score} - {self.visit_score} {self.visit_team} {self.period_cn}\n{self.live_text}\n{sep}'.format(self=self, sep='*'*60)12345678910111213
接着创建zhibo8_api.py模块 , 用于获取相关数据 。
# 当前正在进行的比赛Living_Matches_Url = ''# 某一场比赛当前的max_sidMatch_Max_Sid_Url = ''# 某一场比赛最新文字直播Match_Living_Text_Url = ''# 某一场比赛当前的基本情况Match_Info_Url = ''def get_living_matches():
response = requests.get(Living_Matches_Url)
result = json.loads(response.text)
matches = [Match(**match) for match in result['list'] if match['type'] == 'basketball' and match['period_cn'] != '完赛']return matchesdef get_match_max_sid(match_id):
response = requests.get(Match_Max_Sid_Url % match_id)if response.status_code == requests.codes.ok:return int(response.text)def get_match_living(match_id, max_sid):
# 先获取比赛的当前情况,再获取最新文字直播
match_info = get_match_info(match_id)
response = requests.get(Match_Living_Text_Url % (match_id, max_sid))
texts = []if response.status_code == requests.codes.ok:
result = json.loads(response.text)
texts = [TextLiving(match_info, **living) for living in result]return textsdef get_match_info(match_id):
today = datetime.now().strftime('%Y-%m-%d')
response = requests.get(Match_Info_Url % (today, match_id))
match_info = json.loads(response.text)return match_info123456789101112131415161718192021222324252627282930313233343536373839404142
最后,在main.py模块中启动程序,开始直播!
def get_living_matches():
matches = zhibo8_api.get_living_matches()for match in matches:
print(match)return matchesdef get_watch_match(matches):
match_id = input('请输入比赛ID:')for match in matches:if match.id == match_id:return matchelse:
print('输入的ID不正确')return Nonedef main_loop():
matches = get_living_matches()if len(matches) == 0:
print('当前没有比赛?。。?)return
match = get_watch_match(matches)if not match:
print('没去找到该比赛')return
current_match_max_sid = -1
while True:
match_max_sid = zhibo8_api.get_match_max_sid(match.id)if not match_max_sid:
print('没有直播数据')return
if current_match_max_sid == match_max_sid:continue
current_match_max_sid = match_max_sid
text_livings = zhibo8_api.get_match_living(match.id, current_match_max_sid)for text in text_livings:
print(text)if __name__ == '__main__':
main_loop()
Python OpenCV 霍夫(Hough Transform)直线变换检测原理,图像处理第 33 篇博客 霍夫变换(Hough Transform)是图像处理领域中,从图像中识别几何形状Python函数图像交点的基本方法之一 。主要识别具有某些相同特征Python函数图像交点的几何形状,例如直线,圆形,本篇博客的目标就是从黑白图像中识别出直线 。
翻阅霍夫直线变换的原理时候,橡皮擦觉得原理部分需要先略过,否则很容易在这个地方陷进去,但是问题来Python函数图像交点了,这个原理略过了,直接应用函数,里面有些参数竟然看不懂 。例如极坐标,角度扫描范围 , 这种函数就属于绕不过去的知识点了,所以本文转移方向,死磕原理,下面的博文将语无伦次的为你展示如何学习原理知识 。
因为数学知识的贫乏,所以在学习阶段会涉及到很多基础概念的学习,一起来吧 。
首先找到相对官方的资料,打开该地址
推荐阅读
- postgresql同时俩表的简单介绍
- oracle多数据添加数据,oracle增加数据
- 恋爱治愈养成类游戏推荐,恋爱治愈养成类游戏推荐
- php从二维数组取数据 php对二维数组进行排序
- 四川制造企业erp系统,四川制造企业排名
- 赛车登山的游戏,登山赛车类游戏
- 下载遨游中国2,云游戏秒玩
- c语言隐形函数 c语言函数隐式声明
- sqlserver的编程语言,sqlserver数据库编程