Reputation: 31
Hello all: I have a basic program that copies a web page into a variable and checks the contents to see if a new press release was listed (i.e. by date since all PRs starts with a date in a consistent format. thanks to the help on this board it works.
Now I want to send a text message via twilio. I set my twilio account/number up and installed twilio according to these instructions. However, I get the error "ModuleNotFoundError: No Module named 'twilio'". I have uninstalled and re-installed several times. The only thing I can think of is that twilio is not installed where it should be. What are the file names and where should they be installed? Any advice would be appreciated.
===== RESTART: C:/Users/Family/Documents/Python Programs/check4newPRs.py
June 5, 2017
found new press release dated June 5, 2017
Traceback (most recent call last):
File "C:/Users/Family/Documents/Python Programs/check4newPRs.py", line 27,
in <module>
import twilio
ModuleNotFoundError: No module named 'twilio'
>>>
Here's my code:
# check4newPRs.py
import urllib.request
## Read web page contents into webPageCopy variable.
url = 'https://www.nwbio.com/press-releases/'
response = urllib.request.urlopen(url)
webPageCopy = response.read()
## Determining current date; populating month,day and variables
import datetime
import calendar
now = (datetime.datetime.now())
daynmbr = "05" ## temporarily hard-coded the 5th of June, the last press released by comany. Need to remove prior to going live.
## Creating current date search string, used to search webpage. All press releases start with a date in the following format: "June 5, 2017".
todaysdate = calendar.month_name[now.month] + " " + daynmbr.lstrip("0") + ", " + str(now.year) ## Remove prior to going live.
##todaysdate = calendar.month_name[now.month] + " " + str(now.day).lstrip("0") + ", " + str(now.year) ##use this one for production
print (str(todaysdate))
## ==========================================================================
## ======== press release is found, send Twilio sms text alert ========
## ==========================================================================
if (todaysdate.encode('utf-8')) in webPageCopy: ## todaysdate must be same byte type as the webPageCopy variable.
print ('found new press release dated', todaysdate)
import twilio
import twilio.rest
try:
client = twilio.rest.TwilioRestClient(account_sid, auth_token)
message = client.messages.create(
body="New Northwest Biotherapeutics Press Release Found!!!",
to="+1##########",
from_="+1##########"
)
except twilio.TwilioRestException as e:
print (e)
Upvotes: 1
Views: 653
Reputation: 73100
Twilio developer evangelist here.
First, check which version of Twilio Python you have installed. If it is version 6, then it is the latest and you'll need to update your code.
When you want to use the Twilio REST API you should:
from twilio.rest import Client
Then you can create an instance of a Client
and send a message like this:
client = Client(account_sid, auth_token)
message = client.messages.create(
body="New Northwest Biotherapeutics Press Release Found!!!",
to="+1##########",
from_="+1##########"
)
Let me know if that helps at all.
Upvotes: 1