-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
39 lines (31 loc) · 1.57 KB
/
update.py
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
# This script's purpose is to update the /bin/compile file with the latest Firefox & Geckodriver versions.
import os
import datetime
import time
import requests
from dotenv import load_dotenv
load_dotenv()
print(" ----> Running Auto Updater Script")
scriptPath = os.path.join(os.getcwd(), 'bin', 'compile')
readmePath = os.path.join(os.getcwd(), 'README.md')
latestFFVer = requests.get(
"https://product-details.mozilla.org/1.0/firefox_versions.json").json()['LATEST_FIREFOX_VERSION']
latestgeckoVer = requests.get(
"https://api.github.com/repos/mozilla/geckodriver/releases").json()[0]['name']
supportedHeroku = list(filter(lambda x: x.startswith("heroku"), list(map(
lambda x: x['stack']['name'].lower(), requests.get(os.environ.get("REPOSITORY_URL")).json()['data']))))
with open(scriptPath) as f:
data = f.readlines()
data[2] = f"# Last updated: {datetime.datetime.strftime(datetime.datetime.now(), '%B %d, %Y %I:%M %p %z')}{time.tzname[time.daylight]}\n"
data[38] = f"VERSION_FIREFOX={latestFFVer}\n"
data[39] = f"VERSION_GECKODRIVER={latestgeckoVer}\n"
data[53] = ' "' + '" | "'.join(supportedHeroku) + '")\n'
data[81] = f' error "Must be on a supported Heroku version: {", ".join(supportedHeroku)}"\n'
with open(scriptPath, 'w') as f:
f.writelines(data)
with open(readmePath) as f:
readmeUpdate = f.readlines()
readmeUpdate[0] = f"**LAST UPDATED:** {datetime.datetime.strftime(datetime.datetime.now(), '%B %d, %Y %I:%M %p %z')}{time.tzname[time.daylight]}\n"
with open(readmePath, 'w') as f:
f.writelines(readmeUpdate)
print(" ----> Finished Auto Updater Script")