From 27b2ad8ae3986681f680b7ff8bb27b34c3628b78 Mon Sep 17 00:00:00 2001 From: Tarfah Alrashed Date: Fri, 6 Mar 2020 23:53:11 -0500 Subject: [PATCH 1/2] I added more examples to the about page --- docs/examples.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/docs/examples.md b/docs/examples.md index b6ad6e64..459ae6a1 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -167,6 +167,90 @@ def on_message(msg): ---------- +#### Aggregate Messages + +Aggregate all messages with event dates into a one message with the date and subject of each message. + +Tags: [] + +```python +# fired when a message arrives +def on_message(msg): + if msg.extract_time_entity(): + me = find_contact('me@mit.edu') + msg_subject = 'my current schedule' + msgs = me.messages_from() + old_msg = None + for m in msgs.reversed(): + if m.subject == msg_subject: + old_msg = m + break + new_content = msg.subject + msg.extract_time_entity()[0]['start'] + old_msg.content['text'] + send(to='me', subject= content=new_content) + +``` + +---------- + +#### Moving specific messages after a week + +Any message that arrives from the cs-staff list should be moved to the CS folder after a week + +Tags: [] + +```python +# fired when a message arrives +def on_command(msg): + if msg.sender == "cs-staff@mit.edu": + msg.on_time(f,10080) #in a week + + def f(msg): + msg.move(CS) + +``` + +---------- + +#### Move messeges with specific words in their subject to spam + +Move messeges that contains specific words in the subject to the spam folder + + +Tags: [] + +```python +# fired when a message arrives +def on_message(msg): + subject = msg.subject + words = ['skin', 'tags', 'shark tank', 'keto'] + if any(word in subject for word in words): + msg.move(spam) + + +``` + +---------- + +#### Automatically reply to senders who have been assigned to a specific category + +When a messege arrrives from a sender that I have assigned to the category "persistent spammers", reply to them with the following messege "Please unsubscribe me from your mailing list" every 30 minutes. + +Tags: [] + +```python +# fired when a message arrives +def on_message(msg): + if "persistent spammers" in msg.categories + msg.ontime(replyToSender, 30) + replyToSender(msg) + + def replyToSender(msg): + sender = message.from_ + msg.reply(to=[sender], content='Please unsubscribe me from your mailing list') + +``` + +---------- ### Add Your Own Examples From 2438c8d0f57f7374cd946949180b2fd99c0c6584 Mon Sep 17 00:00:00 2001 From: Soya <33616044+soyapark@users.noreply.github.com> Date: Tue, 10 Mar 2020 01:06:17 -0400 Subject: [PATCH 2/2] Update examples.md --- docs/examples.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index 459ae6a1..3e777f84 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -175,18 +175,24 @@ Tags: [] ```python # fired when a message arrives -def on_message(msg): - if msg.extract_time_entity(): - me = find_contact('me@mit.edu') - msg_subject = 'my current schedule' - msgs = me.messages_from() - old_msg = None - for m in msgs.reversed(): - if m.subject == msg_subject: - old_msg = m - break - new_content = msg.subject + msg.extract_time_entity()[0]['start'] + old_msg.content['text'] - send(to='me', subject= content=new_content) +def on_message(my_message): + msg_subject = 'my current schedule' + msgs = [] + if my_message.extract_time_entity(): + msgs = ME.messages_from() + print(msgs) + + old_msg = None + msgs.reverse() + for m in msgs: + if m.subject == msg_subject: + old_msg = m + break + # append a new schedule + new_content = "%s: %s \n" %(my_message.subject,my_message.extract_time_entity()[0]['start']) + if old_msg: + new_content += old_msg.content['text'] + send(to=ME, subject=msg_subject, body=new_content) ```