aboutsummaryrefslogtreecommitdiffstats
path: root/dlpcvp.py
diff options
context:
space:
mode:
Diffstat (limited to 'dlpcvp.py')
-rwxr-xr-xdlpcvp.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/dlpcvp.py b/dlpcvp.py
new file mode 100755
index 0000000..189ee2a
--- /dev/null
+++ b/dlpcvp.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python3
+
+import json
+import sqlite3
+import urllib.request
+
+# PyPI API documentation https://warehouse.readthedocs.io/api-reference/
+PyPI_base = "https://pypi.org/pypi/{}/json"
+
+def get_version_from_pypi(name, etag=None):
+ req = urllib.request.Request(url=PyPI_base.format(name))
+
+ if etag is not None:
+ req.add_header('ETag', etag)
+
+ with urllib.request.urlopen(req) as resp:
+ if resp.getcode() == 200:
+ data = json.load(resp)
+ info_dict = data['info']
+ return info_dict['name'], info_dict['version'], resp.info()['ETag']
+ else:
+ IOError(resp.info())
+
+print(get_version_from_pypi('m2crypto'))