def main(): """Print Wiktionary engine JSON to STDOUT.""" data = mkdata('Wiktionary', 'Collaborative dictionary', pcencode=True) soup = BS(html(), 'html.parser') # Use 'langlist-large' css class for wiktionaries with # 10K+ entries. # Class 'langlist' will get wikitionaries with 100+ entries. for div in soup.find_all('div', class_='langlist-large'): for link in div.select('ul li a'): # log('link=%r', link) lang = id_ = link['lang'] url = 'https:' + link['href'] name = link.get_text() latin = link.get('title') if latin: name = u'{} / {}'.format(name, latin) w = Wiki(id_, url, lang, name) # log('%r', w) url = SEARCH_URL.format(w=w) d = mkvariant(w.lang, w.name, u'Wiktionary ({w.name})'.format(w=w), url, SUGGEST_URL.format(w=w), ) data['variants'].append(d) print(json.dumps(data, sort_keys=True, indent=2))
def google_search(search_url, suggest_url, title, description, jsonpath=None): """Generate an engine definition for a Google search. Args: search_url (str): Search URL template suggest_url (str): Suggest URL template title (unicode): Engine title description (unicode): Engine description jsonpath (unicode, optional): JSONPath for results """ kwargs = {} if jsonpath: kwargs['jsonpath'] = jsonpath data = mkdata(title, description, **kwargs) for l in langs(): s = mkvariant( l.id.lower(), l.name, u'{} ({})'.format(title, l.name), search_url.format(hl=l.id), suggest_url=suggest_url.format(hl=l.id), # lang=l.id.lower(), ) data['variants'].append(s) print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print Wiktionary engine JSON to STDOUT.""" data = mkdata('Wiktionary', 'Collaborative dictionary', pcencode=True) soup = BS(html(), 'html.parser') # Use 'langlist-large' css class for wiktionaries with # 10K+ entries. # Class 'langlist' will get wikitionaries with 100+ entries. for div in soup.find_all('div', class_='langlist-large'): for link in div.select('ul li a'): # log('link=%r', link) lang = id_ = link['lang'] url = 'https:' + link['href'] name = link.get_text() latin = link.get('title') if latin: name = u'{} / {}'.format(name, latin) w = Wiki(id_, url, lang, name) # log('%r', w) url = SEARCH_URL.format(w=w) d = mkvariant( w.lang, w.name, u'Wiktionary ({w.name})'.format(w=w), url, SUGGEST_URL.format(w=w), ) data['variants'].append(d) print(json.dumps(data, sort_keys=True, indent=2))
def google_search(search_url, suggest_url, title, description, jsonpath=None): """Generate an engine definition for a Google search. Args: search_url (str): Search URL template suggest_url (str): Suggest URL template title (unicode): Engine title description (unicode): Engine description jsonpath (unicode, optional): JSONPath for results """ kwargs = {} if jsonpath: kwargs['jsonpath'] = jsonpath data = mkdata(title, description, **kwargs) for l in langs(): s = mkvariant(l.id.lower(), l.name, u'{} ({})'.format(title, l.name), search_url.format(hl=l.id), suggest_url=suggest_url.format(hl=l.id), # lang=l.id.lower(), ) data['variants'].append(s) print(json.dumps(data, sort_keys=True, indent=2))
def main(): data = mkdata(u'YouTube', u'Video search') soup = BS(html(), 'html.parser') for y in parse(soup): data['variants'].append(yt2search(y)) print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print Amazon engine JSON to STDOUT.""" data = mkdata('Amazon', 'Online shopping') for s in stores(): data['variants'].append(s) print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print Wikipedia engine JSON to STDOUT.""" data = mkdata(u'Bing', u'General search engine') lines = LANGS.strip().split('\n') i = 0 while i < len(lines): t = Bing(lines[i + 1], lines[i]) data['variants'].append(lang2search(t)) i += 2 print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print eBay engine JSON to STDOUT.""" data = mkdata(u'eBay', u'Online auction search') for v in variants(): s = mkvariant(v.uid.lower(), v.name, u'eBay {}'.format(v.name), SEARCH_URL.format(tld=v.tld), SUGGEST_URL.format(site=v.site), ) data['variants'].append(s) print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print Wikipedia engine JSON to STDOUT.""" data = mkdata(u'Wikipedia', u'Collaborative encyclopaedia', pcencode=True) soup = BS(html(), 'html.parser') for w in parse(soup): if w.size < MIN_ARTICLE_COUNT: # log('too small: %r', w.name) continue # log('wiki=%r', w) data['variants'].append(lang2search(w)) print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print DDG engine JSON to STDOUT.""" data = mkdata( u'Duck Duck Go', u'Alternative search engine', jsonpath='$[*].phrase', ) for v in variants(): s = mkvariant( v.id.lower(), v.name, u'Duck Duck Go {}'.format(v.name), SEARCH_URL.format(kl=v.id), SUGGEST_URL.format(kl=v.id), ) data['variants'].append(s) print(json.dumps(data, sort_keys=True, indent=2))
def main(): """Print Wikipedia engine JSON to STDOUT.""" data = mkdata(u'Wikia', u'Fandom sites', pcencode=True) wikis = {} i = 0 for url, cachepath in SOURCES: soup = BS(html(url, cachepath), 'html.parser') for w in parse(soup): # log('wiki=%r', w) i += 1 # log(u'[%03d] "%s" (%s)', i, w.name, w.subdomain) wikis[w.subdomain] = w wikis = wikis.values() wikis.sort(key=lambda t: t.name) data['variants'] = [wiki2search(w) for w in wikis] print(json.dumps(data, sort_keys=True, indent=2))