From ee43ce2bc7b660f123c19e834cf9bf26846446e1 Mon Sep 17 00:00:00 2001 From: Aakash Gajjar Date: Wed, 10 Jul 2024 21:56:51 +0530 Subject: [PATCH 1/2] feat(app): upstream changes to snapchat story url --- .github/ISSUE_TEMPLATE.md | 30 ++++++++-------- .pre-commit-config.yaml | 12 +++---- USAGE.rst | 0 docs/Makefile | 40 ++++++++++----------- docs/authors.rst | 2 +- docs/contributing.rst | 2 +- docs/history.rst | 2 +- docs/make.bat | 72 +++++++++++++++++++------------------- docs/modules.rst | 14 ++++---- docs/readme.rst | 2 +- docs/snapchat_dl.rst | 60 +++++++++++++++---------------- docs/usage.rst | 14 ++++---- requirements_dev.txt | 22 ++++++------ setup.py | 12 +++---- snapchat_dl/snapchat_dl.py | 14 ++++++-- tests/__init__.py | 2 +- tests/test_snapchat_dl.py | 7 ++-- tests/test_utils.py | 3 +- 18 files changed, 158 insertions(+), 152 deletions(-) create mode 100644 USAGE.rst diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 1f2341b..05ff603 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,15 +1,15 @@ -* Snapchat Downloader version: -* Python version: -* Operating System: - -### Description - -Describe what you were trying to get done. -Tell us what happened, what went wrong, and what you expected to happen. - -### What I Did - -``` -Paste the command(s) you ran and the output. -If there was a crash, please include the traceback here. -``` +* Snapchat Downloader version: +* Python version: +* Operating System: + +### Description + +Describe what you were trying to get done. +Tell us what happened, what went wrong, and what you expected to happen. + +### What I Did + +``` +Paste the command(s) you ran and the output. +If there was a crash, please include the traceback here. +``` diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1b44de..fbb4b3c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-yaml @@ -10,16 +10,12 @@ repos: - id: end-of-file-fixer - id: requirements-txt-fixer - id: trailing-whitespace - - repo: https://github.com/asottile/reorder_python_imports - rev: v2.3.0 - hooks: - - id: reorder-python-imports - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 24.4.2 hooks: - id: black - repo: https://github.com/asottile/blacken-docs - rev: v1.7.0 + rev: 1.18.0 hooks: - id: blacken-docs - additional_dependencies: [black==19.10b0] + additional_dependencies: [black==24.4.2] diff --git a/USAGE.rst b/USAGE.rst new file mode 100644 index 0000000..e69de29 diff --git a/docs/Makefile b/docs/Makefile index 6ff7836..0ff0a44 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,20 +1,20 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = python -msphinx -SPHINXPROJ = snapchat_dl -SOURCEDIR = . -BUILDDIR = _build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = python -msphinx +SPHINXPROJ = snapchat_dl +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/authors.rst b/docs/authors.rst index e122f91..426bac5 100644 --- a/docs/authors.rst +++ b/docs/authors.rst @@ -1 +1 @@ -.. include:: ../AUTHORS.rst +.. include:: ../AUTHORS.rst diff --git a/docs/contributing.rst b/docs/contributing.rst index e582053..819f45e 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -1 +1 @@ -.. include:: ../CONTRIBUTING.rst +.. include:: ../CONTRIBUTING.rst diff --git a/docs/history.rst b/docs/history.rst index 2506499..e4e52cc 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1 +1 @@ -.. include:: ../HISTORY.rst +.. include:: ../HISTORY.rst diff --git a/docs/make.bat b/docs/make.bat index 5ae86e0..e2b3e89 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,36 +1,36 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=python -msphinx -) -set SOURCEDIR=. -set BUILDDIR=_build -set SPHINXPROJ=snapchat_dl - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The Sphinx module was not found. Make sure you have Sphinx installed, - echo.then set the SPHINXBUILD environment variable to point to the full - echo.path of the 'sphinx-build' executable. Alternatively you may add the - echo.Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=python -msphinx +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=snapchat_dl + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The Sphinx module was not found. Make sure you have Sphinx installed, + echo.then set the SPHINXBUILD environment variable to point to the full + echo.path of the 'sphinx-build' executable. Alternatively you may add the + echo.Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/modules.rst b/docs/modules.rst index 19b8159..cba3f3b 100644 --- a/docs/modules.rst +++ b/docs/modules.rst @@ -1,7 +1,7 @@ -snapchat_dl -=========== - -.. toctree:: - :maxdepth: 4 - - snapchat_dl +snapchat_dl +=========== + +.. toctree:: + :maxdepth: 4 + + snapchat_dl diff --git a/docs/readme.rst b/docs/readme.rst index 72a3355..de17838 100644 --- a/docs/readme.rst +++ b/docs/readme.rst @@ -1 +1 @@ -.. include:: ../README.rst +.. include:: ../README.rst diff --git a/docs/snapchat_dl.rst b/docs/snapchat_dl.rst index 8158425..f099260 100644 --- a/docs/snapchat_dl.rst +++ b/docs/snapchat_dl.rst @@ -1,30 +1,30 @@ -snapchat\_dl package -==================== - -Submodules ----------- - -snapchat\_dl.cli module ------------------------ - -.. automodule:: snapchat_dl.cli - :members: - :undoc-members: - :show-inheritance: - -snapchat\_dl.snapchat\_dl module --------------------------------- - -.. automodule:: snapchat_dl.snapchat_dl - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - -.. automodule:: snapchat_dl - :members: - :undoc-members: - :show-inheritance: +snapchat\_dl package +==================== + +Submodules +---------- + +snapchat\_dl.cli module +----------------------- + +.. automodule:: snapchat_dl.cli + :members: + :undoc-members: + :show-inheritance: + +snapchat\_dl.snapchat\_dl module +-------------------------------- + +.. automodule:: snapchat_dl.snapchat_dl + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: snapchat_dl + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/usage.rst b/docs/usage.rst index a78597c..190a81c 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1,7 +1,7 @@ -===== -Usage -===== - -To use Snapchat Downloader in a project:: - - import snapchat_dl +===== +Usage +===== + +To use Snapchat Downloader in a project:: + + import snapchat_dl diff --git a/requirements_dev.txt b/requirements_dev.txt index 3bc04a1..500cc02 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,11 +1,11 @@ -bandit==1.6.2 -black==19.10b0 -blacken-docs==1.7.0 -bump2version==0.5.11 -coverage==4.5.4 -pre-commit==2.5.1 -pytest==5.4.3 -reorder_python_imports==2.3.0 -Sphinx==1.8.5 -watchdog==0.9.0 -wheel==0.38.1 +bandit==1.7.9 +black==24.1a1 +blacken-docs==1.18.0 +bump2version==1.0.1 +coverage==7.5.4 +pre-commit==3.7.1 +pytest==8.2.2 +reorder_python_imports==3.13.0 +Sphinx==7.3.7 +watchdog==4.0.1 +wheel==0.43.0 diff --git a/setup.py b/setup.py index fbec7d5..56618e2 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,11 @@ url="https://github.com/skyme5/snapchat-dl", author="Aakash Gajjar", author_email="skyqutip@gmail.com", - entry_points={"console_scripts": ["snapchat-dl=snapchat_dl.app:main",],}, + entry_points={ + "console_scripts": [ + "snapchat-dl=snapchat_dl.app:main", + ], + }, include_package_data=True, install_requires=requirements, test_suite="tests", @@ -45,11 +49,5 @@ "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", ], ) diff --git a/snapchat_dl/snapchat_dl.py b/snapchat_dl/snapchat_dl.py index 3b0a527..804e0ad 100644 --- a/snapchat_dl/snapchat_dl.py +++ b/snapchat_dl/snapchat_dl.py @@ -1,4 +1,5 @@ """The Main Snapchat Downloader Class.""" + import concurrent.futures import json import os @@ -34,7 +35,7 @@ def __init__( self.sleep_interval = sleep_interval self.quiet = quiet self.dump_json = dump_json - self.endpoint_web = "https://story.snapchat.com/@{}" + self.endpoint_web = "https://www.snapchat.com/add/{}/" self.regexp_web_json = ( r'([^<]+)<\/script>' ) @@ -75,9 +76,16 @@ def util_web_story(content: dict): return content["props"]["pageProps"]["story"]["snapList"] return list() + def util_web_extract(content: dict): + if "curatedHighlights" in content["props"]["pageProps"]: + return content["props"]["pageProps"]["curatedHighlights"] + return list() + user_info = util_web_user_info(response_json) stories = util_web_story(response_json) - return stories, user_info + curatedHighlights = util_web_extract(response_json) + spotHighlights = util_web_extract(response_json) + return stories, user_info, curatedHighlights, spotHighlights except (IndexError, KeyError, ValueError): raise APIResponseError @@ -90,7 +98,7 @@ def download(self, username): Returns: [bool]: story downloader """ - stories, snap_user = self._web_fetch_story(username) + stories, snap_user, *_ = self._web_fetch_story(username) if len(stories) == 0: if self.quiet is False: diff --git a/tests/__init__.py b/tests/__init__.py index 469a104..299bed9 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1 @@ -"""Unit test package for snapchat_dl.""" +"""Unit test package for snapchat_dl.""" diff --git a/tests/test_snapchat_dl.py b/tests/test_snapchat_dl.py index 64adb8b..31a2ce3 100644 --- a/tests/test_snapchat_dl.py +++ b/tests/test_snapchat_dl.py @@ -22,7 +22,10 @@ class TestSnapchat_dl(unittest.TestCase): def setUp(self): """Set up test fixtures.""" self.snapchat_dl = SnapchatDL( - limit_story=10, quiet=True, directory_prefix=".test-data", dump_json=True, + limit_story=10, + quiet=True, + directory_prefix=".test-data", + dump_json=True, ) self.test_url = "https://filesamples.com/samples/video/mp4/sample_640x360.mp4" self.test_url404 = "https://google.com/error.html" @@ -43,7 +46,7 @@ def test_class_init(self): def test_invalid_username(self): """Test snapchat_dl Stories are not available.""" - with self.assertRaises(UserNotFoundError): + with self.assertRaises(NoStoriesFound): self.snapchat_dl.download("username") @mock.patch("snapchat_dl.snapchat_dl.SnapchatDL._api_response") diff --git a/tests/test_utils.py b/tests/test_utils.py index ffe5097..89055d5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -20,7 +20,8 @@ def test_valid_username(self): def test_strf_time(self): """Test strf_time.""" self.assertEqual( - strf_time(978307200, "%Y-%m-%dT%H-%M-%S"), "2001-01-01T00-00-00", + strf_time(978307200, "%Y-%m-%dT%H-%M-%S"), + "2001-01-01T00-00-00", ) def test_search_usernames(self): From c07871a574f965f2396fb49990876182ead68c18 Mon Sep 17 00:00:00 2001 From: Aakash Gajjar Date: Wed, 10 Jul 2024 22:19:07 +0530 Subject: [PATCH 2/2] feat(github): update github actions versions --- .../workflows/continuous-integration-pip.yml | 57 ++++++++-------- .../continuous-integration-publish.yml | 67 +++++++++---------- 2 files changed, 61 insertions(+), 63 deletions(-) diff --git a/.github/workflows/continuous-integration-pip.yml b/.github/workflows/continuous-integration-pip.yml index 1326fac..c9f274a 100644 --- a/.github/workflows/continuous-integration-pip.yml +++ b/.github/workflows/continuous-integration-pip.yml @@ -3,33 +3,32 @@ name: build on: [push] jobs: - build: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.11] - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8] - - steps: - - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pytest - pip install pytest-cov - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Test with pytest - run: | - pytest --cov=./ --cov-report=xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + steps: + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test with pytest + run: | + pytest --cov=./ --cov-report=xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 diff --git a/.github/workflows/continuous-integration-publish.yml b/.github/workflows/continuous-integration-publish.yml index c880459..a24041d 100644 --- a/.github/workflows/continuous-integration-publish.yml +++ b/.github/workflows/continuous-integration-publish.yml @@ -1,40 +1,39 @@ name: publish on: - push: - tags: - - 'v*.*.*' + push: + tags: + - "v*.*.*" jobs: - build: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8] - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8] - - steps: - - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools - pip install wheel - pip install twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + steps: + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools + pip install wheel + pip install twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/*