Created
May 3, 2022 01:21
-
-
Save cassc/292b0d25cb0de050b26ad854bbf9e1d0 to your computer and use it in GitHub Desktop.
Get deps.edn from clojars by libarary name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import argparse | |
import requests | |
from collections import OrderedDict | |
CLOJARS_URL = 'https://clojars.org/{}' | |
ap = argparse.ArgumentParser() | |
ap.add_argument('-l', '--library', help='Libary short name', type=str) | |
args = ap.parse_args() | |
def parse(lib): | |
url = CLOJARS_URL.format(lib.strip()) | |
content = requests.get(url).content | |
soup = BeautifulSoup(content, 'lxml') | |
deps_edn = soup.select_one('#deps-coordinates').text | |
homepage = soup.select_one('#jar-sidebar > li.homepage > a').attrs.get('href') | |
description = soup.select_one('#jar-title > p').text | |
od = OrderedDict() | |
od['description'] = description | |
od['homepage'] = homepage | |
od['deps_edn'] = deps_edn | |
return od | |
if __name__ == '__main__': | |
lib = args.library | |
for _, v in parse(lib).items(): | |
print('=' * 42) | |
print(v) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment