Skip to content

Commit

Permalink
Merge pull request #19 from RileyXX/improve-chromedriver-version-chec…
Browse files Browse the repository at this point in the history
…k-and-add-auto-update

Improve chromedriver version check and automatically install correct chromedriver version
  • Loading branch information
RileyXX authored May 14, 2023
2 parents 4321f6d + 0ce3132 commit ec095ad
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 10 deletions.
90 changes: 82 additions & 8 deletions IMDbTraktSyncer/checkChromedriver.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,91 @@
import feedparser
import subprocess
import pkg_resources
import platform

def get_chrome_version():
system = platform.system()
if system == 'Windows':
from winreg import ConnectRegistry, HKEY_CURRENT_USER, OpenKey, QueryValueEx

try:
registry = ConnectRegistry(None, HKEY_CURRENT_USER)
key = OpenKey(registry, r'Software\Google\Chrome\BLBeacon')
version, _ = QueryValueEx(key, 'version')
return version.split('.')[0]
except:
return None

elif system == 'Darwin':
try:
plist_path = '/Applications/Google Chrome.app/Contents/Info.plist'
with open(plist_path, 'rb') as plist_file:
plist_content = plist_file.read().decode('utf-8')
version_start = plist_content.index('<key>CFBundleShortVersionString</key>') + 38
version_end = plist_content.index('</string>', version_start)
return plist_content[version_start:version_end].split('.')[0]
except:
return None

elif system == 'Linux':
try:
process = subprocess.run(['google-chrome', '--version'], capture_output=True, text=True)
version = process.stdout.strip().split(' ')[2].split('.')[0]
return version
except:
return None

return None

def install_chromedriver(version):
# Install the chromedriver-py package using pip
subprocess.run(['pip', 'install', f'chromedriver-py=={version}'])

# Check if chromedriver-py is already installed
try:
pkg_resources.get_distribution('chromedriver-py')
# print("chromedriver-py is already installed. Skipping installation.")
dist = pkg_resources.get_distribution('chromedriver-py')
installed_version = dist.version.split('.')[0] # Retrieve only the prefix
chrome_version = get_chrome_version()

if chrome_version and installed_version != chrome_version:
# Make a request to the RSS feed
feed = feedparser.parse('https://pypi.org/rss/project/chromedriver-py/releases.xml')

# Find the corresponding chromedriver-py version
matching_version = None
for entry in feed.entries:
title = entry.title
if title.startswith(chrome_version):
matching_version = title.split()[-1]
break

if matching_version:
# Install the corresponding chromedriver-py version
install_chromedriver(matching_version)
else:
print(f"No matching chromedriver-py version found for Chrome {chrome_version}")
else:
# print("chromedriver-py is already installed with the correct version.")
pass
except pkg_resources.DistributionNotFound:
# Make a request to the RSS feed
feed = feedparser.parse('https://pypi.org/rss/project/chromedriver-py/releases.xml')
chrome_version = get_chrome_version()

# Get the second latest release version
version = feed.entries[1].title.split()[-1]
if chrome_version:
# Make a request to the RSS feed
feed = feedparser.parse('https://pypi.org/rss/project/chromedriver-py/releases.xml')

# Install the chromedriver-py package using pip
subprocess.run(['pip', 'install', f'chromedriver-py=={version}'])
# Find the corresponding chromedriver-py version
matching_version = None
for entry in feed.entries:
title = entry.title
if title.startswith(chrome_version):
matching_version = title.split()[-1]
break

if matching_version:
# Install the corresponding chromedriver-py version
install_chromedriver(matching_version)
else:
print(f"No matching chromedriver-py version found for Chrome {chrome_version}")
else:
print("Failed to retrieve Chrome version.")
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read()

VERSION = '1.1.1'
VERSION = '1.1.2'
DESCRIPTION = 'This python script will sync user ratings for Movies and TV Shows both ways between Trakt and IMDb.'

# Setting up
Expand All @@ -35,4 +35,4 @@
'IMDbTraktSyncer = IMDbTraktSyncer.IMDbTraktSyncer:main'
]
}
)
)

0 comments on commit ec095ad

Please sign in to comment.