From 9bfab2b82d4f7ee537f26320c2f14b0c06ecf095 Mon Sep 17 00:00:00 2001 From: PlaceReporter99 <106759534+PlaceReporter99@users.noreply.github.com> Date: Sun, 28 Apr 2024 18:53:45 +0100 Subject: [PATCH] Fix workflows, use os.environ for sendmsg.py, add debug stuff and keep new room awake gosh that was a lot of commit text --- .github/workflows/chatupdate.yml | 9 +++++-- .github/workflows/manual_test.yaml | 29 ---------------------- .github/workflows/tests.yml | 39 ------------------------------ sendmsg.py | 11 +++++---- utilitybot.py | 15 +++++++++--- 5 files changed, 25 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/manual_test.yaml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/chatupdate.yml b/.github/workflows/chatupdate.yml index 67922e3..df307b6 100644 --- a/.github/workflows/chatupdate.yml +++ b/.github/workflows/chatupdate.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v4 - name: Install required packages run: | @@ -15,4 +15,9 @@ jobs: python3 -m pip install -r requirements.txt - name: Send Message - run: python3 sendmsg.py ${{ secrets.BOT_EMAIL }} ${{ secrets.BOT_PASSWORD }} ${{ github.event_name }} ${{ github.actor }} + run: python3 sendmsg.py + env: + email: ${{ secrets.BOT_EMAIL }} + password: ${{ secrets.BOT_PASSWORD }} + event: ${{ github.event_name }} + actor: ${{ github.actor }} diff --git a/.github/workflows/manual_test.yaml b/.github/workflows/manual_test.yaml deleted file mode 100644 index ca82bb3..0000000 --- a/.github/workflows/manual_test.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Open Utility Bot PR for manual testing - -on: - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - open_bot: - runs-on: ubuntu-latest - steps: - - - name: Checkout repo - uses: actions/checkout@v3.5.3 - - - name: Setup python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - - name: Install packages - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r requirements.txt - - - name: Run bot - run: python3 manual_test.py ${{ secrets.BOT_EMAIL }} ${{ secrets.BOT_PASSWORD }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index cf64829..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Run Tests - -on: - pull_request: - workflow_dispatch: - push: - branches: - - "main" - paths-ignore: - - "pages/**" - schedule: - - cron: "43 */6 * * *" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - runs-on: ubuntu-latest - if: ${{ !contains(github.event.head_commit.message, '[no-test]') }} - steps: - - name: Checkout repo content - uses: actions/checkout@v3.5.3 # checkout the repository content - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' # install the python version needed - - - name: Install required packages - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r requirements.txt - - - name: Run tests - run: | - cd tests - python3 main.py ${{ secrets.BOT_EMAIL }} ${{ secrets.BOT_PASSWORD }} diff --git a/sendmsg.py b/sendmsg.py index 3cd8e13..3441929 100644 --- a/sendmsg.py +++ b/sendmsg.py @@ -1,18 +1,19 @@ import re import sys +import os import sechat -EMAIL = sys.argv[1] -PASSWORD = sys.argv[2] -EVENT_NAME = sys.argv[3] -EVENT_USER = sys.argv[4] +EMAIL = os.environ["username"] +PASSWORD = os.environ["password"] +EVENT_NAME = os.environ["event"] +EVENT_USER = os.environ["actor"] cleaned = re.sub(r"\[.*\]", "", EVENT_USER) bot = sechat.Bot() bot.login(EMAIL, PASSWORD) -r = bot.joinRoom(147676) +r = bot.joinRoom(152883) def indent(text): diff --git a/utilitybot.py b/utilitybot.py index 315b5c5..20d63a1 100644 --- a/utilitybot.py +++ b/utilitybot.py @@ -16,9 +16,14 @@ from firebase_admin import credentials from firebase_admin import firestore +with open('database_auth.json') as f: + print(f.read()) cred = credentials.Certificate('database_auth.json') +print(cred) f_init = firebase_admin.initialize_app(cred) +print(f_init) db = firestore.client() +print(db) # import streamlit as st @@ -63,7 +68,8 @@ def remote(event): def dataread(coll, user, key): try: return db.collection(coll).document(user).to_dict()[key] - except: + except BaseException as e: + print(e) return None def datawrite(coll, user, key, value): @@ -74,6 +80,7 @@ def datatoggle(coll, user, key): def tobool(val, truthy=["true", "1", "on", "y", "yes", "t", "i"], falsy=["false", "0", "off", "n", "no", "f", "o"], strfunc = (lambda x: str(x).lower())): ch = strfunc(val) + print(ch) if ch in truthy: return True elif ch in falsy: @@ -364,9 +371,11 @@ def msg(event): bot = sechat.Bot() bot.login(os.environ["BOT_EMAIL"], os.environ["BOT_PASSWORD"]) def repeat(): - [r, baso] = [bot.joinRoom(1), bot.joinRoom(146039)] - for room in [r, baso]: + import datetime + [r, baso, ubot] = map(bot.joinRoom, [1, 146039, 152883]) + for room in [r, baso, ubot]: onn(room) + ubot.send(f"Wake up, it's {str(datetime.datetime.now())}") repeat() app.run(host='0.0.0.0', port=5000) try: