Initial commit
This commit is contained in:
50
main.py
Normal file
50
main.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import configparser
|
||||
|
||||
import requests
|
||||
|
||||
from package import pkg
|
||||
|
||||
# Local Variables
|
||||
|
||||
## Application State
|
||||
_state = "test"
|
||||
|
||||
if _state == "prod":
|
||||
datafile = "/etc/autopkg/data.ini"
|
||||
elif _state == "test":
|
||||
datafile = "data.ini"
|
||||
|
||||
## Apps to be packaged
|
||||
apps = {
|
||||
"bitcoinknots": "https://api.github.com/repos/bitcoinknots/bitcoin/releases/latest",
|
||||
"electrs": "https://api.github.com/repos/romanz/electrs/releases/latest"
|
||||
}
|
||||
|
||||
# Setup data file
|
||||
data = configparser.ConfigParser()
|
||||
|
||||
data.read(datafile)
|
||||
|
||||
## Setup file if not present
|
||||
if "Versions" not in data:
|
||||
data["Versions"] = {}
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Handle apps (get versions)
|
||||
for app, url in apps.items():
|
||||
response = requests.get(url)
|
||||
|
||||
# Parse through JSON data
|
||||
if response.status_code == 200:
|
||||
json = response.json()
|
||||
version = json["id"]
|
||||
|
||||
data["Versions"][app] = str(version)
|
||||
|
||||
# Package new versions if available
|
||||
if version != data["Versions"][app]:
|
||||
pkg(app, version)
|
||||
|
||||
# Write changes
|
||||
with open("data.ini", "w") as datafile:
|
||||
data.write(datafile)
|
||||
Reference in New Issue
Block a user