Skip to content

Commit

Permalink
PayPal: skip logging in if already logged in (#104)
Browse files Browse the repository at this point in the history
* Don't try to publish personal repo

* * fix: [paypal] Check if logged in, otherwise crashes
  • Loading branch information
Zburatorul authored Oct 7, 2024
1 parent 8df1560 commit 7fa5bc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,3 @@ jobs:
path: |
dist/*.whl
dist/*.tar.gz
python-publish-package:
# Only publish package on push to tag or default branch.
if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master') }}
runs-on: ubuntu-latest
needs:
- tox
steps:
- uses: actions/[email protected]
with:
name: python-packages
path: dist
- name: Publish to PyPI (test server)
uses: pypa/gh-action-pypi-publish@54b39fb9371c0b3a6f9f14bb8a67394defc7a806 # 2020-09-25
with:
user: __token__
password: ${{ secrets.pypi_test_token }}
repository_url: https://test.pypi.org/legacy/
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
- name: Publish to PyPI (main server)
uses: pypa/gh-action-pypi-publish@54b39fb9371c0b3a6f9f14bb8a67394defc7a806 # 2020-09-25
with:
user: __token__
password: ${{ secrets.pypi_token }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
14 changes: 13 additions & 1 deletion finance_dl/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from requests.exceptions import HTTPError
import jsonschema
from atomicwrites import atomic_write
Expand Down Expand Up @@ -137,12 +137,24 @@ def __init__(self, credentials: dict, output_directory: str, **kwargs):
def check_after_wait(self):
check_url(self.driver.current_url)

def is_already_logged_in(self):
try:
self.wait_and_locate((By.XPATH, '//*[contains(text(), "PayPal balance")]'), timeout=1)
logger.info('Already logged in')
return True
except:
return False

def login(self):
if self.logged_in:
return

self.driver.get('https://www.paypal.com/us/signin')
time.sleep(0.2)
if self.is_already_logged_in():
self.logged_in = True
self.csrf_token = None
return
logger.info('Finding username field')
username, = self.wait_and_locate((By.XPATH, '//input[@type="email"]'),
only_displayed=True)
Expand Down

0 comments on commit 7fa5bc5

Please sign in to comment.