Skip to content

Commit

Permalink
fix for python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
carderne committed Mar 27, 2024
1 parent 5dd8c3b commit 60c11ad
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions sigexport/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
def fetch_data(
db_file: Path,
key: str,
chats: str | None = None,
include_empty: bool = False,
chats: str,
include_empty: bool,
) -> tuple[models.Convos, models.Contacts]:
"""Load SQLite data into dicts."""
contacts: models.Contacts = {}
convos: models.Convos = {}
chats_list = chats.split(",") if chats else []
chats_list = chats.split(",") if len(chats) > 0 else []

db = sqlcipher.connect(str(db_file)) # type: ignore
c = db.cursor()
Expand Down
4 changes: 2 additions & 2 deletions sigexport/logging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typer import secho
from typer import colors, secho

verbose = False


def log(msg: str, fg: str | None = None) -> None:
def log(msg: str, fg: str = colors.BLACK) -> None:
if verbose:
secho(msg, fg=fg)
4 changes: 2 additions & 2 deletions sigexport/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def main(
paginate: int = Option(
100, "--paginate", "-p", help="Messages per page in HTML; set to 0 for infinite"
),
chats: OptionalStr = Option(
None, help="Comma-separated chat names to include: contact names or group names"
chats: str = Option(
"", help="Comma-separated chat names to include: contact names or group names"
),
json_output: bool = Option(
False, "--json/--no-json", "-j", help="Whether to create JSON output"
Expand Down
14 changes: 8 additions & 6 deletions sigexport/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import re
from collections import namedtuple
Expand Down Expand Up @@ -30,7 +32,7 @@ class RawMessage:
sticker: dict[str, Any] | None
quote: dict[str, Any] | None

def get_ts(self: "RawMessage") -> int:
def get_ts(self: RawMessage) -> int:
if self.sent_at:
return self.sent_at
elif self.timestamp:
Expand Down Expand Up @@ -97,7 +99,7 @@ class Message:
reactions: list[Reaction]
attachments: list[Attachment]

def to_md(self: "Message") -> str:
def to_md(self: Message) -> str:
date_str = self.date.strftime("%Y-%m-%d %H:%M:%S")
body = self.body

Expand All @@ -115,16 +117,16 @@ def to_md(self: "Message") -> str:

return f"[{date_str}] {self.sender}: {self.quote}{body}\n"

def comp(self: "Message") -> tuple[datetime, str, str]:
def comp(self: Message) -> tuple[datetime, str, str]:
date = self.date.replace(second=0, microsecond=0)
return (date, self.sender, self.body.replace("\n", "").replace(">", ""))

def dict(self: "Message") -> dict:
def dict(self: Message) -> dict:
msg_dict = asdict(self)
msg_dict["date"] = msg_dict["date"].isoformat()
return msg_dict

def dict_str(self: "Message") -> str:
def dict_str(self: Message) -> str:
return json.dumps(self.dict(), ensure_ascii=False)


Expand All @@ -137,7 +139,7 @@ class MergeMessage:
sender: str
body: str

def to_message(self: "MergeMessage") -> Message:
def to_message(self: MergeMessage) -> Message:
body = self.body

p_reactions = re.compile(r"\n\(- (.*) -\)")
Expand Down
4 changes: 3 additions & 1 deletion sigexport/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from datetime import datetime
from pathlib import Path
from typing import cast

import emoji
from typer import Exit, secho
Expand All @@ -24,7 +25,8 @@ def parse_datetime(input_str: str) -> datetime:
return datetime.strptime(input_str, fmt)
except ValueError as e:
last_exception = e
raise (last_exception)
exception = cast(ValueError, last_exception)
raise (exception)


def version_callback(value: bool) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_integration():
source=source,
old=None,
paginate=100,
chats=None,
chats="",
list_chats=False,
include_empty=False,
verbose=True,
Expand Down

0 comments on commit 60c11ad

Please sign in to comment.