This commit is contained in:
deathbybandaid 2019-07-16 12:40:44 -04:00
parent 89a2b316e0
commit 3643719954

View File

@ -7,6 +7,7 @@ This is the SpiceBot Update system.
import sopel import sopel
import requests import requests
import json
import pkg_resources import pkg_resources
from .Config import config as botconfig from .Config import config as botconfig
@ -25,7 +26,7 @@ class BotVersion():
self.spicebot = { self.spicebot = {
"version_local": None, "version_local": None,
"version_local_num": None, "version_local_num": None,
"version_url": 'https://api.github.com/users/SpiceBot/repos', "version_url": "https://api.github.com/repos/SpiceBot/SpiceBot/commits/master",
"version_online": None, "version_online": None,
"version_online_num": None, "version_online_num": None,
} }
@ -51,15 +52,16 @@ class BotVersion():
self.sopel["version_online_num"] = self.count_repo_commits() self.sopel["version_online_num"] = self.count_repo_commits()
# get actual version number, and commit count, and assemble a version # get actual version number, and commit count, and assemble a version
def count_repo_commits(self, _acc=0): def count_repo_commits(self):
info = requests.get(self.spicebot["version_url"], verify=botconfig.core.verify_ssl).json() commitcount = 0
return len(info) try:
page = requests.get(self.spicebot["version_url"])
def find_next(self, link): result = page.content
for l in link.split(','): jsoncommits = json.loads(result.decode('utf-8'))
a, b = l.split(';') commitcount = len(jsoncommits)
if b.strip() == 'rel="next"': except Exception as e:
return a.strip()[1:-1] commitcount = str(e)
return commitcount
version = BotVersion() version = BotVersion()