Skip to content

Commit

Permalink
fixup some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zstyblik committed Jun 30, 2024
1 parent 4bdaff3 commit c6b9087
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
5 changes: 3 additions & 2 deletions gh2slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import rss2irc # noqa: I202
import rss2slack
from lib import CachedData
from lib import config_options

ALIASES = {
Expand Down Expand Up @@ -304,7 +305,7 @@ def parse_args() -> argparse.Namespace:

def process_page_items(
logger: logging.Logger,
cache: rss2irc.CachedData,
cache: CachedData,
pages: List,
expiration: int,
repository_url: str,
Expand Down Expand Up @@ -348,7 +349,7 @@ def process_page_items(
return to_publish


def scrub_items(logger: logging.Logger, cache: rss2irc.CachedData) -> None:
def scrub_items(logger: logging.Logger, cache: CachedData) -> None:
"""Scrub cache and remove expired items."""
time_now = int(time.time())
for key in list(cache.items.keys()):
Expand Down
9 changes: 5 additions & 4 deletions phpbb2slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import feedparser

import rss2irc # noqa: I202
import rss2slack
import rss2slack # noqa: I202
from lib import CachedData # noqa: I202

CACHE_EXPIRATION = 86400 # seconds
HTTP_TIMEOUT = 30 # seconds
Expand Down Expand Up @@ -274,7 +275,7 @@ def parse_news(data: str, authors: List[str]) -> Dict:

def prune_news(
logger: logging.Logger,
cache: rss2irc.CachedData,
cache: CachedData,
news: Dict[str, Dict],
expiration: int = CACHE_EXPIRATION,
) -> None:
Expand All @@ -292,7 +293,7 @@ def prune_news(
news.pop(key)


def scrub_items(logger: logging.Logger, cache: rss2irc.CachedData) -> None:
def scrub_items(logger: logging.Logger, cache: CachedData) -> None:
"""Scrub cache and remove expired items."""
time_now = int(time.time())
for key in list(cache.items.keys()):
Expand All @@ -312,7 +313,7 @@ def scrub_items(logger: logging.Logger, cache: rss2irc.CachedData) -> None:


def update_items_expiration(
cache: rss2irc.CachedData, news: Dict, expiration: int
cache: CachedData, news: Dict, expiration: int
) -> None:
"""Update cache contents."""
item_expiration = int(time.time()) + expiration
Expand Down
5 changes: 3 additions & 2 deletions tests/test_gh2slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import gh2slack # noqa:I100,I202
import rss2irc # noqa:I100,I202
from lib import CachedData # noqa:I100,I202

SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -351,7 +352,7 @@ def test_process_page_items():
],
]
repository_url = "http://example.com"
cache = rss2irc.CachedData(
cache = CachedData(
items={
"http://example.com/bar": {
"expiration": 0,
Expand Down Expand Up @@ -391,7 +392,7 @@ def test_process_page_items():
def test_scrub_items():
"""Test scrub_items()."""
item_expiration = int(time.time()) + 60
test_cache = rss2irc.CachedData(
test_cache = CachedData(
items={
"foo": {
"expiration": item_expiration,
Expand Down
9 changes: 5 additions & 4 deletions tests/test_phpbb2slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import phpbb2slack # noqa:I100,I202
import rss2irc
from lib import CachedData
from lib import config_options

ITEM_EXPIRATION = int(time.time())
Expand Down Expand Up @@ -157,7 +158,7 @@ def test_main_ideal(
)
fixture_http_server.capture_requests = True

cache = rss2irc.CachedData()
cache = CachedData()
source1 = cache.get_source_by_url(rss_url)
source1.http_etag = ""
source1.http_last_modified = ""
Expand Down Expand Up @@ -264,7 +265,7 @@ def test_main_cache_hit(
)
fixture_http_server.capture_requests = True

cache = rss2irc.CachedData()
cache = CachedData()
source1 = cache.get_source_by_url(rss_url)
source1.http_etag = "pytest_etag"
source1.http_last_modified = "pytest_lm"
Expand Down Expand Up @@ -361,7 +362,7 @@ def test_parse_news():
"cache,expected_cache",
[
(
rss2irc.CachedData(
CachedData(
items={
"foo": {
"expiration": get_item_expiration() + 60,
Expand Down Expand Up @@ -402,7 +403,7 @@ def test_scrub_items(cache, expected_cache):
"comments_cnt": 20,
},
},
rss2irc.CachedData(
CachedData(
items={
"http://example.com": {
"expiration": 0,
Expand Down
14 changes: 7 additions & 7 deletions tests/test_rss2irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import pytest

import rss2irc # noqa:I202
from lib import CachedData
from lib import config_options
from lib import HTTPSource
from lib import CachedData # noqa:I202
from lib import config_options # noqa:I202
from lib import HTTPSource # noqa:I202

SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -182,7 +182,7 @@ def test_main_ideal(
{"ETag": "pytest_etag", "Last-Modified": "pytest_lm"},
)

cache = rss2irc.CachedData()
cache = CachedData()
source1 = cache.get_source_by_url(rss_url)
source1.http_etag = ""
source1.http_last_modified = ""
Expand Down Expand Up @@ -284,7 +284,7 @@ def test_main_cache_operations(
{"ETag": "pytest_etag", "Last-Modified": "pytest_lm"},
)

cache = rss2irc.CachedData()
cache = CachedData()
cache.items[cache_key] = frozen_ts + 60
cache.items["https://expired.example.com"] = 123456
source1 = cache.get_source_by_url(rss_url)
Expand Down Expand Up @@ -379,7 +379,7 @@ def test_main_cache_hit(
},
)

cache = rss2irc.CachedData()
cache = CachedData()
source1 = cache.get_source_by_url(rss_url)
source1.http_etag = "pytest_etag"
source1.http_last_modified = "pytest_last_modified"
Expand Down Expand Up @@ -472,7 +472,7 @@ def test_scrub_items():
logger.disabled = True

item_expiration = int(time.time()) + 60
test_cache = rss2irc.CachedData(
test_cache = CachedData(
items={
"foo": item_expiration,
"bar": int(time.time()) - 3600,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_rss2slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import rss2irc # noqa:I100,I202
import rss2slack # noqa:I100,I202
from lib import CachedData
from lib import config_options

SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -151,7 +152,7 @@ def test_main_ideal(
)
fixture_http_server.capture_requests = True

cache = rss2irc.CachedData()
cache = CachedData()
source1 = cache.get_source_by_url(rss_url)
source1.http_etag = ""
source1.http_last_modified = ""
Expand Down Expand Up @@ -263,7 +264,7 @@ def test_main_cache_hit(
)
fixture_http_server.capture_requests = True

cache = rss2irc.CachedData()
cache = CachedData()
source1 = cache.get_source_by_url(rss_url)
source1.http_etag = "pytest_etag"
source1.http_last_modified = "pytest_lm"
Expand Down

0 comments on commit c6b9087

Please sign in to comment.