当前位置: 首页 > news >正文

新野微网站建设上海出大事啦

新野微网站建设,上海出大事啦,温州什么时候有互联网公司,常州网站建设套餐使用Web应用程序编程接口 #xff08;API#xff09;自动请求网站的特定信息而不是整个网页#xff0c;再对这些信息进行可视化 使用Web API Web API是网站的一部分#xff0c;用于与使用具体URL请求特定信息的程序交互。这种请求称为API调用 。请求的数据将以易于处理的…使用Web应用程序编程接口 API自动请求网站的特定信息而不是整个网页再对这些信息进行可视化 使用Web API Web API是网站的一部分用于与使用具体URL请求特定信息的程序交互。这种请求称为API调用 。请求的数据将以易于处理的格式如JSON或CSV返回。依赖于外部数据源的大多数应用程序依赖于API调用如集成社交媒体网站的应用程序 Git和GitHub GitHub的名字源自Git后者是一个分布式版本控制系统帮助人们管理为项目所做的工作避免一个人所做的修改影响其他人所做的修改。在项目中实现新功能时Git跟踪你对每个文件所做的修改。确定代码可行后你提交所做的修改而Git将记录项目最新的状态。如果犯了错想撤销所做的修改你可以轻松地返回到以前的任何可行状态。要更深入地了解如何使用Git进行版本控制请参阅附录D。GitHub上的项目都存储在仓库中后者包含与项目相关联的一切代码、项目参与者的信息、问题或bug报告等等 在本章中我们将编写一个程序自动下载GitHub上星级最高的Python项目的信息并对这些信息进行可视化 使用API调用请求数据 GitHub的API让你能够通过API调用来请求各种信息。要知道API调用是什么样的请在浏览器的地址栏中输入如下地址 https://api.github.com/search/repositories?qlanguage:pythonsortstar https://api.github.com/search/repositories?qlanguage:pythonsortstar这个调用返回GitHub当前托管了多少个Python项目以及有关最受欢迎的Python仓库的信息 https://api.github.com/ 将请求发送到GitHub网站中响应API调用的部分接下来的search/repositories 让API搜索GitHub上的所有仓库 repositories 后面的问号指出需要传递一个实参。q 表示查询而等号 让我们能够开始指定查询。我们使用language:python 指出只想获取主要语言为Python的仓库的信息。最后的sortstars 指定将项目按星级排序 安装requests pip install requests处理API响应 import requests # 执行API调用并存储响应。 url https://api.github.com/search/repositories?qlanguage:pythonsortstars headers {Accept: application/vnd.github.v3json} r requests.get(url, headersheaders) print(fStatus code: {r.status_code}) # Status code: 200 # 将API响应赋给一个变量。 response_dict r.json() # 处理结果。 print(response_dict.keys()) # dict_keys([total_count, incomplete_results, items])状态码200表示请求成功 方法json() 将这些信息转换为一个Python字典 处理响应字典 # 将API响应赋给一个变量。 response_dict r.json() print(fTotal repositories: {response_dict[total_count]}) # 9420397 # 仓库总数 # 探索有关仓库的信息。 repo_dicts response_dict[items] print(fRepositories returned: {len(repo_dicts)}) # 30 # 返回30个仓库 # 研究第一个仓库。 repo_dict repo_dicts[0] print(f\nKeys: {len(repo_dict)}) # Keys: 80 # repo_dict 包含80个键 for key in sorted(repo_dict.keys()):print(key)提取repo_dict 中与一些键相关联的值 print(\nSelected information about first repository:) # Selected information about first repository: print(fName: {repo_dict[name]}) # Name: flask print(fOwner: {repo_dict[owner][login]}) # Owner: pallets print(fStars: {repo_dict[stargazers_count]}) # Stars: 63955 print(fRepository: {repo_dict[html_url]}) # Repository: https://github.com/pallets/flask print(fCreated: {repo_dict[created_at]}) # Created: 2010-04-06T11:11:59Z print(fUpdated: {repo_dict[updated_at]}) # Updated: 2023-08-27T04:37:37Z print(fDescription: {repo_dict[description]}) # Description: The Python micro framework for building web applications.owner login 所有者登录名 概述最受欢迎的仓库 # 研究有关仓库的信息。 repo_dicts response_dict[items] print(fRepositories returned: {len(repo_dicts)})print(\nSelected information about each repository:) for repo_dict in repo_dicts:print(f\nName: {repo_dict[name]})print(fOwner: {repo_dict[owner][login]})print(fStars: {repo_dict[stargazers_count]})print(fRepository: {repo_dict[html_url]})print(fDescription: {repo_dict[description]})代码结果如下 Repositories returned: 30Selected information about each repository:Name: flask Owner: pallets Stars: 63955 Repository: https://github.com/pallets/flask Description: The Python micro framework for building web applications.Name: langchain Owner: langchain-ai Stars: 60009 Repository: https://github.com/langchain-ai/langchain Description: ⚡ Building applications with LLMs through composability ⚡Name: ailearning Owner: apachecn Stars: 36223 Repository: https://github.com/apachecn/ailearning Description: AiLearning数据分析机器学习实战线性代数PyTorchNLTKTF2Name: linux-insides Owner: 0xAX Stars: 28546 Repository: https://github.com/0xAX/linux-insides Description: A little bit about a linux kernel监视API的速率限制 大多数API存在速率限制也就是说在特定时间内可执行的请求数存在限制 要获悉是否接近了GitHub的限制请在浏览器中输入https://api.github.com/rate_limit你将看到类似于下面的响应https://api.github.com/rate_limit 注意很多API要求注册获得API密钥后才能执行API调用 使用Plotly可视化仓库 import requests from plotly.graph_objs import Bar from plotly import offline# 执行API调用并存储响应。 url https://api.github.com/search/repositories?qlanguage:pythonsortstars headers {Accept: application/vnd.github.v3json} r requests.get(url, headersheaders) print(fStatus code: {r.status_code})# 处理结果。 response_dict r.json() repo_dicts response_dict[items] repo_names, stars [], [] for repo_dict in repo_dicts:repo_names.append(repo_dict[name])stars.append(repo_dict[stargazers_count])# 可视化。 data [{type: bar,x: repo_names,y: stars, }] my_layout {title: GitHub上最受欢迎的Python项目,xaxis: {title: Repository},yaxis: {title: Stars}, }fig {data: data, layout: my_layout} offline.plot(fig, filenamepython_repos.html)改进Plotly图表 data my_layout 可在data 和my_layout 中以键值对的形式指定各种样式 data修改图表 my_layout修改字 data [{type: bar,x: repo_names,y: stars,marker: {color: red,line: {width: 1.5, color: rgb(25, 25, 25)}},opacity: 0.6, }]my_layout {title: GitHub上最受欢迎的Python项目,titlefont: {size: 28},xaxis: {title: Repository,titlefont: {size: 24},tickfont: {size: 14},},yaxis: {title: Stars,titlefont: {size: 24},tickfont: {size: 14},}, }添加自定义工具提示 hovertext 工具提示将鼠标指向条形将显示其表示的信息 # 处理结果。 response_dict r.json() repo_dicts response_dict[items] repo_names, stars, labels [], [], [] for repo_dict in repo_dicts:repo_names.append(repo_dict[name])stars.append(repo_dict[stargazers_count])owner repo_dict[owner][login]description repo_dict[description]label f{owner}br /{description}labels.append(label)# 可视化。 data [{type: bar,x: repo_names,y: stars,hovertext: labels,marker: {color: rgb(60, 100, 150),line: {width: 1.5, color: rgb(25, 25, 25)}},opacity: 0.6, }]Plotly允许在文本元素中使用HTML代码 在图表中添加可单击的链接 点击图表底端的项目名可以访问项目在GitHub上的主页 # 处理结果。 response_dict r.json() repo_dicts response_dict[items] repo_links, stars, labels [], [], [] for repo_dict in repo_dicts:repo_name repo_dict[name]repo_url repo_dict[html_url]repo_link fa href{repo_url}{repo_name}/arepo_links.append(repo_link)stars.append(repo_dict[stargazers_count])owner repo_dict[owner][login]description repo_dict[description]label f{owner}br /{description}labels.append(label)将data里x的值改为repo_links data [{x: repo_links, }]深入了解Plotly和GitHub API 想要深入了解如何生成Plotly图表可以看Plotly User Guide in Python和Python Figure Reference Hacker News API Hacker News网站Hacker News的API让你能够访问有关该网站所有文章和评论的信息且不要求通过注册获得密钥 import requests import json# 执行API调用并存储响应。 url https://hacker-news.firebaseio.com/v0/item/19155826.json r requests.get(url) print(r.status_code)# 200# 探索数据的结构。 response_dict r.json() readable_file readable_hn_data.json with open(readable_file, w) as f:json.dump(response_dict, f, indent4)下面的URL返回一个列表其中包含Hacker News上当前排名靠前的文章的ID https://hacker-news.firebaseio.com/v0/topstories.jsonfrom operator import itemgetter import requests# 执行API调用并存储响应。 url https://hacker-news.firebaseio.com/v0/topstories.json r requests.get(url) # print(fStatus code: {r.status_code})# 处理有关每篇文章的信息。 submission_ids r.json() submission_dicts [] for submission_id in submission_ids[:10]:# 对于每篇文章都执行一个API调用。url fhttps://hacker-news.firebaseio.com/v0/item/{submission_id}.jsonr requests.get(url)# print(fid: {submission_id}\tstatus: {r.status_code})response_dict r.json()# 对于每篇文章都创建一个字典。submission_dict {title: response_dict[title],hn_link: fhttp://news.ycombinator.com/item?id{submission_id},comments: response_dict[descendants],}submission_dicts.append(submission_dict)submission_dicts sorted(submission_dicts, keyitemgetter(comments),reverseTrue)for submission_dict in submission_dicts:print(f\nTitle: {submission_dict[title]})print(fDiscussion link: {submission_dict[hn_link]})print(fComments: {submission_dict[comments]})
http://www.tj-hxxt.cn/news/216636.html

