View Single Post
Old 12-16-2015, 03:49 PM   #19
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,807
Karma: 6000000
Join Date: Nov 2009
Device: many
I added a Current Version: "0.3.4" line to my ePub3-itizer release page.

Then you could simplify things using regular expressions to be just:

Code:
from __future__ import unicode_literals, division, absolute_import, print_function

import sys
import os
import re

try:
    import urllib.request as url_request
except ImportError:
    import urllib2 as url_request


_latest_pattern = re.compile(r'Current Version:\s*"([^&]*)&')
_version_pattern = re.compile(r'<version>([^<]*)</version>')

def check_for_updates(site_url, plugin_path):
    latest_version = None
    installed_version = None

    try:
        # get the latest version from the plugin release website page
        req = url_request.Request(site_url)
        response = url_request.urlopen(req)
        the_page = response.read()
        the_page = the_page.decode('utf-8')
        m = _latest_pattern.search(the_page)
        if m:
            latest_version = (m.group(1).strip())

        # get installed version of plugin
        ppath = os.path.join(plugin_path, "plugin.xml")
        with open(ppath,'rb') as f:
            data = f.read()
            data = data.decode('utf-8')
            m = _version_pattern.search(data)
            if m:
                installed_version = m.group(1).strip()
    except:
        pass

    return latest_version, installed_version


SITE_URL = "https://www.mobileread.com/forums/showpost.php?p=2973066&postcount=1"
PLUGIN_PATH = "/Users/kbhend/Desktop"
latest_version, installed_version = check_for_updates(SITE_URL, PLUGIN_PATH)
print(latest_version, installed_version)
KevinH is online now   Reply With Quote