Skip to content

Commit c7c7eb0

Browse files
authored
Merge pull request #286 from bellingcat/version_comparison
Small code fixes and GH Actions cache
2 parents 8685b6b + 7e4ba62 commit c7c7eb0

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

.github/workflows/tests-core.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,23 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@v4
3030

31-
- name: Install Poetry
32-
run: pipx install poetry
33-
3431
- name: Set up Python ${{ matrix.python-version }}
3532
uses: actions/setup-python@v5
3633
with:
3734
python-version: ${{ matrix.python-version }}
3835

39-
- name: Install dependencies
36+
- name: Install latest Poetry
37+
run: pipx install poetry
38+
39+
- name: Cache Poetry and pip artifacts
40+
uses: actions/cache@v4
41+
with:
42+
path: |
43+
~/.cache/pypoetry
44+
~/.cache/pip
45+
key: poetry-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
46+
47+
- name: Install dependencies from source only
4048
run: poetry install --no-interaction --with dev
4149

4250
- name: Run Core Tests

.github/workflows/tests-download.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424

25-
- name: Install poetry
26-
run: pipx install poetry
27-
2825
- name: Set up Python ${{ matrix.python-version }}
2926
uses: actions/setup-python@v5
3027
with:
3128
python-version: ${{ matrix.python-version }}
3229

33-
- name: Install dependencies
30+
- name: Install latest Poetry
31+
run: pipx install poetry
32+
33+
- name: Cache Poetry and pip artifacts
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
~/.cache/pypoetry
38+
~/.cache/pip
39+
key: poetry-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
40+
41+
- name: Install dependencies from source only
3442
run: poetry install --no-interaction --with dev
3543

3644
- name: Run Download Tests

src/auto_archiver/core/orchestrator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from __future__ import annotations
8+
from packaging import version
89
from typing import Generator, Union, List, Type, TYPE_CHECKING
910
import argparse
1011
import os
@@ -436,16 +437,19 @@ def setup_config(self, args: list) -> dict:
436437

437438
def check_for_updates(self):
438439
response = requests.get("https://pypi.org/pypi/auto-archiver/json").json()
439-
latest_version = response["info"]["version"]
440+
latest_version = version.parse(response["info"]["version"])
441+
current_version = version.parse(__version__)
440442
# check version compared to current version
441-
if latest_version != __version__:
443+
if latest_version > current_version:
442444
if os.environ.get("RUNNING_IN_DOCKER"):
443445
update_cmd = "`docker pull bellingcat/auto-archiver:latest`"
444446
else:
445447
update_cmd = "`pip install --upgrade auto-archiver`"
446448
logger.warning("")
447449
logger.warning("********* IMPORTANT: UPDATE AVAILABLE ********")
448-
logger.warning(f"A new version of auto-archiver is available (v{latest_version}, you have {__version__})")
450+
logger.warning(
451+
f"A new version of auto-archiver is available (v{latest_version}, you have v{current_version})"
452+
)
449453
logger.warning(f"Make sure to update to the latest version using: {update_cmd}")
450454
logger.warning("")
451455

src/auto_archiver/modules/gsheet_feeder_db/gsheet_feeder_db.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ def should_process_sheet(self, sheet_name: str) -> bool:
8888
if len(self.allow_worksheets) and sheet_name not in self.allow_worksheets:
8989
# ALLOW rules exist AND sheet name not explicitly allowed
9090
return False
91-
if len(self.block_worksheets) and sheet_name in self.block_worksheets:
92-
# BLOCK rules exist AND sheet name is blocked
93-
return False
94-
return True
91+
return not (self.block_worksheets and sheet_name in self.block_worksheets)
9592

9693
def missing_required_columns(self, gw: GWorksheet) -> list:
9794
missing = []
@@ -161,9 +158,8 @@ def batch_if_valid(col, val, final_value=None):
161158
if (screenshot := item.get_media_by_id("screenshot")) and hasattr(screenshot, "urls"):
162159
batch_if_valid("screenshot", "\n".join(screenshot.urls))
163160

164-
if thumbnail := item.get_first_image("thumbnail"):
165-
if hasattr(thumbnail, "urls"):
166-
batch_if_valid("thumbnail", f'=IMAGE("{thumbnail.urls[0]}")')
161+
if (thumbnail := item.get_first_image("thumbnail")) and hasattr(thumbnail, "urls"):
162+
batch_if_valid("thumbnail", f'=IMAGE("{thumbnail.urls[0]}")')
167163

168164
if browsertrix := item.get_media_by_id("browsertrix"):
169165
batch_if_valid("wacz", "\n".join(browsertrix.urls))

src/auto_archiver/modules/telethon_extractor/telethon_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _get_media_posts_in_group(self, chat, original_post, max_amp=10):
190190
if getattr(original_post, "grouped_id", None) is None:
191191
return [original_post] if getattr(original_post, "media", False) else []
192192

193-
search_ids = [i for i in range(original_post.id - max_amp, original_post.id + max_amp + 1)]
193+
search_ids = list(range(original_post.id - max_amp, original_post.id + max_amp + 1))
194194
posts = self.client.get_messages(chat, ids=search_ids)
195195
media = []
196196
for post in posts:

0 commit comments

Comments
 (0)