-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add auto check for updates to prebuilt UShER tree
- Loading branch information
Showing
2 changed files
with
57 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
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,55 @@ | ||
"""Check if UShER pre-built tree has been updated. | ||
This script is designed to be run as a cron job to indicate if the | ||
UShER pre-built tree has been updated, which means the repo should | ||
be re-run. | ||
Note it reads the Slack webhook from a file not tracked in this repo. | ||
After creating that webhook file and giving it a valid Slack webhook, | ||
add a line like the following via ``crontab -e``: | ||
0 5 * * * python3 <full_path>/check_for_prebuilt_usher_update.py | ||
""" | ||
|
||
|
||
import json | ||
import os | ||
import urllib.request | ||
|
||
|
||
currdir = os.path.dirname(__file__) | ||
|
||
|
||
with open(os.path.join(currdir, "results/usher_prebuilt/version_info.txt")) as f: | ||
existing_version = f.read() | ||
|
||
response = urllib.request.urlopen("https://hgdownload.gi.ucsc.edu/hubs/GCF/000/864/105/GCF_000864105.1/UShER_NC_007362.1/fluA.GCF_000864105.1.NC_007362.1.latest.version.txt") | ||
new_version = response.read().decode("utf-8") | ||
|
||
if existing_version == new_version: | ||
msg = "UShER H5N1 version unchanged" | ||
else: | ||
msg = f"UShER H5N1 version has **changed**" | ||
|
||
msg += "\n\nnew_version=" + new_version + "\nexisting_version=" + existing_version + "\n" | ||
|
||
print(msg) | ||
|
||
with open(os.path.join(currdir, "_Slack_webhook_url.txt")) as f: | ||
webhook_url = f.read() | ||
|
||
payload = {"text": msg} | ||
data = json.dumps(payload).encode("utf-8") | ||
req = urllib.request.Request( | ||
webhook_url, | ||
data=data, | ||
headers={'Content-Type': 'application/json'} | ||
) | ||
|
||
with urllib.request.urlopen(req) as response: | ||
if response.status == 200: | ||
print("Message sent successfully.") | ||
else: | ||
raise ValueError(f"Failed to send message. Status code: {response.status}") |