From f199b9bc0cabff291e38bae3bbf296f0ddd37c8f Mon Sep 17 00:00:00 2001 From: Christopher Kreft Date: Thu, 17 Aug 2023 16:30:58 +0200 Subject: [PATCH] remove anonfiles / bayfiles --- .github/workflows/test-anonfile.yml | 29 --------------------------- .github/workflows/test-bayfiles.yml | 29 --------------------------- README.md | 6 ++---- hoster/__init__.py | 4 ++-- hoster/base_hoster.py | 1 + hoster/hosters/__init__.py | 2 -- hoster/hosters/anonfiles.py | 31 ----------------------------- hoster/hosters/bayfiles.py | 29 --------------------------- hoster/hosters/file_io.py | 1 + hoster/hosters/gofile.py | 1 + hoster/hosters/keepsh.py | 1 + multi_hoster_uploader | 6 ++++-- tests/test_hosters.py | 12 +++-------- 13 files changed, 15 insertions(+), 137 deletions(-) delete mode 100644 .github/workflows/test-anonfile.yml delete mode 100644 .github/workflows/test-bayfiles.yml delete mode 100644 hoster/hosters/anonfiles.py delete mode 100644 hoster/hosters/bayfiles.py diff --git a/.github/workflows/test-anonfile.yml b/.github/workflows/test-anonfile.yml deleted file mode 100644 index c1421f9..0000000 --- a/.github/workflows/test-anonfile.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Anonfiles - -on: - push: - branches: [main] - pull_request: - branches: [main] - schedule: - - cron: '0 0 * * *' - -jobs: - test_anonfiles: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.x - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Run anonfiles test - run: python -m unittest tests.test_hosters.TestHosters.test_anonfiles_upload diff --git a/.github/workflows/test-bayfiles.yml b/.github/workflows/test-bayfiles.yml deleted file mode 100644 index b36e533..0000000 --- a/.github/workflows/test-bayfiles.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Bayfiles - -on: - push: - branches: [main] - pull_request: - branches: [main] - schedule: - - cron: '0 0 * * *' - -jobs: - test_bayfiles: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.x - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Run bayfiles test - run: python -m unittest tests.test_hosters.TestHosters.test_bayfiles_upload diff --git a/README.md b/README.md index a4ea823..44ca476 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,6 @@ Multi Hoster Uploader serves as both a command-line tool and a Python package fo | Hoster | Status | |---------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Anonfiles Favicon Anonfiles | [![Anonfiles](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-anonfile.yml/badge.svg)](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-anonfile.yml) | -| Bayfiles Favicon Bayfiles | [![Bayfiles](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-bayfiles.yml/badge.svg)](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-bayfiles.yml) | | FileIo Favicon FileIo | [![FileIO](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-file_io.yml/badge.svg)](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-file_io.yml) | | Gofile Favicon GoFile | [![GoFile](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-gofile.yml/badge.svg)](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-gofile.yml) | | KeepSh | [![KeepSh](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-keepsh.yml/badge.svg)](https://github.com/c-kr/multi_hoster_uploader/actions/workflows/test-keepsh.yml) | @@ -64,13 +62,13 @@ To use the `MultiHosterManager` class in your own script, follow these steps: ```python from hoster import MultiHosterManager -from hoster.hosters import AnonfilesHoster, BayfilesHoster, FileIoHoster, GofileHoster, KeepShHoster +from hoster.hosters import FileIoHoster, GofileHoster, KeepShHoster ``` Instantiate the MultiHosterManager class with the list of hoster classes and, optionally, a flag to randomize the hoster order: ```python -manager = MultiHosterManager([FileIoHoster, GofileHoster, BayfilesHoster, KeepShHoster, AnonfilesHoster], random_hoster=True) +manager = MultiHosterManager([FileIoHoster, GofileHoster, KeepShHoster], random_hoster=True) ``` Call the upload method of the MultiHosterManager instance, providing the file path as an argument: diff --git a/hoster/__init__.py b/hoster/__init__.py index 42e0074..7f63805 100644 --- a/hoster/__init__.py +++ b/hoster/__init__.py @@ -1,9 +1,9 @@ -from hoster.hosters import AnonfilesHoster, FileIoHoster, BayfilesHoster, GofileHoster from hoster.base_hoster import Hoster from random import shuffle from typing import List, Optional, Type, Union from pathlib import Path + class MultiHosterManager: def __init__(self, hosters: List[Type[Hoster]], random_hoster: bool = False): """ @@ -42,4 +42,4 @@ def upload(self, file_path: Union[str, Path]) -> Optional[str]: except Exception as e: print(f"An error occurred while uploading to {hoster.__class__.__name__}: {e}") continue - return None \ No newline at end of file + return None diff --git a/hoster/base_hoster.py b/hoster/base_hoster.py index 3303de4..513a8c0 100644 --- a/hoster/base_hoster.py +++ b/hoster/base_hoster.py @@ -3,6 +3,7 @@ from typing import Any, List, Tuple, Union from pathlib import Path + class Hoster: def __init__(self, upload_url: str, upload_url_keys: List[str], success_keys: List[str], success_values: Union[List[Union[str, bool]], None] = None) -> None: """ diff --git a/hoster/hosters/__init__.py b/hoster/hosters/__init__.py index 80c08fa..38da827 100644 --- a/hoster/hosters/__init__.py +++ b/hoster/hosters/__init__.py @@ -1,5 +1,3 @@ -from .anonfiles import AnonfilesHoster -from .bayfiles import BayfilesHoster from .file_io import FileIoHoster from .gofile import GofileHoster from .keepsh import KeepShHoster diff --git a/hoster/hosters/anonfiles.py b/hoster/hosters/anonfiles.py deleted file mode 100644 index 752536d..0000000 --- a/hoster/hosters/anonfiles.py +++ /dev/null @@ -1,31 +0,0 @@ -import json -import requests - -from hoster.base_hoster import Hoster - -class AnonfilesHoster(Hoster): - - def __init__(self): - super().__init__( - upload_url="https://api.anonfiles.com/upload", - upload_url_keys=['data', 'file', 'url', 'short'], - success_keys=['status'], - success_values=[True] - ) - - def upload(self, file_path): - with open(file_path, 'rb') as file: - response = requests.post(self.upload_url, files={'file': file}, timeout=10) - if response.status_code == 200: - return self.process_response(response) - else: - return False, None - - def process_response(self, response): - json_data = json.loads(response.content) - download_url = self._get_value_from_json(json_data, self.upload_url_keys) - success = self._get_value_from_json(json_data, self.success_keys) - if success and self.is_valid_url(download_url): - return success, download_url - else: - return False, None \ No newline at end of file diff --git a/hoster/hosters/bayfiles.py b/hoster/hosters/bayfiles.py deleted file mode 100644 index 4db14c3..0000000 --- a/hoster/hosters/bayfiles.py +++ /dev/null @@ -1,29 +0,0 @@ -import json -from hoster.base_hoster import Hoster - -class BayfilesHoster(Hoster): - - def __init__(self): - super().__init__( - upload_url="https://api.bayfiles.com/upload", - upload_url_keys=['data', 'file', 'url', 'full'], - success_keys=['status'], - success_values=[True] - ) - - def process_response(self, response): - json_data = json.loads(response.text) - success = self.success_values == [json_data.get(key) for key in self.success_keys] - download_url = None - if success: - current_data = json_data - for key in self.upload_url_keys: - current_data = current_data.get(key) - download_url = current_data - else: - return False, None - - if self.is_valid_url(download_url): - return success, download_url - else: - return False, None \ No newline at end of file diff --git a/hoster/hosters/file_io.py b/hoster/hosters/file_io.py index c79b155..5259d62 100644 --- a/hoster/hosters/file_io.py +++ b/hoster/hosters/file_io.py @@ -1,6 +1,7 @@ import json from hoster.base_hoster import Hoster + class FileIoHoster(Hoster): def __init__(self): diff --git a/hoster/hosters/gofile.py b/hoster/hosters/gofile.py index 9fa8b88..dae3920 100644 --- a/hoster/hosters/gofile.py +++ b/hoster/hosters/gofile.py @@ -1,6 +1,7 @@ from hoster.base_hoster import Hoster import requests + class GofileHoster(Hoster): def __init__(self): super().__init__( diff --git a/hoster/hosters/keepsh.py b/hoster/hosters/keepsh.py index 9d96f04..a962402 100644 --- a/hoster/hosters/keepsh.py +++ b/hoster/hosters/keepsh.py @@ -2,6 +2,7 @@ import requests from hoster.base_hoster import Hoster + class KeepShHoster(Hoster): def __init__(self, bucket_name='free'): diff --git a/multi_hoster_uploader b/multi_hoster_uploader index 229f3e3..b0d6af0 100755 --- a/multi_hoster_uploader +++ b/multi_hoster_uploader @@ -9,11 +9,12 @@ License: MIT import argparse from hoster import MultiHosterManager -from hoster.hosters import AnonfilesHoster,BayfilesHoster, FileIoHoster, GofileHoster, KeepShHoster +from hoster.hosters import FileIoHoster, GofileHoster, KeepShHoster from sys import exit # define the hoster classes to use in the order to try -HOSTERS = [FileIoHoster, GofileHoster, BayfilesHoster, KeepShHoster, AnonfilesHoster] +HOSTERS = [FileIoHoster, GofileHoster, KeepShHoster] + def main(): parser = argparse.ArgumentParser(description='Upload a file to various file hosting services.') @@ -31,5 +32,6 @@ def main(): print('Upload failed.') exit(2) + if __name__ == '__main__': main() diff --git a/tests/test_hosters.py b/tests/test_hosters.py index 8db202f..c6c3117 100644 --- a/tests/test_hosters.py +++ b/tests/test_hosters.py @@ -1,13 +1,12 @@ import unittest import os -from hoster.hosters import AnonfilesHoster, BayfilesHoster, FileIoHoster, GofileHoster, KeepShHoster +from hoster.hosters import FileIoHoster, GofileHoster, KeepShHoster + class TestHosters(unittest.TestCase): def setUp(self): self.file_path = 'test_file.txt' - self.anonfiles_hoster = AnonfilesHoster() - self.bayfiles_hoster = BayfilesHoster() self.file_io_hoster = FileIoHoster() self.gofile_hoster = GofileHoster() self.keepsh_hoster = KeepShHoster() @@ -26,12 +25,6 @@ def _assert_upload(self, hoster): self.assertIsNotNone(upload_url) self.assertTrue(upload_url.startswith("https")) - def test_anonfiles_upload(self): - self._assert_upload(self.anonfiles_hoster) - - def test_bayfiles_upload(self): - self._assert_upload(self.bayfiles_hoster) - def test_file_io_upload(self): self._assert_upload(self.file_io_hoster) @@ -41,5 +34,6 @@ def test_gofile_upload(self): def test_keepsh_upload(self): self._assert_upload(self.keepsh_hoster) + if __name__ == '__main__': unittest.main()