-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# TestFlight watcher | ||
|
||
This script checks for free TestFlight slots for a given list of apps. It calls a callback function when new slots become available and (optionally) when they run out. | ||
|
||
This repo includes, as an example, a Telegram bot which uses *TestFlight watcher* and sends notification messages. | ||
|
||
## Example usage | ||
|
||
The `telegram_bot.py` script takes a comma-separated list of app IDs as an argument. | ||
|
||
`./telegram_bot.py ID1,ID2,ID3` | ||
|
||
where `ID1`, `ID2`, `ID3` are the 8-character | ||
app IDs you can find at the end of the TestFlight URL. If your URL is `https://testflight.apple.com/join/ABCDEFGH`, your `ID` is `ABCDEFGH`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import testflight_watcher | ||
import requests | ||
import sys | ||
|
||
|
||
CHAT_ID = "" | ||
BOT_TOKEN = "" | ||
BOT_URL = "https://api.telegram.org/bot{}/sendMessage".format(BOT_TOKEN) | ||
MSG_NO_FULL = "TestFlight slots for <b>{}</b> beta are now available! \ | ||
<a href='{}'>Download now</a>" | ||
MSG_FULL = "<b>{}</b> beta program on TestFlight is now full" | ||
|
||
|
||
def send_notification(tf_id, free_slots, title): | ||
dl_url = testflight_watcher.TESTFLIGHT_URL.format(tf_id) | ||
if free_slots: | ||
message = MSG_NO_FULL.format(title, dl_url) | ||
else: | ||
message = MSG_FULL.format(title) | ||
requests.get(BOT_URL, params={"chat_id": CHAT_ID, | ||
"text": message, | ||
"parse_mode": "html", | ||
"disable_web_page_preview": "true"}) | ||
|
||
testflight_watcher.watch(sys.argv[-1].split(","), send_notification) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import requests | ||
from lxml import html | ||
import re | ||
from time import sleep | ||
|
||
|
||
XPATH_STATUS = '//*[@class="beta-status"]/span/text()' | ||
XPATH_TITLE = '/html/head/title/text()' | ||
TITLE_REGEX = r'Join the (.+) beta - TestFlight - Apple' | ||
TESTFLIGHT_URL = 'https://testflight.apple.com/join/{}' | ||
FULL_TEXT = 'This beta is full.' | ||
|
||
|
||
def watch(watch_ids, callback, notify_full=True, sleep_time=900): | ||
data = {} | ||
while True: | ||
for tf_id in watch_ids: | ||
req = requests.get( | ||
TESTFLIGHT_URL.format(tf_id), | ||
headers={"Accept-Language": "en-us"}) | ||
page = html.fromstring(req.text) | ||
free_slots = (page.xpath(XPATH_STATUS)[0] != FULL_TEXT) | ||
if tf_id not in data: | ||
data[tf_id] = free_slots | ||
else: | ||
if data[tf_id] != free_slots: | ||
if free_slots or notify_full: | ||
title = re.findall( | ||
TITLE_REGEX, | ||
page.xpath(XPATH_TITLE)[0])[0] | ||
callback(tf_id, free_slots, title) | ||
data[tf_id] = free_slots | ||
sleep(sleep_time) |