Browse Source

Some cleanup and formatting

master
parent
commit
9495e82fab
No known key found for this signature in database GPG Key ID: DA34C790D267C164
3 changed files with 9 additions and 6 deletions
  1. +3
    -0
      tests/test_tildee.py
  2. +6
    -1
      tildee/__init__.py
  3. +0
    -5
      tildee/models.py

+ 3
- 0
tests/test_tildee.py View File

@ -1,5 +1,6 @@
from tildee.models import *
def test_topic_log_parser_links():
input = """<li class="topic-log-entry">
<a href="/user/TestUser" class="link-user">TestUser</a>
@ -11,6 +12,7 @@ def test_topic_log_parser_links():
assert output.data["old"] == "https://example.com"
assert output.data["new"] == "https://example.com/a"
def test_topic_log_parser_titles_safe():
input = """<li class="topic-log-entry">
<a href="/user/TestUser" class="link-user">TestUser</a>
@ -23,6 +25,7 @@ def test_topic_log_parser_titles_safe():
assert output.data["old"] == "More tests? Yes."
assert output.data["new"] == "More tests? Yes. No."
def test_topic_log_parser_titles_unsafe():
input = """<li class="topic-log-entry">
<a href="/user/TestUser" class="link-user">TestUser</a>


+ 6
- 1
tildee/__init__.py View File

@ -3,7 +3,12 @@ __version__ = "0.2.3"
import requests
from requests import Response
from lxml import html, etree
from tildee.models import *
from tildee.models import (
TildesTopic,
TildesComment,
TildesNotification,
TildesConversation,
)
from typing import Union, List, Optional


+ 0
- 5
tildee/models.py View File

@ -177,13 +177,10 @@ class TildesTopicLogEntry:
0
].attrib["datetime"]
edit_str = self._tree.cssselect("a.link-user")[0].tail.strip()
print(f"Input: {edit_str}")
self.kind = TildesTopicLogEntryKind.UNKNOWN
self.data = None
if edit_str.startswith("added tag") or edit_str.startswith("removed tag"):
self.kind = TildesTopicLogEntryKind.TAG_EDIT
added_str = ""
removed_str = ""
added_tags = []
removed_tags = []
if "added tag '" in edit_str:
@ -246,8 +243,6 @@ class TildesTopicLogEntry:
match = re.match("moved from ~(\\S+) to ~(\\S+)", edit_str)
self.data = {"old": match.group(1), "new": match.group(2)}
print(f"Result: {str(self.kind)[24:]} {self.data}")
class TildesTopicLogEntryKind(Enum):
"""Enum representing the possible kinds of topic log entry. Documentation includes structure for ``TildesTopicLogEntry``'s data attribute."""


Loading…
Cancel
Save