From f8cb5893fbe20a9d4640a495b856b08774b29bae Mon Sep 17 00:00:00 2001 From: Jeremy Ephron Barenholtz Date: Sun, 13 Sep 2020 12:49:09 -0700 Subject: [PATCH 1/4] Update README.md --- README.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5977e35..87c3332 100644 --- a/README.md +++ b/README.md @@ -217,21 +217,28 @@ from simplegmail.query import construct_query gmail = Gmail() +labels = gmail.list_labels() + +# To find a label by the name that you know (just an example): +finance_label = list(filter(lambda x: x.name == 'Finance', labels))[0] +homework_label = list(filter(lambda x: x.name == 'Homework', labels))[0] +cs_label = list(filter(lambda x: x.name == 'CS', labels))[0] + # Unread messages in inbox with label "Work" -messages = gmail.get_unread_inbox(label_ids=["Work"]) +messages = gmail.get_unread_inbox(labels=[finance_label]) # For even more control use queries: -# Messages that are: newer than 2 days old, unread, labeled "Work" or both "Homework" and "CS" +# Messages that are: newer than 2 days old, unread, labeled "Finance" or both "Homework" and "CS" query_params = { "newer_than": (2, "day"), "unread": True, - "labels":[["Work"], ["Homework", "CS"]] + "labels":[[finance_label], [homework_label, cs_label]] } messages = gmail.get_messages(query=construct_query(query_params)) # We could have also accomplished this with -# messages = gmail.get_unread_messages(query=construct_query(newer_than=(2, "day"), labels=[["Work"], ["Homework", "CS"]])) +# messages = gmail.get_unread_messages(query=construct_query(newer_than=(2, "day"), labels=[[finance_label], [homework_label, cs_label]])) # There are many, many different ways of achieving the same result with search. ``` @@ -245,21 +252,29 @@ gmail = Gmail() # For even more control use queries: # Messages that are either: -# newer than 2 days old, unread, labeled "Work" or both "Homework" and "CS" +# newer than 2 days old, unread, labeled "Finance" or both "Homework" and "CS" # or # newer than 1 month old, unread, labeled "Top Secret", but not starred. +labels = gmail.list_labels() + +# To find a label by the name that you know (just an example): +finance_label = list(filter(lambda x: x.name == 'Finance', labels))[0] +homework_label = list(filter(lambda x: x.name == 'Homework', labels))[0] +cs_label = list(filter(lambda x: x.name == 'CS', labels))[0] +top_secret_label = list(filter(lambda x: x.name == 'Top Secret', labels))[0] + # Construct our two queries separately query_params_1 = { "newer_than": (2, "day"), "unread": True, - "labels":[["Work"], ["Homework", "CS"]] + "labels":[[finance_label], [homework_label, cs_label]] } query_params_2 = { "newer_than": (1, "month"), "unread": True, - "labels": ["Top Secret"], + "labels": [top_secret_label], "starred": True, "exclude_starred": True } From de69e5ac7f21e26f0db776d5798f7f0a883559eb Mon Sep 17 00:00:00 2001 From: Jeremy Ephron Barenholtz Date: Sun, 13 Sep 2020 13:04:35 -0700 Subject: [PATCH 2/4] Update README.md --- README.md | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 87c3332..3bf8424 100644 --- a/README.md +++ b/README.md @@ -217,28 +217,24 @@ from simplegmail.query import construct_query gmail = Gmail() +# Unread messages in inbox with label "Work" labels = gmail.list_labels() +work_label = list(filter(lambda x: x.name == 'Work', labels))[0] -# To find a label by the name that you know (just an example): -finance_label = list(filter(lambda x: x.name == 'Finance', labels))[0] -homework_label = list(filter(lambda x: x.name == 'Homework', labels))[0] -cs_label = list(filter(lambda x: x.name == 'CS', labels))[0] - -# Unread messages in inbox with label "Work" -messages = gmail.get_unread_inbox(labels=[finance_label]) +messages = gmail.get_unread_inbox(labels=[work_label]) # For even more control use queries: # Messages that are: newer than 2 days old, unread, labeled "Finance" or both "Homework" and "CS" query_params = { "newer_than": (2, "day"), "unread": True, - "labels":[[finance_label], [homework_label, cs_label]] + "labels":[["Work"], ["Homework", "CS"]] } messages = gmail.get_messages(query=construct_query(query_params)) # We could have also accomplished this with -# messages = gmail.get_unread_messages(query=construct_query(newer_than=(2, "day"), labels=[[finance_label], [homework_label, cs_label]])) +# messages = gmail.get_unread_messages(query=construct_query(newer_than=(2, "day"), labels=[["Work"], ["Homework", "CS"]])) # There are many, many different ways of achieving the same result with search. ``` @@ -258,23 +254,17 @@ gmail = Gmail() labels = gmail.list_labels() -# To find a label by the name that you know (just an example): -finance_label = list(filter(lambda x: x.name == 'Finance', labels))[0] -homework_label = list(filter(lambda x: x.name == 'Homework', labels))[0] -cs_label = list(filter(lambda x: x.name == 'CS', labels))[0] -top_secret_label = list(filter(lambda x: x.name == 'Top Secret', labels))[0] - # Construct our two queries separately query_params_1 = { "newer_than": (2, "day"), "unread": True, - "labels":[[finance_label], [homework_label, cs_label]] + "labels":[["Finance"], ["Homework", "CS"]] } query_params_2 = { "newer_than": (1, "month"), "unread": True, - "labels": [top_secret_label], + "labels": ["Top Secret"], "starred": True, "exclude_starred": True } From 7b7c6fde49472cd8daa5312b468ed29a3b1affaa Mon Sep 17 00:00:00 2001 From: Jeremy Ephron Barenholtz Date: Sun, 13 Sep 2020 13:12:39 -0700 Subject: [PATCH 3/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3bf8424..3df6a24 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ A simple Gmail API client in Python for applications. +# Note about upgrading to v3.0.0 + +The newest release is not backwards compatible with previous versions, so you'll need to re-authenticate tokens you have for existing projects upon upgrading. + Currently Supported Behavior: - Sending html messages - Sending messages with attachments From a6c7ddc7ca23e209f300bf58b87426cf4c66c8c1 Mon Sep 17 00:00:00 2001 From: Jeremy Ephron Barenholtz Date: Sun, 13 Sep 2020 13:13:03 -0700 Subject: [PATCH 4/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3df6a24..8adbf33 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ A simple Gmail API client in Python for applications. The newest release is not backwards compatible with previous versions, so you'll need to re-authenticate tokens you have for existing projects upon upgrading. +--- + Currently Supported Behavior: - Sending html messages - Sending messages with attachments