微信小程序服药提醒_您将不会再忘记服药:每日电话提醒

微信小程序服药提醒

Image for post
National Cancer Institute on 美国国家癌症研究所Unsplash 照片

In today’s hectic lifestyle, people generally tend to forget when to take their medicines. So I made a Medicine Reminder that reminds you to take your Medication via Voice Call Message.

在当今忙碌的生活方式中,人们通常会忘记何时服用药物。 因此,我做了药物提醒,提醒您通过语音电话留言服药。

In this article, I will guide you to make a reminder that will call you automatically to take your medicine at your preferable time.

在本文中,我将指导您进行提醒,该提醒将在您需要的时间自动呼叫您服药。

So for receiving a call on your mobile number, we will use the Twilio Python Package, and for scheduling calls, as a reminder, we will use APScheduler. For automating the calling process, we will put our code on the Heroku Cloud Platform.

因此,要使用您的手机号码接听电话,我们将使用Twilio Python软件包,并且为了提醒您安排通话,我们将使用APScheduler。 为了使调用过程自动化,我们将代码放在Heroku Cloud Platform上。

The flow of the process is:

该流程如下:

· Setting up Twilio

·设置Twilio

· Python Script for receiving a call from Twilio

· Python脚本,用于接收来自Twilio的呼叫

· Scheduling our Python code

·安排我们的Python代码

· Putting our code on Heroku for automation

·将代码放在Heroku上进行自动化

设置Twilio (Setting up Twilio)

Create a free account on twilio.com by confirming your email address and phone number.

通过确认您的电子邮件地址和电话号码,在twilio.com上创建一个免费帐户。

After signing-in to your Twilio account, create a project with your preferable name.

登录到您的Twilio帐户后,请使用您的首选名称创建一个项目。

Now, you have to take a mobile number from Twilio so that you can receive the reminder call from that number. Steps to get the phone number from Twilio:-

现在,您必须从Twilio取得一个手机号码,以便您可以从该号码接收提醒电话。 从Twilio获取电话号码的步骤:-

  1. Go on All Products & Services on the upper-left corner of Twilio homepage.

    转到Twilio主页左上角的所有产品和服务

Image for post

2. Then click on the Phone Numbers tab.

2.然后单击“ 电话号码”选项卡

Image for post

3. After that, click on Get your first Twilio phone number so that you can get a phone number from which you will receive a call. You will get the phone number for free.

3.之后,单击“ 获取您的第一个Twilio电话号码”,这样您就可以获取一个电话号码,您将通过该电话号码接听电话。 您将免费获得电话号码。

Image for post

Now go to Twilio Console and get your ACCOUNT SID and AUTH TOKEN that you need in the coding process.

现在转到Twilio Console ,获取在编码过程中需要的帐户SID和身份验证令牌。

And also, add your phone number on Twilio on which you want to receive the reminder call. For that again, go on the Phone Numbers tab and click on Verified Caller IDs to add the recipient’s phone number.

另外,在Twilio上添加您要接收提醒电话的电话号码。 再次为此,请转到“ 电话号码”选项卡,然后单击“ 已验证的呼叫者ID”以添加收件人的电话号码。

Image for post

用于接收来自Twilio的呼叫的Python脚本 (The Python Script for receiving a call from Twilio)

You check out my Github repository of this project here.

您可以在此处查看我有关该项目的Github存储库。

Image for post

First of all, create a Project directory and add the following file named as script.py ,schedule.py , requirements.txt and a Procfile(without a file extension) into Project directory. I will tell you the use of each file and what it contains as we move further.

首先,创建一个项目 目录,然后将以下名为script.pyschedule.pyrequirements.txt的文件和一个Procfile (不带文件扩展名)添加到Project目录中。 我将告诉您每个文件的用途以及其中包含的内容。

For receiving a call from Twilio, you have to do the following -:

要接收来自Twilio的呼叫,您必须执行以下操作-:

  1. Install the Twilio dependency on your machine by writing pip install twilio in the command prompt.

    通过编写pip install twilio在计算机上安装Twilio依赖pip install twilio 在命令提示符下。

  2. Now go to Twilio Console, get your account_sid and auth_token so that Twilio can verify you.

    现在转到Twilio控制台,获取您的account_sidauth_token,以便Twilio可以验证您的身份

  3. Then you have to write the following code in script.py for receiving the call from Twilio:-

    然后,您必须在script.py编写以下代码以接收来自Twilio的呼叫:-

from twilio.rest import Clientaccount_sid = 'AC68dd6fb818a70751f9f8a5af3'   #Replace with your account_sid'auth_token = '0d9c4274fea8fc95aXXXXXXXX'    #Replace with your auth_token'client = Client(account_sid, auth_token)def callmsg():    
call = client.calls.create(
from_='+17146604658', #Replace with the phone number that you got from Twilio
twiml='<Response><Say>Reminder to take your Pill at 7:17 P.M.</Say></Response>',
to='+918285XXXXXX' #Phone number that you add on Twilio
)print(call.sid)

Before moving on the further run script.py to see that if you are getting a call from Twilio with the response that you have provided.

在继续运行script.py 看看是否收到来自Twilio的电话,并提供了您的回复。

安排我们的Python代码 (Scheduling our Python code)

Now we will need Python’s library — Advanced Python Scheduler (APScheduler) that lets you schedule your Python code to be executed at your preferable time. Do the following steps for scheduling the calling process-:

现在,我们将需要Python的库-Advanced Python Scheduler( APScheduler ),该库可让您安排Python代码在更合适的时间执行。 执行以下步骤以安排调用过程:

  1. Install the APScheduler dependency on your machine by writing pip install apscheduler in the command prompt.

    通过在命令提示符下编写pip install apscheduler ,在您的计算机上安装APScheduler依赖项。

  2. Then you have to write the following code in schedule.py for scheduling the call:-

    然后,您必须在schedule.py编写以下代码以schedule.py调用时间:-

