aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2022-06-19 12:17:19 +0200
committerTeddy Wing2022-06-25 13:47:39 +0200
commit1c1fd3c3ba017e816aafc0840e287e5b49f5ddeb (patch)
treeb3e7d51914d81c7cfe93382fc0f464baea424ec4
parentd5527df82229dba88a83675a5984ebc1bddde7ea (diff)
downloadcws-status-1c1fd3c3ba017e816aafc0840e287e5b49f5ddeb.tar.bz2
cws-status: Take regex command line argument to filter extensions
The script now accepts a command line argument that filters the list of extension names and prints the matches as output.
-rw-r--r--cws-status23
1 files changed, 21 insertions, 2 deletions
diff --git a/cws-status b/cws-status
index 3f6e2ba..2dc1aa9 100644
--- a/cws-status
+++ b/cws-status
@@ -1,10 +1,23 @@
#!/usr/bin/env python3
+import re
+import sys
from urllib import request
import browser_cookie3
from lxml import html
+
+EX_USAGE = 64
+
+
+if len(sys.argv) < 2:
+ print('error: missing regex argument', file=sys.stderr)
+ sys.exit(EX_USAGE)
+
+regex = sys.argv[1]
+
+
url = 'https://chrome.google.com/webstore/devconsole/<UUID>'
cookie_jar = browser_cookie3.chrome(
@@ -18,7 +31,13 @@ page_html = opener.open(url).read()
tree = html.fromstring(page_html)
item_names = tree.xpath('//table[//th[text()="Item"]]/tbody/tr/td[1]/a/div//text()')
-print(item_names)
+item_names_versions = []
+
+for i in range(0, len(item_names), 2):
+ item_names_versions.append(f'{item_names[i]} ({item_names[i + 1]})')
item_statuses = tree.xpath('//table[//th[text()="Item"]]/tbody/tr/td[7]/text()')
-print(item_statuses)
+
+for i, name in enumerate(item_names_versions):
+ if re.match(regex, name):
+ print(f'{name}\t{item_statuses[i]}')