Skip to content

Commit

Permalink
Major changes to doc and code (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunaljubce authored Sep 15, 2024
1 parent 52bdaa3 commit e4158ec
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 287 deletions.
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ sqlalchemy = "*"
openpyxl = "*"
pandas = "*"
pytest = "*"
oauth2client = "*"

[dev-packages]

[requires]
python_version = "3.8"
python_version = "3.12"

[scripts]
clingy = "env PYTHONPATH=${PYTHONPATH}:${PWD} python src/main.py"
517 changes: 241 additions & 276 deletions Pipfile.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ Clingy is a CLI (Command Line Interface) tool that will purge your mailbox of un
* Setup the environment using the command - `pipenv sync -d`. This will setup your virtual environment using Pipfile.Lock.

#### Test if your credentials.json is valid
* Execute the command - `pipenv run pytest`.
* Execute the command - `pipenv run pytest tests/test_user_setup.py`.

If your authentication is working fine, the test will succeed and you should see the below message -
```
→ pipenv run pytest
======================================================================= test session starts =======================================================================
→ pipenv run pytest tests/test_user_setup.py
==================================== test session starts ====================================
platform darwin -- Python 3.8.18, pytest-7.4.4, pluggy-1.3.0
rootdir: /Users/a81045729/Documents/constant_variables/gmail-cleaner
configfile: pytest.ini
collected 1 item
tests/test_auth.py . [100%]
tests/test_user_setup.py . [100%]
======================================================================== 1 passed in 0.94s ========================================================================
===================================== 1 passed in 0.94s =====================================
```

For first time users, you will be redirected to a Google screen to choose your Gmail account and authenticate the application as below. If you have used Clingy before, you should not have to follow the below steps and instead you will directly see the above success message on your console.
Expand Down
4 changes: 4 additions & 0 deletions src/custom_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class AuthenticationException(Exception):

def __init__(self, message) -> None:
self.message = message
8 changes: 7 additions & 1 deletion src/get_gmail_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#############################################################################################################################################
# Command to run: pipenv run clingy --labels-and-types '{"category_promotions":"unread"}' #
# Command to run: pipenv run clingy --labels '{"category_promotions":"unread"}' #
#############################################################################################################################################

from __future__ import print_function
from time import perf_counter
from typing import Dict, Tuple

MAX_RESULTS_BATCHSIZE = 50
Expand Down Expand Up @@ -45,6 +46,8 @@ def extract_message_metadata_from_labels(label: Dict, service: object, labels_an
delete_msgs_from_labels = list(labels_and_msg_types.keys())
extracted_msg_metadata_list = []

t1_start = perf_counter()

if label['name'].lower() in delete_msgs_from_labels:
label_dtls = service.users().labels().get(userId="me", id=label['name']).execute()
total_msg_count_in_label, unread_msg_count_in_label = label_dtls['messagesTotal'], label_dtls['messagesUnread']
Expand All @@ -65,5 +68,8 @@ def extract_message_metadata_from_labels(label: Dict, service: object, labels_an
extracted_msg_metadata_dict = extract_message_contents(msg_to_be_deleted)
extracted_msg_metadata_list.append(extracted_msg_metadata_dict)

t1_stop = perf_counter()
print("Time taken: ", t1_stop - t1_start)

return (msg_ids_in_label, extracted_msg_metadata_list)

3 changes: 2 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ def main(self):

if __name__ == '__main__':
clingy = Clingy('credentials.json')
clingy.main()
clingy.main()

10 changes: 10 additions & 0 deletions tests/test_user_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest
from src.main import Clingy

def test_user_setup():
clingy = Clingy('credentials.json')

try:
clingy.authenticate()
except Exception as e:
pytest.fail(f"User authentication failed with error: {str(e)}")
6 changes: 3 additions & 3 deletions utils/welcome.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def welcome_screen() -> None:

print("""
____ _ _
print(r"""
____ _ _
/ ___| (_)_ __ __ _ _ _
| | | | | '_ \ / _` | | | |
| |___| | | | | | (_| | |_| |
\____|_|_|_| |_|\__, |\__, |
|___/ |__/
Clingy 1.0 welcomes you!
""")

0 comments on commit e4158ec

Please sign in to comment.