from datetime import datetime
import pytzfrom apscheduler.schedulers.blocking import BlockingScheduler#importing the callmsg function from script.py that you have madefrom script import callmsgist = pytz.timezone('Asia/Kolkata')sched = BlockingScheduler()# Schedule the python script to be called everyday from monday to friday at 7:17 P.M. You change the time as per your need.sched.add_job(callmsg, 'cron', day_of_week='mon-fri', hour=19, minute=17, timezone=ist)sched.start()

Before moving on to the automation process run the schedule.py to confirm that you are getting the call at the scheduled time you have entered in schedule.py

在继续进行自动化过程之前,请运行schedule.py 确认您已在schedule.py输入的预定时间接听电话

将我们的代码放到Heroku上进行自动化 (Putting our code on Heroku for automation)

Now we are ready with getting a call through Twilio and scheduling it with APScheduler, but we have to make it an automated process so that we did not need to run the python script again and again. For automating the call processing, we will use the Heroku platform.

现在,我们已经准备好通过Twilio进行调用并使用APScheduler对其进行调度,但是我们必须使其成为一个自动化过程,这样就不必一次又一次地运行python脚本。 为了使呼叫处理自动化,我们将使用Heroku平台。

Heroku is a Cloud Application Platform service that enables developers to build, run, and operate applications entirely in the cloud.

Heroku是一项云应用程序平台服务,使开发人员可以完全在云中构建,运行和操作应用程序。

Create a Heroku’s free developer account.

创建一个Heroku的免费开发者帐户。

After logging-in to the Heroku dashboard, Click on NewCreate a new app and give a name to your application. Here I gave a callreminder name to my Heroku Application.

登录到Heroku仪表板后,单击“ 新建” →“ 创建新应用”,并为您的应用命名。 在这里,我给Heroku应用程序指定了一个提醒的名字。

Image for post

You require Heroku CLI (Command Line Interface) from which you can create and manage your Heroku apps directly from the command terminal. And Heroku CLI requires Git, the popular version control system. If you don’t already have Git installed, complete the following before installing the CLI:

您需要Heroku CLI(命令行 界面) ,从中可以直接从命令终端创建和管理Heroku应用程序。 Heroku CLI需要流行的版本控制系统Git 。 如果尚未安装Git,请在安装CLI之前完成以下操作:

After you set up Git, you have to download and install Heroku CLI

设置Git之后,您必须下载并安装Heroku CLI

Now, for server-side implementation, we need to do two things-:

现在,对于服务器端实现,我们需要做两件事:

  1. To list the external dependencies, in our case, we have two dependencies Twilio and APScheduler. You have to write the current version of Twilio and APScheduler that you installed in requirements.txt

    为了列出外部依赖关系,在我们的例子中,我们有两个依赖关系TwilioAPScheduler。 您有您在安装写TwilioAPScheduler的当前版本requirements.txt

twilio==6.41.0
APScheduler==3.6.3

2. We need a Procfile. A Procfile is a file that will tell the Heroku to run this project according to a specific schedule. Write the following line of code in Procfile

2.我们需要一个Procfile。 Procfile是一个文件,它将告诉Heroku根据特定的时间表运行该项目。 在Procfile编写以下代码Procfile

clock: python schedule.py

Now we just left with deploying our project on Heroku. For that, open your command prompt and go to your Project directory destination and then follow the following steps:-

现在我们只剩下在Heroku上部署我们的项目了。 为此,请打开命令提示符并转到Project目录目标,然后执行以下步骤:

  • If you haven’t already, log in to your Heroku account and follow the prompts to create a new SSH public key.

    如果尚未登录,请登录到Heroku帐户,然后按照提示创建新的SSH公钥。
>>    heroku login
  • Initialize a Git repository

    初始化一个Git仓库
>>    git init
>> heroku git:remote -a callreminder
  • Deploy your application

    部署您的应用
>>    git add .
>> git commit -am “make it better”
>> git push heroku master

The final step is to make your Medicine Reminder run at just one time, and it reminds you daily by calling. For that, go to the Resources tab at your Heroku’s App Page there, you can see Free Dynos.

最后一步是使您的Medicine Reminder一次运行,它每天通过电话提醒您。 为此,请转到Heroku应用程序页面上的“ 资源”选项卡,您可以看到“免费Dynos”。

Image for post

Under Free Dynos, you can see clock python schedule.py make it run by edit tab and switch the slider ON and Confirm the clock.

在“ 免费Dynos”下,您可以看到Clock python schedule.py,使其通过“编辑”选项卡运行,并打开滑块并确认时钟。

Image for post

That’s it. If you have done everything right, then you can get the Reminder Call to take your pills at your number as per your schedule without even running the code frequently.

而已。 如果您做对了所有事情,那么您可以接到“提醒电话”,按照您的时间表按您的电话号码服药,而无需频繁运行代码。

Image for post

You can notice that I got a call from Twilio Number at 7:17 P.M.

您可以注意到,我在7:17 PMTwilio号码接到了电话

If you don’t want to get Reminder Call anymore, you can go to Resources → Free Dynos and can see clock python schedule.py and switch the slider OFF and Confirm to stop.

如果您不想再收到“提醒电话”,则可以转到“ 资源”→“免费Dynos”,并可以看到时钟python schedule.py ,然后将滑块关闭并确认停止。

Image for post

翻译自: https://medium.com/swlh/a-daily-medicine-reminder-using-python-in-just-20-lines-of-code-c8efbfe033f2

微信小程序服药提醒

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值