Skip to content

Commit

Permalink
code formatting with black
Browse files Browse the repository at this point in the history
  • Loading branch information
trp07 committed Jan 5, 2019
1 parent f4d1ca5 commit 5ef23f1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions messages/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def validate_facebook(attr, value):
Functions below this hearder are general utility functions.
"""


def timestamp():
"""Get current date and time."""
return "{:%Y-%b-%d %H:%M:%S}".format(datetime.datetime.now())
10 changes: 9 additions & 1 deletion messages/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
from ._exceptions import MessageSendError


MESSAGE_CLASSES = {Email, Facebook, SlackWebhook, SlackPost, TelegramBot, Twilio, WhatsApp}
MESSAGE_CLASSES = {
Email,
Facebook,
SlackWebhook,
SlackPost,
TelegramBot,
Twilio,
WhatsApp,
}
MESSAGE_TYPES = {i.__name__.lower(): i for i in MESSAGE_CLASSES}


Expand Down
19 changes: 11 additions & 8 deletions messages/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def send(self):
if self.verbose:
print(timestamp(), "Login successful.")

if self.thread_type not in ('USER', 'GROUP'):
if self.thread_type not in ("USER", "GROUP"):
raise MessageSendError("Thread type must be either USER or GROUP.")

if self.thread_type == 'USER':
if self.thread_type == "USER":
model = fbchat_models.ThreadType.USER
else:
model = fbchat_models.ThreadType.GROUP
Expand All @@ -177,17 +177,20 @@ def send(self):
thread_type=model,
)
if self.verbose:
print(timestamp(), "Local attachment sent, message id {}.".format(self.message_id))

print(
timestamp(),
"Local attachment sent, message id {}.".format(self.message_id),
)

if self.remote_attachment:
self.message_id = client.sendRemoteFiles(
self.remote_attachment,
thread_id=self.to,
thread_type=model,
self.remote_attachment, thread_id=self.to, thread_type=model
)
if self.verbose:
print(timestamp(), "Remote attachment sent, message id {}.".format(self.message_id))
print(
timestamp(),
"Remote attachment sent, message id {}.".format(self.message_id),
)

client.logout()

Expand Down
27 changes: 13 additions & 14 deletions messages/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from ._utils import timestamp



class Twilio(Message):
"""
Create and send text SMS/MMS text messages using the Twilio API.
Expand Down Expand Up @@ -62,15 +61,15 @@ class Twilio(Message):
attachments = validate_property("attachments")

def __init__(
self,
from_=None,
to=None,
auth=None,
body=" ",
attachments=None,
profile=None,
save=False,
verbose=False,
self,
from_=None,
to=None,
auth=None,
body=" ",
attachments=None,
profile=None,
save=False,
verbose=False,
):

self.from_ = from_
Expand Down Expand Up @@ -115,9 +114,9 @@ def send(self):
Set self.sid to return code of message.
"""
url = (
"https://api.twilio.com/2010-04-01/Accounts/"
+ self._auth[0]
+ "/Messages.json"
"https://api.twilio.com/2010-04-01/Accounts/"
+ self._auth[0]
+ "/Messages.json"
)
data = {
"From": self.from_,
Expand All @@ -137,7 +136,7 @@ def send(self):
resp = requests.post(url, data=data, auth=(self._auth[0], self._auth[1]))
resp.raise_for_status()
except requests.exceptions.RequestException as e:
exc = '{}\n{}'.format(e, resp.json()["message"])
exc = "{}\n{}".format(e, resp.json()["message"])
raise MessageSendError(exc)

self.sid = resp.json()["sid"]
Expand Down

0 comments on commit 5ef23f1

Please sign in to comment.