博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
戴尔笔记本 主板供电_使用笔记本微服务为应用程序供电
阅读量:2519 次
发布时间:2019-05-11

本文共 4819 字,大约阅读时间需要 16 分钟。

戴尔笔记本 主板供电

Previously, we learned how to create a microservice from a notebook using the Jupyter kernel gateway. We learned both how to annotate existing cells, as well as how to generate a new notebook with code cells ready to be filled-in. Now let’s look at this from the other direction: breaking down a problem into the microservices needed to implement its solution.

之前,我们学习了如何使用Jupyter内核网关从笔记本创建微服务。 我们学习了如何注释现有单元,以及如何使用准备好填充的代码单元生成新笔记本。 现在让我们从另一个方向来看:将问题分解为实现其解决方案所需的微服务。

For this post, we’ll solve a problem that’s been solved thousands of times before: making a Twitter bot. Specifically, when the bot is mentioned along with a location, it should tweet a search URL for relevant Meetups in that vicinity. Breaking it down further, the tweeted mention has to get to the bot, the bot has to figure out what location is being talked about, then it has to tweet in a way that the original person will see the correct search URL. To see the only code we’ll actually write in the making of this bot, check out the on GitHub.

对于本文,我们将解决一个已经解决了数千次的问题:制造一个Twitter机器人。 具体来说,当提及该漫游器及其位置时,它应该在该推文中发布该附近相关聚会的搜索URL。 进一步分解,必须在推特上提及该机器人,该机器人必须弄清楚正在讨论的位置,然后必须以一种方式发推文,以使原始人看到正确的搜索URL。 要查看我们将在该机器人制作过程中实际编写的唯一代码,请查看GitHub上的 。

将Twitter连接到机器人 (Connecting Twitter to the bot)

Keeping with our theme, instead of writing a full Twitter application we’ll be using . IFTTT creates connections between services, calling them Recipes. We will be employing its ties to Twitter and Maker, which it refers to as Channels. Of course, we’ll want new, different IFTTT and Twitter accounts for our new bot.

与我们的主题保持一致,我们将使用而不是编写完整的Twitter应用程序。 IFTTT在服务之间创建连接,称其为“配方”。 我们将利用其与Twitter和Maker的联系,将其称为渠道。 当然,我们希望新的机器人使用新的,不同的IFTTT和Twitter帐户。

For this example, we’ll use the  notebook from the kernel gateway demos on . It contains one endpoint marked up for our use: /generate_search_url.

对于此示例,我们将使用上的内核网关演示中的笔记本。 它包含一个标记为供我们使用的端点: /generate_search_url

A Twitter-Maker recipe

This part requires a Recipe with the trigger Channel of Twitter, the Trigger of a “New mention of you”, and an Action Channel of Maker with “Make a web request” to the service URL you’ll be standing up, making sure to pass along the text of the tweet and the original Twitter handle:

这部分需要一个食谱,其中包含Twitter的触发通道,“新提及您”的触发源以及Maker的操作通道,其中包含您将要站起来的服务URL的“发出网络请求”,请确保传递推文的文本和原始Twitter句柄:

https://kernel-gateway-microservice-demo.mybluemix.net/generate_search_url?text=<<<{

{Text}}>>>&user={
{UserName}}

https://kernel-gateway-microservice-demo.mybluemix.net/generate_search_url?text=<<<{

{Text}}>>>&user={
{UserName}}

获取位置并创建搜索URL (Getting the location and making the search URL)

Getting the location from the tweet’s text requires a considerable amount of language processing, and since we don’t want to solve that problem again, we’ll make use of the  API service from AlchemyAPI, Inc. While the notebook was written using a Python kernel, a less contrived service could require a kernel for a different language, run computations through a data scientist’s model in the notebook, or help leverage an existing cluster’s capabilities. In this case, it takes the result from calling Alchemy with your API key, prepares a URL to be tweeted, and then calls another service to have it tweeted. Being written for Python also makes it trivial to deploy our contrived service as a pure Python application on a PaaS, such as IBM Bluemix, which you may have guessed from the URL in the previous step.

从推文的文本中获取位置需要大量的语言处理,并且由于我们不想再次解决该问题,因此我们将使用AlchemyAPI,Inc.的 API服务。如果使用Python内核,则人为程度较低的服务可能需要使用其他语言的内核,通过笔记本中的数据科学家模型运行计算,或者帮助利用现有集群的功能。 在这种情况下,它将使用您的API密钥调用Alchemy的结果,准备要发布的URL,然后调用另一个服务来发布它。 为Python编写代码也使得将我们的人为服务作为纯Python应用程序部署到PaaS(例如IBM Bluemix)上变得微不足道,您可能已经在上一步的URL中猜到了。

推特结果 (Tweeting the result)

For the last part, we’ll again make use of IFTTT.

A Maker-Twitter recipeThis time, we need a Recipe going from Maker, with a Trigger “Receiving a web request” at an “Event name”
search_url_generated, to Twitter, and an Action to “Post a tweet” with the text:

对于最后一部分,我们将再次使用IFTTT。 这次,我们需要一个来自Maker的食谱,其中一个触发器“正在接收一个Web请求”(在“事件名称” search_url_generated,发送到Twitter,以及一个“文本在其中发布推文”的操作:

.{

{Value1}} you can find meetups near {
{Value2}} at {
{Value3}}

{

{Value1}},您可以在{
{Value3}}的{
{Value2}}附近找到聚会。

The values will be filled in with the original Twitter handle, the search URL, and the extracted location name.

这些值将使用原始Twitter句柄,搜索URL和提取的位置名称填充。

The notebook will require your Maker Channel key to send the right web request. Like the Alchemy API Key, this would be set into the environment around the running Jupyter kernel gateway. If those were correctly set, you’re already done.

笔记本电脑将需要您的Maker Channel键才能发送正确的Web请求。 像Alchemy API密钥一样,这将被设置到正在运行的Jupyter内核网关周围的环境中。 如果这些设置正确,则说明您已经完成。

Twitter timeline with followup

学到更多 (Learn More)

Nitin Dahyabhai

Nitin is a member of the IBM Cloud Emerging Technology group.

Nitin是IBM Cloud Emerging Technology组的成员。

Nitin Dahyabhai
Nitin Dahyabhai

翻译自:

戴尔笔记本 主板供电

转载地址:http://ieqwd.baihongyu.com/

你可能感兴趣的文章
常用算法
查看>>
SQL算术数字的默认类型
查看>>
正则表达式
查看>>
TCP/IP Socket
查看>>
How do I debug a published XBAP file in VS2010?
查看>>
单工、半双工和全双工的定义
查看>>
Hdu【线段树】基础题.cpp
查看>>
时钟系统
查看>>
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>
android addRule()
查看>>
转:app store 注册账号生成证书上传app完整的教程
查看>>
dedecms 搬家流程
查看>>
POST提交大量数据,导致后面数据丢失
查看>>
To Do List
查看>>
增强一个对象的方法(继承、装饰者模式、动态代理)
查看>>