Skip to content

Commit a5fe38a

Browse files
committed
Initial release
1 parent 427a5ba commit a5fe38a

File tree

7 files changed

+380
-0
lines changed

7 files changed

+380
-0
lines changed

.gitignore

+284
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,visualstudiocode,python,virtualenv,homebrew
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,visualstudiocode,python,virtualenv,homebrew
3+
4+
### Homebrew ###
5+
Brewfile.lock.json
6+
7+
### Linux ###
8+
*~
9+
10+
# temporary files which can be created if a process still has a handle open of a deleted file
11+
.fuse_hidden*
12+
13+
# KDE directory preferences
14+
.directory
15+
16+
# Linux trash folder which might appear on any partition or disk
17+
.Trash-*
18+
19+
# .nfs files are created when an open file is removed but is still being accessed
20+
.nfs*
21+
22+
### macOS ###
23+
# General
24+
.DS_Store
25+
.AppleDouble
26+
.LSOverride
27+
28+
# Icon must end with two \r
29+
Icon
30+
31+
32+
# Thumbnails
33+
._*
34+
35+
# Files that might appear in the root of a volume
36+
.DocumentRevisions-V100
37+
.fseventsd
38+
.Spotlight-V100
39+
.TemporaryItems
40+
.Trashes
41+
.VolumeIcon.icns
42+
.com.apple.timemachine.donotpresent
43+
44+
# Directories potentially created on remote AFP share
45+
.AppleDB
46+
.AppleDesktop
47+
Network Trash Folder
48+
Temporary Items
49+
.apdisk
50+
51+
### macOS Patch ###
52+
# iCloud generated files
53+
*.icloud
54+
55+
### Python ###
56+
# Byte-compiled / optimized / DLL files
57+
__pycache__/
58+
*.py[cod]
59+
*$py.class
60+
61+
# C extensions
62+
*.so
63+
64+
# Distribution / packaging
65+
.Python
66+
build/
67+
develop-eggs/
68+
dist/
69+
downloads/
70+
eggs/
71+
.eggs/
72+
lib/
73+
lib64/
74+
parts/
75+
sdist/
76+
var/
77+
wheels/
78+
share/python-wheels/
79+
*.egg-info/
80+
.installed.cfg
81+
*.egg
82+
MANIFEST
83+
84+
# PyInstaller
85+
# Usually these files are written by a python script from a template
86+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
87+
*.manifest
88+
*.spec
89+
90+
# Installer logs
91+
pip-log.txt
92+
pip-delete-this-directory.txt
93+
94+
# Unit test / coverage reports
95+
htmlcov/
96+
.tox/
97+
.nox/
98+
.coverage
99+
.coverage.*
100+
.cache
101+
nosetests.xml
102+
coverage.xml
103+
*.cover
104+
*.py,cover
105+
.hypothesis/
106+
.pytest_cache/
107+
cover/
108+
109+
# Translations
110+
*.mo
111+
*.pot
112+
113+
# Django stuff:
114+
*.log
115+
local_settings.py
116+
db.sqlite3
117+
db.sqlite3-journal
118+
119+
# Flask stuff:
120+
instance/
121+
.webassets-cache
122+
123+
# Scrapy stuff:
124+
.scrapy
125+
126+
# Sphinx documentation
127+
docs/_build/
128+
129+
# PyBuilder
130+
.pybuilder/
131+
target/
132+
133+
# Jupyter Notebook
134+
.ipynb_checkpoints
135+
136+
# IPython
137+
profile_default/
138+
ipython_config.py
139+
140+
# pyenv
141+
# For a library or package, you might want to ignore these files since the code is
142+
# intended to run in multiple environments; otherwise, check them in:
143+
# .python-version
144+
145+
# pipenv
146+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
147+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
148+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
149+
# install all needed dependencies.
150+
#Pipfile.lock
151+
152+
# poetry
153+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
154+
# This is especially recommended for binary packages to ensure reproducibility, and is more
155+
# commonly ignored for libraries.
156+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
157+
#poetry.lock
158+
159+
# pdm
160+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
161+
#pdm.lock
162+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
163+
# in version control.
164+
# https://pdm.fming.dev/#use-with-ide
165+
.pdm.toml
166+
167+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
168+
__pypackages__/
169+
170+
# Celery stuff
171+
celerybeat-schedule
172+
celerybeat.pid
173+
174+
# SageMath parsed files
175+
*.sage.py
176+
177+
# Environments
178+
.env
179+
.venv
180+
env/
181+
venv/
182+
ENV/
183+
env.bak/
184+
venv.bak/
185+
186+
# Spyder project settings
187+
.spyderproject
188+
.spyproject
189+
190+
# Rope project settings
191+
.ropeproject
192+
193+
# mkdocs documentation
194+
/site
195+
196+
# mypy
197+
.mypy_cache/
198+
.dmypy.json
199+
dmypy.json
200+
201+
# Pyre type checker
202+
.pyre/
203+
204+
# pytype static type analyzer
205+
.pytype/
206+
207+
# Cython debug symbols
208+
cython_debug/
209+
210+
# PyCharm
211+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
212+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
213+
# and can be added to the global gitignore or merged into this file. For a more nuclear
214+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
215+
#.idea/
216+
217+
### Python Patch ###
218+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
219+
poetry.toml
220+
221+
# ruff
222+
.ruff_cache/
223+
224+
# LSP config files
225+
pyrightconfig.json
226+
227+
### VirtualEnv ###
228+
# Virtualenv
229+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
230+
[Bb]in
231+
[Ii]nclude
232+
[Ll]ib
233+
[Ll]ib64
234+
[Ll]ocal
235+
[Ss]cripts
236+
pyvenv.cfg
237+
pip-selfcheck.json
238+
239+
### VisualStudioCode ###
240+
.vscode/*
241+
!.vscode/settings.json
242+
!.vscode/tasks.json
243+
!.vscode/launch.json
244+
!.vscode/extensions.json
245+
!.vscode/*.code-snippets
246+
247+
# Local History for Visual Studio Code
248+
.history/
249+
250+
# Built Visual Studio Code Extensions
251+
*.vsix
252+
253+
### VisualStudioCode Patch ###
254+
# Ignore all local history of files
255+
.history
256+
.ionide
257+
258+
### Windows ###
259+
# Windows thumbnail cache files
260+
Thumbs.db
261+
Thumbs.db:encryptable
262+
ehthumbs.db
263+
ehthumbs_vista.db
264+
265+
# Dump file
266+
*.stackdump
267+
268+
# Folder config file
269+
[Dd]esktop.ini
270+
271+
# Recycle Bin used on file shares
272+
$RECYCLE.BIN/
273+
274+
# Windows Installer files
275+
*.cab
276+
*.msi
277+
*.msix
278+
*.msm
279+
*.msp
280+
281+
# Windows shortcuts
282+
*.lnk
283+
284+
# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,visualstudiocode,python,virtualenv,homebrew

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM python:3.10-slim-bullseye
2+
ADD main.py .
3+
ADD requirements.txt .
4+
RUN pip install -r requirements.txt
5+
CMD ["python", "./main.py"]

main.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
import time
3+
import requests
4+
from bs4 import BeautifulSoup
5+
from datetime import datetime
6+
import logging
7+
8+
logging.basicConfig(encoding='utf-8', level=logging.INFO, format='%(asctime)s %(message)s')
9+
10+
11+
_CHAT_ID = os.getenv('CHAT_ID')
12+
_BETA_ID = os.getenv('BETA_ID')
13+
_BOT_TOKEN = os.getenv('BOT_TOKEN')
14+
_DEBUG = os.getenv('DEBUG')
15+
16+
def is_not_full(text):
17+
if text == "This beta is full.":
18+
return False
19+
else:
20+
return True
21+
22+
if __name__ == "__main__":
23+
24+
if not _CHAT_ID:
25+
logging.error("You need to set your Telegram chat id to let this program run!")
26+
exit(2)
27+
28+
if not _BETA_ID:
29+
logging.error("You need to set the id of the beta you want to check to let this program run!")
30+
exit(2)
31+
32+
if not _BOT_TOKEN:
33+
logging.error("You need to set your Telegram bot token to let this program run!")
34+
exit(2)
35+
36+
_URL = 'https://testflight.apple.com/join/' + _BETA_ID
37+
38+
logging.info("Starting checking free slot now!")
39+
40+
if not _DEBUG:
41+
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.")
42+
else:
43+
logging.getLogger().setLevel(logging.DEBUG)
44+
45+
while True:
46+
now = datetime.now()
47+
try:
48+
page = requests.get(_URL)
49+
50+
soup = BeautifulSoup(page.content, "html.parser")
51+
beta_status_div = soup.find("div", class_="beta-status")
52+
result = beta_status_div.find("span").text
53+
54+
if is_not_full(result):
55+
loggin.info("Join now!")
56+
logging.debug("Sending Telegram message.")
57+
58+
text = "Join now on . \n" + _URL
59+
token = _BOT_TOKEN
60+
chat_id = _CHAT_ID
61+
url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text
62+
results = requests.get(url_req)
63+
logging.debug("Message sent: " + results.json()['ok'])
64+
65+
break
66+
else:
67+
logging.debug("Still full!")
68+
except requests.exceptions.ConnectionError:
69+
logging.error("Failure! Check internet connection. Retrying...")
70+
except:
71+
logging.error("Cannot check due an exception. Retrying...")
72+
73+
time.sleep(5)
74+
75+
logging.warning("Closing because there was at least 1 free slot")
76+
exit(0)

renameme.env

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# You should rename this file .env and set your environment variables here
2+
CHAT_ID=00000000
3+
BOT_TOKEN=0000000000:jkghasghjakskgjhasssdsdsdsdsdsdsds
4+
# Telegram Beta
5+
BETA_ID=u6iogfd0
6+
DEBUG=True

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
beautifulsoup4

run-docker.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
IMAGE=$(docker build -q .)
2+
docker tag $IMAGE tfchecker:latest
3+
docker run --env-file=.env -it --rm $IMAGE
4+
docker image rm --force $IMAGE

run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export $(grep -v '^#' .env | xargs)
2+
python3 main.py
3+
unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)

0 commit comments

Comments
 (0)