Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retire pylint and isort in favor of ruff #119

Merged
merged 10 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/isort.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/pylint.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Ruff
on:
- pull_request

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
[![Downloads](https://static.pepy.tech/badge/chat-miner/month)](https://pepy.tech/project/chat-miner)
[![codecov](https://codecov.io/gh/joweich/chat-miner/branch/main/graph/badge.svg?token=6EQF0YNGLK)](https://codecov.io/gh/joweich/chat-miner)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

**chat-miner** provides lean parsers for every major platform transforming chats into pandas dataframes. Artistic visualizations allow you to explore your data and create artwork from your chats.

Expand Down Expand Up @@ -127,4 +126,4 @@ options:
Input file to be processed
-o OUTPUT, --output OUTPUT
Output file for the results
```
```
6 changes: 3 additions & 3 deletions chatminer/chatparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, filepath: str):
def parse_file(self):
self._logger.info("Starting reading raw messages...")
self._read_raw_messages_from_file()
self._logger.info(f"Finished reading %i raw messages.", len(self._raw_messages))
self._logger.info("Finished reading %i raw messages.", len(self._raw_messages))

self._logger.info("Starting parsing raw messages...")
self._parse_raw_messages()
Expand Down Expand Up @@ -191,7 +191,7 @@ def _parse_message(self, mess: Dict[str, Any]):
elif "content" in mess:
body = mess["content"]
else:
self._logger.warning(f"Skipped message with unknown format: %s", mess)
self._logger.warning("Skipped message with unknown format: %s", mess)
return None

time = dt.datetime.fromtimestamp(mess["timestamp_ms"] / 1000)
Expand Down Expand Up @@ -233,7 +233,7 @@ def _parse_message(self, mess: Dict[str, Any]):
elif any(key == "is_unsent" for key in mess):
return None
else:
self._logger.warning(f"Skipped message with unknown format: %s", mess)
self._logger.warning("Skipped message with unknown format: %s", mess)
return None

time = dt.datetime.fromtimestamp(mess["timestamp_ms"] / 1000)
Expand Down
65 changes: 26 additions & 39 deletions chatminer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,61 @@

def get_args():
try:
parser = argparse.ArgumentParser(
cliparser = argparse.ArgumentParser(
description="chat-miner provides lean parsers for every major platform transforming chats into pandas dataframes.\
Artistic visualizations allow you to explore your data and create artwork from your chats."
)

parser.add_argument(
cliparser.add_argument(
"-p",
"--parser",
type=str,
help="The platform from which the chats are imported",
choices=["whatsapp", "instagram", "facebook", "signal", "telegram"],
)

parser.add_argument(
cliparser.add_argument(
"-i", "--input", type=str, help="Input file to be processed"
)

parser.add_argument(
cliparser.add_argument(
"-o", "--output", type=str, help="Output file for the results"
)

return parser.parse_args(), parser
except:
return cliparser.parse_args(), cliparser
except KeyboardInterrupt:
sys.exit()


def main():
try:
args, parser = get_args()
args, cliparser = get_args()

parser_type = args.parser
INPUT_FILE = args.input
OUTPUT_FILE = args.output

if INPUT_FILE == None or OUTPUT_FILE == None or parser_type == None:
if args.input is None or args.output is None or args.parser is None:
raise ValueError

if (parser_type).lower() == "whatsapp":
parser_type = WhatsAppParser(INPUT_FILE)
parser_type.parse_file()
output = parser_type.parsed_messages.get_df()

elif (parser_type).lower() == "facebook":
parser_type = FacebookMessengerParser(INPUT_FILE)
parser_type.parse_file()
output = parser_type.parsed_messages.get_df()

elif (parser_type).lower() == "instagram":
parser_type = InstagramJsonParser(INPUT_FILE)
parser_type.parse_file()
output = parser_type.parsed_messages.get_df()

elif (parser_type).lower() == "signal":
parser_type = SignalParser(INPUT_FILE)
parser_type.parse_file()
output = parser_type.parsed_messages.get_df()

elif (parser_type).lower() == "telegram":
parser_type = TelegramJsonParser(INPUT_FILE)
parser_type.parse_file()
output = parser_type.parsed_messages.get_df()
if (args.parser).lower() == "whatsapp":
chatparser = WhatsAppParser(args.input)

elif (args.parser).lower() == "facebook":
chatparser = FacebookMessengerParser(args.input)
elif (args.parser).lower() == "instagram":
chatparser = InstagramJsonParser(args.input)
elif (args.parser).lower() == "signal":
chatparser = SignalParser(args.input)
elif (args.parser).lower() == "telegram":
chatparser = TelegramJsonParser(args.input)
else:
raise ValueError

output.to_csv(OUTPUT_FILE, index=False)
chatparser.parse_file()
df = chatparser.parsed_messages.get_df()
df.to_csv(args.output, index=False)

except ValueError:
parser.print_usage()
cliparser.print_usage()

except:
except KeyboardInterrupt:
sys.exit()


Expand Down
4 changes: 2 additions & 2 deletions chatminer/nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def extract_sentiment(message: str) -> Optional[str]:
"""
try:
return str(sentiment_pipeline(message)[0]["label"])
except:
print(f"Error processing message: {message}")
except Exception as e:
print(f"Error processing message: {message}: {e}")
return None

df["sentiment"] = df["message"].apply(extract_sentiment)
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"
5 changes: 5 additions & 0 deletions test/vis/test_smoketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
def test_visualization_import():
try:
import chatminer.visualizations as vis

assert hasattr(vis, "sunburst")
assert hasattr(vis, "wordcloud")
assert hasattr(vis, "calendar_heatmap")
assert hasattr(vis, "radar")
except ImportError as e:
pytest.fail(f"Error importing visualizations: {e}")