Skip to content

Commit

Permalink
remember me fix and initial github actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
madmachinations committed Jan 4, 2025
1 parent 19041ef commit 788cfa1
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Build Release

on:
push:
branches:
- main

jobs:

docker:
name: Build Server Container
runs-on: ubuntu-latest
steps:
- name: Set version
run: echo "IMAGE_VERSION=$(date +"%y%m.%j")" >> $GITHUB_ENV
- name: Show version number
run: echo "Building release for version - $IMAGE_VERSION"

- name: Check out code
uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
context: ./server/
push: true
tags: |
ha-alexa-shopping-list-sync:$IMAGE_VERSION
ha-alexa-shopping-list-sync:latest

release:
name: Release Client Version
runs-on: ubuntu-latest
needs: docker
steps:
- name: Set version
run: echo "IMAGE_VERSION=$(date +"%y%m.%j")" >> $GITHUB_ENV

- name: Check out code
uses: actions/checkout@v3

- name: Create a tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag $IMAGE_VERSION
git push origin $IMAGE_VERSION
- name: Create a Release
uses: actions/create-release@v1
with:
tag_name: $IMAGE_VERSION
release_name: $IMAGE_VERSION
body: "Automated release for version $IMAGE_VERSION"
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}


hass:
name: Publish update to HASS Add-on repository
runs-on: ubuntu-latest
needs: release
env:
REPO_NAME: madmachinations/home-assistant-alexa-shopping-list-hass
FILE_PATH: alexa_shopping_list/config.yaml
steps:
- name: Set version
run: echo "IMAGE_VERSION=$(date +"%y%m.%j")" >> $GITHUB_ENV

- name: Check out the external repository
uses: actions/checkout@v3
with:
repository: ${{ env.REPO_NAME }}
path: external-repo
token: ${{ secrets.GITHUB_TOKEN }}

- name: Update version in YAML file
run: |
cd external-repo
sed -i "s/^version:.*/version: '$IMAGE_VERSION'/" ${{ env.FILE_PATH }}
cd ../
- name: Commit and push changes
run: |
cd external-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ${{ env.FILE_PATH }}
git commit -m "Update version to $IMAGE_VERSION"
git push origin master
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ There is a HASS OS Add-on of the server.

Add this repository to your installation, and install the alexa shopping list add on:

`https://gitlab.com/home-assistant-components/hass-addons`
`https://github.com/madmachinations/home-assistant-alexa-shopping-list-hass`

### Build your own container image

Expand Down Expand Up @@ -106,6 +106,8 @@ You can do this with the client script in this repository.

So, if you have not done so already, download this repository first.

**THE CLIENT SCRIPT IS RUN ON THE COMPUTER YOU ARE USING RIGHT NOW, NOT ON YOUR HOME ASSISTANT BOX AND NOT WITHIN THE RUNNING CONTAINER. YOU NEED TO DOWNLOAD THE FILES FROM THIS REPOSITORY TO YOUR COMPUTER, AND THE CLIENT SCRIPT IS INSIDE THE CLIENT FOLDER**

Before we begin, you need to make sure your system has both `python3` and `pip3` installed.

If that is the case, `cd` into the `client` directory
Expand Down
10 changes: 9 additions & 1 deletion server/alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def _setup_driver(self):
self._load_cookies()

if len(self.driver.find_elements(By.ID, 'nav-backup-backup')) > 0:
# I don't know why this is, but random amazon displays some weird page instead of the usual home page.
# This solution only works for versions of amazon in english, so would cause problems for other languages.
# But this only happens rarely, so... whatever.
self.driver.find_element(By.CLASS_NAME, "nav-bb-right").find_element(By.LINK_TEXT, "Your Account").click()
time.sleep(5)

Expand Down Expand Up @@ -158,7 +161,10 @@ def _driver_is_on_login_password_page(self):

def _handle_login_password_page(self):
self.driver.find_element(By.ID, 'ap_password').send_keys(self.password)
self.driver.find_element(By.NAME, 'rememberMe').click()
try:
self.driver.find_element(By.NAME, 'rememberMe').click()
except:
pass
self._login_submit_button()


Expand Down Expand Up @@ -191,6 +197,7 @@ def login(self, email: str, password: str):

account_menu = self.driver.find_element(By.ID, 'nav-link-accountList')
account_menu.click()
time.sleep(5)

self.email = email
self.password = password
Expand Down Expand Up @@ -271,6 +278,7 @@ def get_alexa_list(self, refresh: bool = True):


def _get_alexa_list_item_element(self, item: str):
#TODO: This potentially needs the scrolling solution from above?
self._ensure_driver_is_on_alexa_list(False)
time.sleep(5)
list_container = self.driver.find_element(By.CLASS_NAME, 'virtual-list')
Expand Down
1 change: 1 addition & 0 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async def _cmd_is_authenticated():
recent = _get_config_value('auth_checked_time', 0)
time_diff = _time_now() - recent

#TODO: This is potentially causing issues during setup where it thinks it's logged in but isnt
if time_diff < 86400:
return True, None

Expand Down

0 comments on commit 788cfa1

Please sign in to comment.