Created
April 26, 2021 14:07
-
-
Save pauladams8/a8b88065b56507289351e944908514b5 to your computer and use it in GitHub Desktop.
Compare cloud storage providers
This file contains 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
import re | |
import json | |
import requests | |
from pprint import pp | |
from pick import pick | |
from bs4 import BeautifulSoup | |
r = requests.get('https://en.wikipedia.org/wiki/Comparison_of_online_backup_services') | |
soup = BeautifulSoup(markup=r.text, features='lxml') | |
table = soup.select_one('table') | |
rows = table.select('tr') | |
features = [cell.find(text=True).strip() for cell in rows[0].select('th')] | |
selected_features = dict(pick(options=features, multiselect=True, title='What features do you need? (press space to select, enter to continue)', indicator='>')) | |
def gen_providers(): | |
for i, row in enumerate(rows): | |
if i == 0: | |
continue | |
def gen_values(): | |
for cell in row.select('td'): | |
yield v.strip() if (v := cell.find(text=True)) else None | |
provider = dict(zip(features, gen_values())) | |
try: | |
for k in selected_features: | |
if provider.get(k) == 'No': | |
raise StopIteration | |
except StopIteration: | |
continue | |
yield provider | |
for provider in gen_providers(): | |
print(provider['Provider']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment