Add XML and YAML to archiver
This commit is contained in:
parent
959b55a939
commit
1bf1db707c
|
@ -4,7 +4,9 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import dict2xml
|
||||||
import praw.models
|
import praw.models
|
||||||
|
import yaml
|
||||||
|
|
||||||
from bulkredditdownloader.archive_entry import ArchiveEntry
|
from bulkredditdownloader.archive_entry import ArchiveEntry
|
||||||
from bulkredditdownloader.configuration import Configuration
|
from bulkredditdownloader.configuration import Configuration
|
||||||
|
@ -45,7 +47,16 @@ class Archiver(RedditDownloader):
|
||||||
json.dump(entry.compile(), file)
|
json.dump(entry.compile(), file)
|
||||||
|
|
||||||
def _write_submission_xml(self, entry: ArchiveEntry):
|
def _write_submission_xml(self, entry: ArchiveEntry):
|
||||||
raise NotImplementedError
|
resource = Resource(entry.submission, '', '.xml')
|
||||||
|
file_path = self.file_name_formatter.format_path(resource, self.download_directory)
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
logger.debug(f'Writing submission {entry.submission.id} to file in XML format at {file_path}')
|
||||||
|
xml_entry = dict2xml.dict2xml(entry.compile(), wrap='root')
|
||||||
|
file.write(xml_entry)
|
||||||
|
|
||||||
def _write_submission_yaml(self, entry: ArchiveEntry):
|
def _write_submission_yaml(self, entry: ArchiveEntry):
|
||||||
raise NotImplementedError
|
resource = Resource(entry.submission, '', '.yaml')
|
||||||
|
file_path = self.file_name_formatter.format_path(resource, self.download_directory)
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
logger.debug(f'Writing submission {entry.submission.id} to file in YAML format at {file_path}')
|
||||||
|
yaml.dump(entry.compile(), file)
|
||||||
|
|
|
@ -26,11 +26,31 @@ def test_write_submission_json(test_submission_id: str, tmp_path: Path, reddit_i
|
||||||
assert test_path.exists()
|
assert test_path.exists()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip
|
@pytest.mark.online
|
||||||
def test_write_submission_xml():
|
@pytest.mark.reddit
|
||||||
raise NotImplementedError
|
@pytest.mark.parametrize('test_submission_id', (
|
||||||
|
'm3reby',
|
||||||
|
))
|
||||||
|
def test_write_submission_xml(test_submission_id: str, tmp_path: Path, reddit_instance: praw.Reddit):
|
||||||
|
archiver_mock = MagicMock()
|
||||||
|
test_path = Path(tmp_path, 'test.xml')
|
||||||
|
test_submission = reddit_instance.submission(id=test_submission_id)
|
||||||
|
archiver_mock.file_name_formatter.format_path.return_value = test_path
|
||||||
|
test_entry = ArchiveEntry(test_submission)
|
||||||
|
Archiver._write_submission_xml(archiver_mock, test_entry)
|
||||||
|
assert test_path.exists()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip
|
@pytest.mark.online
|
||||||
def test_write_submission_yaml():
|
@pytest.mark.reddit
|
||||||
raise NotImplementedError
|
@pytest.mark.parametrize('test_submission_id', (
|
||||||
|
'm3reby',
|
||||||
|
))
|
||||||
|
def test_write_submission_yaml(test_submission_id: str, tmp_path: Path, reddit_instance: praw.Reddit):
|
||||||
|
archiver_mock = MagicMock()
|
||||||
|
test_path = Path(tmp_path, 'test.yaml')
|
||||||
|
test_submission = reddit_instance.submission(id=test_submission_id)
|
||||||
|
archiver_mock.file_name_formatter.format_path.return_value = test_path
|
||||||
|
test_entry = ArchiveEntry(test_submission)
|
||||||
|
Archiver._write_submission_yaml(archiver_mock, test_entry)
|
||||||
|
assert test_path.exists()
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
appdirs
|
appdirs
|
||||||
bs4
|
bs4
|
||||||
click
|
click
|
||||||
|
dict2xml
|
||||||
ffmpeg-python
|
ffmpeg-python
|
||||||
praw
|
praw
|
||||||
|
pyyaml
|
||||||
requests
|
requests
|
||||||
youtube-dl
|
youtube-dl
|
Loading…
Reference in a new issue