Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaam committed Mar 15, 2023
1 parent 427a5ba commit a5fe38a
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 0 deletions.
284 changes: 284 additions & 0 deletions .gitignore
@@ -0,0 +1,284 @@
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,visualstudiocode,python,virtualenv,homebrew
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,visualstudiocode,python,virtualenv,homebrew

### Homebrew ###
Brewfile.lock.json

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

### VirtualEnv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,visualstudiocode,python,virtualenv,homebrew
5 changes: 5 additions & 0 deletions Dockerfile
@@ -0,0 +1,5 @@
FROM python:3.10-slim-bullseye
ADD main.py .
ADD requirements.txt .
RUN pip install -r requirements.txt
CMD ["python", "./main.py"]
76 changes: 76 additions & 0 deletions main.py
@@ -0,0 +1,76 @@
import os
import time
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import logging

logging.basicConfig(encoding='utf-8', level=logging.INFO, format='%(asctime)s %(message)s')


_CHAT_ID = os.getenv('CHAT_ID')
_BETA_ID = os.getenv('BETA_ID')
_BOT_TOKEN = os.getenv('BOT_TOKEN')
_DEBUG = os.getenv('DEBUG')

def is_not_full(text):
if text == "This beta is full.":
return False
else:
return True

if __name__ == "__main__":

if not _CHAT_ID:
logging.error("You need to set your Telegram chat id to let this program run!")
exit(2)

if not _BETA_ID:
logging.error("You need to set the id of the beta you want to check to let this program run!")
exit(2)

if not _BOT_TOKEN:
logging.error("You need to set your Telegram bot token to let this program run!")
exit(2)

_URL = 'https://testflight.apple.com/join/' + _BETA_ID

logging.info("Starting checking free slot now!")

if not _DEBUG:
logging.info("Debug is disabled. You will see only messages when there are free slots or errors. You can define DEBUG environment variable to enable it.")
else:
logging.getLogger().setLevel(logging.DEBUG)

while True:
now = datetime.now()
try:
page = requests.get(_URL)

soup = BeautifulSoup(page.content, "html.parser")
beta_status_div = soup.find("div", class_="beta-status")
result = beta_status_div.find("span").text

if is_not_full(result):
loggin.info("Join now!")
logging.debug("Sending Telegram message.")

text = "Join now on . \n" + _URL
token = _BOT_TOKEN
chat_id = _CHAT_ID
url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text
results = requests.get(url_req)
logging.debug("Message sent: " + results.json()['ok'])

break
else:
logging.debug("Still full!")
except requests.exceptions.ConnectionError:
logging.error("Failure! Check internet connection. Retrying...")
except:
logging.error("Cannot check due an exception. Retrying...")

time.sleep(5)

logging.warning("Closing because there was at least 1 free slot")
exit(0)
6 changes: 6 additions & 0 deletions renameme.env
@@ -0,0 +1,6 @@
# You should rename this file .env and set your environment variables here
CHAT_ID=00000000
BOT_TOKEN=0000000000:jkghasghjakskgjhasssdsdsdsdsdsdsds
# Telegram Beta
BETA_ID=u6iogfd0
DEBUG=True
2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
requests
beautifulsoup4
4 changes: 4 additions & 0 deletions run-docker.sh
@@ -0,0 +1,4 @@
IMAGE=$(docker build -q .)
docker tag $IMAGE tfchecker:latest
docker run --env-file=.env -it --rm $IMAGE
docker image rm --force $IMAGE
3 changes: 3 additions & 0 deletions run.sh
@@ -0,0 +1,3 @@
export $(grep -v '^#' .env | xargs)
python3 main.py
unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)

0 comments on commit a5fe38a

Please sign in to comment.