diff --git a/.gitignore b/.gitignore
index ea14333..a9d4ffa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.*sw*
.DS_Store
*~
+.idea/
diff --git a/.idea/babysitter_bot.iml b/.idea/babysitter_bot.iml
deleted file mode 100644
index 46ce774..0000000
--- a/.idea/babysitter_bot.iml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index 99e770f..0000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 5413da0..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
- ApexVCS
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index f9bf3df..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 6c904a5..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,185 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- DEFINITION_ORDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1508950836856
-
-
- 1508950836856
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/basic_sitter_bot.py b/basic_sitter_bot.py
new file mode 100644
index 0000000..cbccca5
--- /dev/null
+++ b/basic_sitter_bot.py
@@ -0,0 +1,59 @@
+import os
+from typing import Tuple
+
+from flask import Flask, request
+from twilio.rest import Client as TwilioClient
+from twilio.twiml.messaging_response import MessagingResponse
+
+twilio_client = TwilioClient(os.getenv('TWILIO_SID'), os.getenv('TWILIO_TOKEN'))
+
+app = Flask(__name__)
+app.config.from_object(__name__)
+
+sitters = {}
+
+@app.route('/bot', methods=['POST'])
+def bot():
+ from_ = request.values.get('From')
+ body = request.values.get('Body').lower()
+ response = 'I wasn\'t sure what to do with your input. '
+
+ if has_phone_num(body):
+
+ try:
+ sitter_name, sitter_num = add_sitter(body)
+ except (AssertionError, ValueError):
+ response = 'Sorry, did you mean to add a sitter? Please try again.'
+ else:
+ response = f'Okay, I added {sitter_name.title()} to sitters, with phone # {sitter_num}. '
+ print(sitters)
+
+ resp = MessagingResponse()
+ resp.message(response)
+ return str(resp)
+
+
+def has_phone_num(string):
+ return len([char for char in string if char.isnumeric()]) == 10
+
+
+def add_sitter(body: str) -> Tuple[str, str]:
+ name, *num_parts = body.split(' ')
+
+ num_only = ''.join(char
+ for num in num_parts
+ for char in num if char.isnumeric())
+
+ lowercase_name = name.lower()
+ sitter = sitters.get(lowercase_name)
+
+ assert len(num_only) == 10
+
+ sitters[lowercase_name] = f'+1{num_only}'
+
+ return name, sitters[lowercase_name]
+
+
+if __name__ == '__main__':
+ app.run(debug=True, port=8000)
+
diff --git a/basic_sitter_bot_with_pickle.py b/basic_sitter_bot_with_pickle.py
new file mode 100644
index 0000000..6564945
--- /dev/null
+++ b/basic_sitter_bot_with_pickle.py
@@ -0,0 +1,74 @@
+import os
+import pickle
+from typing import Tuple
+
+from flask import Flask, request
+from twilio.rest import Client as TwilioClient
+from twilio.twiml.messaging_response import MessagingResponse
+
+MY_CELL = os.getenv('MY_CELL')
+BOOKER_NUM = os.getenv('MY_TWILIO_NUM')
+
+twilio_client = TwilioClient(os.getenv('TWILIO_SID'), os.getenv('TWILIO_TOKEN'))
+
+app = Flask(__name__)
+app.config.from_object(__name__)
+
+sitters = {}
+if os.path.exists('sitters.p'):
+ sitters = pickle.load(open('sitters.p', 'rb'))
+
+@app.route('/bot', methods=['POST'])
+def bot():
+ from_ = request.values.get('From')
+ body = request.values.get('Body').lower()
+ response = 'I wasn\'t sure what to do with your input. '
+
+ if has_phone_num(body):
+
+ try:
+ sitter_name, sitter_num = add_sitter(body)
+ except (AssertionError, ValueError):
+ response = 'Sorry, did you mean to add a sitter? Please try again.'
+ else:
+ response = f'Okay, I added {sitter_name.title()} to sitters, with phone # {sitter_num}. '
+ print(sitters)
+
+ resp = MessagingResponse()
+ resp.message(response)
+ return str(resp)
+
+
+def has_phone_num(string):
+ return len([char for char in string if char.isnumeric()]) == 10
+
+
+def add_sitter(body: str) -> Tuple[str, str]:
+ name, *num_parts = body.split(' ')
+
+ num_only = ''.join(char
+ for num in num_parts
+ for char in num if char.isnumeric())
+
+ lowercase_name = name.lower()
+ sitter = sitters.get(lowercase_name)
+
+ assert len(num_only) == 10
+
+ sitters[lowercase_name] = f'+1{num_only}'
+ persist_sitters()
+
+ return name, sitters[lowercase_name]
+
+
+def persist_sitters():
+ pickle.dump(sitters, open('sitters.p', 'wb'))
+
+
+if __name__ == '__main__':
+ if sitters:
+ sitter_list = 'Your sitters are ' + ' and '.join(
+ f'{sitter_name.title()}' for sitter_name in sitters) + '.'
+ twilio_client.api.account.messages.create(to=MY_CELL, from_=BOOKER_NUM, body=sitter_list)
+ app.run(debug=True, port=8000)
+
diff --git a/sitter_bot.py b/sitter_bot.py
index a1bfee3..6efc7b2 100644
--- a/sitter_bot.py
+++ b/sitter_bot.py
@@ -60,7 +60,7 @@ def bot() -> str:
if not sitters:
response = f'You don\'t have any sitters yet. {help_add}.'
else:
- sitter_list = 'Your sitters are ' + ', '.join(
+ sitter_list = 'Your sitters are ' + ' and '.join(
f'{sitter_name.title()}' for sitter_name in sitters) + '.'
response = f'{sitter_list} {help_text}'
@@ -100,7 +100,7 @@ def bot() -> str:
def has_phone_num(string):
- return len([char for char in string if char.isnumeric()]) >= 10
+ return len([char for char in string if char.isnumeric()]) == 10
def syndicate_and_book(session_start: datetime.datetime, session_end: datetime.datetime) -> Optional[str]:
@@ -111,13 +111,13 @@ def syndicate_and_book(session_start: datetime.datetime, session_end: datetime.d
pass
-def book_sitter(in_message: str) -> Optional[str]:
- session_start, session_end = parse_sitter_request(in_message)
+def book_sitter(body: str) -> Optional[str]:
+ session_start, session_end = parse_sitter_request(body)
syndicate_and_book(session_start, session_end)
-def add_sitter(in_message: str) -> Tuple[str, str]:
- name, *num_parts = in_message.split(' ')
+def add_sitter(body: str) -> Tuple[str, str]:
+ name, *num_parts = body.split(' ')
num_only = ''.join(char
for num in num_parts