mirror of
https://github.com/bellingcat/auto-archiver.git
synced 2026-06-12 21:28:29 +03:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3b727b005 | ||
|
|
ee37b20e6c | ||
|
|
a184bf7b97 | ||
|
|
e535f44a88 | ||
|
|
0f28bf0e35 | ||
|
|
18a8636552 |
@@ -2,3 +2,4 @@ from .database import Database
|
|||||||
from .gsheet_db import GsheetsDb
|
from .gsheet_db import GsheetsDb
|
||||||
from .console_db import ConsoleDb
|
from .console_db import ConsoleDb
|
||||||
from .csv_db import CSVDb
|
from .csv_db import CSVDb
|
||||||
|
from .api_db import AAApiDb
|
||||||
41
src/auto_archiver/databases/api_db.py
Normal file
41
src/auto_archiver/databases/api_db.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import requests, os
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from . import Database
|
||||||
|
from ..core import Metadata
|
||||||
|
|
||||||
|
|
||||||
|
class AAApiDb(Database):
|
||||||
|
"""
|
||||||
|
Connects to auto-archiver-api instance
|
||||||
|
"""
|
||||||
|
name = "auto_archiver_api_db"
|
||||||
|
|
||||||
|
def __init__(self, config: dict) -> None:
|
||||||
|
# without this STEP.__init__ is not called
|
||||||
|
super().__init__(config)
|
||||||
|
self.assert_valid_string("api_endpoint")
|
||||||
|
self.assert_valid_string("api_secret")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def configs() -> dict:
|
||||||
|
return {
|
||||||
|
"api_endpoint": {"default": None, "help": "API endpoint where calls are made to"},
|
||||||
|
"api_secret": {"default": None, "help": "API authentication secret"},
|
||||||
|
"public": {"default": False, "help": "whether the URL should be publicly available via the API"},
|
||||||
|
"author_id": {"default": None, "help": "which email to assign as author"},
|
||||||
|
"group_id": {"default": None, "help": "which group of users have access to the archive in case public=false as author"},
|
||||||
|
"tags": {"default": [], "help": "what tags to add to the archived URL", "cli_set": lambda cli_val, cur_val: set(cli_val.split(","))},
|
||||||
|
}
|
||||||
|
|
||||||
|
def done(self, item: Metadata) -> None:
|
||||||
|
"""archival result ready - should be saved to DB"""
|
||||||
|
logger.info(f"saving archive of {item.get_url()} to the AA API.")
|
||||||
|
|
||||||
|
payload = {'result': item.to_json(), 'public': self.public, 'author_id': self.author_id, 'group_id': self.group_id, 'tags': list(self.tags)}
|
||||||
|
response = requests.post(os.path.join(self.api_endpoint, "submit-archive"), json=payload, auth=("abc", self.api_secret))
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
logger.success(f"AA API: {response.json()}")
|
||||||
|
else:
|
||||||
|
logger.error(f"AA API FAIL ({response.status_code}): {response.json()}")
|
||||||
@@ -64,7 +64,10 @@ class GsheetsFeeder(Gsheets, Feeder):
|
|||||||
# All checks done - archival process starts here
|
# All checks done - archival process starts here
|
||||||
m = Metadata().set_url(url)
|
m = Metadata().set_url(url)
|
||||||
ArchivingContext.set("gsheet", {"row": row, "worksheet": gw}, keep_on_reset=True)
|
ArchivingContext.set("gsheet", {"row": row, "worksheet": gw}, keep_on_reset=True)
|
||||||
folder = slugify(gw.get_cell(row, 'folder').strip())
|
if gw.get_cell_or_default(row, 'folder', "") is None:
|
||||||
|
folder = ''
|
||||||
|
else:
|
||||||
|
folder = slugify(gw.get_cell_or_default(row, 'folder', "").strip())
|
||||||
if len(folder):
|
if len(folder):
|
||||||
if self.use_sheet_names_in_stored_paths:
|
if self.use_sheet_names_in_stored_paths:
|
||||||
ArchivingContext.set("folder", os.path.join(folder, slugify(self.sheet), slugify(wks.title)), True)
|
ArchivingContext.set("folder", os.path.join(folder, slugify(self.sheet), slugify(wks.title)), True)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ _MAJOR = "0"
|
|||||||
_MINOR = "5"
|
_MINOR = "5"
|
||||||
# On main and in a nightly release the patch should be one ahead of the last
|
# On main and in a nightly release the patch should be one ahead of the last
|
||||||
# released build.
|
# released build.
|
||||||
_PATCH = "18"
|
_PATCH = "20"
|
||||||
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
|
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
|
||||||
# https://semver.org/#is-v123-a-semantic-version for the semantics.
|
# https://semver.org/#is-v123-a-semantic-version for the semantics.
|
||||||
_SUFFIX = ""
|
_SUFFIX = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user