-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcheck_phpmyadmin_daily_snapshots.py
More file actions
executable file
·50 lines (40 loc) · 1.78 KB
/
check_phpmyadmin_daily_snapshots.py
File metadata and controls
executable file
·50 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# I suggest creating a venv for this. I did it with `python3 -m venv daily_snapshot_venv` then source that with `source daily_snapshot_venv/bin/activate`.
# Install 'beautifulsoup4' to the venv
# This program checks that the phpMyAdmin daily downloads are within a day or two of the current time.
# We allow an extra day of wiggle room because of the possibility of working in different time zones.
#
# Written by Isaac Bennetch <bennetch@gmail.com>
import urllib.request
try:
from bs4 import BeautifulSoup
except ModuleNotFoundError:
print("The BeautifulSoup module is not available. Please make sure you have the proper module or are running the correct venv.")
raise SystemExit
import datetime
#############
# Main code #
#############
download_url = 'https://www.phpmyadmin.net/downloads/'
page = urllib.request.urlopen(download_url)
soup = BeautifulSoup(page, 'html.parser')
full_text = soup.get_text()
split = full_text.split("generated")
today_date = datetime.date.today()
# Process each instance of the keyword on the page, because we can have multiple QA and master versions
for substring in split:
# Take only the date, not the entire page following it
generated_date = substring.split()[0]
# Strip off the trailing comma
if generated_date.endswith(','):
generated_date = generated_date[:-1]
if generated_date != 'phpMyAdmin':
converted_date = datetime.datetime.strptime(generated_date, '%Y-%m-%d').date()
difference = today_date - converted_date
# We give an extra day as a buffer to account for time zones
if difference > datetime.timedelta(days=1):
print("Problem found")
print("Current date: " + today_date.strftime('%Y-%m-%d'))
print("Snapshot date: " + generated_date)
else:
print("Everything is groovy")