Skip to content

Commit

Permalink
Merge pull request #78 from sgratzl/sgratzl/fix_missing_mode
Browse files Browse the repository at this point in the history
fix missing mode + add .dt attribute
  • Loading branch information
sgratzl authored Jul 21, 2022
2 parents 27ce66e + c2ec94e commit 0a52a3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-dev.txt') }}
key: ${{ runner.os }}-pip2-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip2-${{ matrix.python-version }}-
- name: Install dependencies
run: |
pip install -r requirements.txt -r requirements-dev.txt
Expand Down
77 changes: 2 additions & 75 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,82 +54,15 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
cyclic-import,
disable=cyclic-import,
unexpected-line-ending-format,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
locally-enabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
bad-continuation,
broad-except,
too-many-locals,
too-many-lines
Expand Down Expand Up @@ -250,6 +183,7 @@ good-names=i,
Run,
_,
ts,
dt,
id

# Include a hint for the correct naming format with invalid-name
Expand Down Expand Up @@ -402,13 +336,6 @@ max-line-length=200
# Maximum number of lines in a module
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
17 changes: 14 additions & 3 deletions slack_cleaner2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from logging import Logger
from time import sleep
from functools import cached_property
from datetime import datetime
import requests
from requests import Response
from slack_sdk import WebClient
Expand Down Expand Up @@ -345,10 +346,18 @@ class SlackMessage:
"""
message timestamp
"""
dt: datetime
"""
message timestamp as datetime
"""
thread_ts: Optional[float]
"""
message timestamp for its thread
"""
thread_dt: Optional[datetime]
"""
message timestamp for its thread as datetime
"""

text: str
"""
Expand Down Expand Up @@ -404,6 +413,7 @@ def __init__(self, entry: JSONDict, channel: SlackChannel, slack: "SlackCleaner"
:type slack: SlackCleaner
"""
self.ts = float(entry["ts"])
self.dt = datetime.fromtimestamp(self.ts)
self.text = entry["text"]
self.channel = channel
self._slack = slack
Expand All @@ -413,13 +423,14 @@ def __init__(self, entry: JSONDict, channel: SlackChannel, slack: "SlackCleaner"
self.pinned_to = entry.get("pinned_to", False)
self.has_replies = entry.get("reply_count", 0) > 0
self.thread_ts = float(entry.get("thread_ts", entry["ts"]))
self.files = [SlackFile(f, slack) for f in entry.get("files", []) if f["mode"] != "tombstone"]
self.thread_dt = datetime.fromtimestamp(self.thread_ts)
self.files = [SlackFile(f, slack) for f in entry.get("files", []) if f.get("mode", "tombstone") != "tombstone"]
self.is_tombstone = entry.get("subtype", None) == "tombstone"

@cached_property
def user(self) -> Optional[SlackUser]:
"""
user sending the messsage
user sending the message
"""
return self._slack.users.resolve_user(self.user_id) if self.user_id else None

Expand Down Expand Up @@ -508,7 +519,7 @@ def parse_reaction(reaction: JSONDict) -> "SlackMessageReaction":
def __str__(self):
user_name = "bot" if self.bot else self.user
text = self.text[0:20] if len(self.text) > 20 else self.text
return f"{self.channel.name}:{self.ts} ({user_name}): {text}"
return f"{self.channel.name}:{self.dt.isoformat()} ({user_name}): {text}"

def __repr__(self):
return str(self)
Expand Down

0 comments on commit 0a52a3d

Please sign in to comment.