相关文章:

  • 网站年报公示怎么做邵阳 网站开发 招聘
  • 未来的门户网站开发公司组织架构图模板
  • 网站建设关键词排名优化上海人才网站官网入口
  • 工装设计效果图网站创意网红墙图片
  • 高端网站建设的要求江苏seo排名
  • 专做动漫的网站家庭装修设计软件哪个好用
  • 营销型企业网站策划方案互联网广告销售好做吗
  • 快速优化网站建设自己做的网站如何在百度被搜索到
  • 网站建设上市公司宁波住房和城乡建设官网
  • 广州网站设计易企建站怎样申请免费网站域名
  • 阿里云备案 网站备案域名做设计去哪个网站找素材
  • wordpress网站主机名wordpress 自定义页眉
  • 平台网站开发风险找哪些公司做网站
  • 深圳品牌网站制作报价网站响应方案
  • 邯郸哪里有做网站的李网页设计师相关职业前景
  • 安全联盟可信网站认证做网站服务器配置应该怎么选
  • 网站公司建设个服务号多少钱北京蓝杉网站建设公司
  • 高端大气企业网站模板建设宁夏分行互联网站
  • 中山技术支持中山网站建设技术培训ui设计
  • 河源北京网站建设wordpress推送到百度
  • 丹阳网站建设公司毕业生就业推荐表模板网站开发
  • 下花园区住房和城乡建设局网站电子商务网站建设一体化教案
  • 网站开发过时了做一个商城网站多少钱
  • 河北网站建设与推广wordpress评论导出
  • 网站开发用户需求说明书pc28网站开发
  • 建筑人才招聘哪个网站最好做外贸的社交网站有哪些
  • 那个网站的详情做的好南京制作网页公司
  • php做视频网站有哪些软件下载专业网站托管
  • 网站建设公司厂画质优化app下载
  • 网络运营一般工资多少重庆seo收费