def create_dictionary_from_cursor(lang, cursor, max_entries=10000): l = list(cursor) q = [] d = {} include_pron = lang in ['he', 'zh'] include_strokes = lang in ['zh'] # Create a list of entries with the appropriate fields for phrase in l: if 'txs' in phrase and phrase['txs'] != {}: new_txs = scraper.get_viewable_txs(phrase) to_append = { 'lang': phrase['lang'], 'base': phrase['base'], 'txs' : new_txs, '_id': str(phrase['_id']), 'rank': phrase['rank'], } if include_pron: to_append['pron'] = phrase['pron'] if include_strokes and 'strokes' in phrase.keys(): to_append['strokes'] = phrase['strokes'] if new_txs != {}: q.append(to_append) # Convert the list into a dictionary based on ID, limiting by number of entries for h in q[0:max_entries]: d[h['_id']] = h return d
def get_row_html(phrase): new_txs = scraper.get_viewable_txs(phrase) d_chunks = [] for t in new_txs.keys(): t_chunks = ["%d. %s" % (i+1, new_txs[t][i]) for i in range(0, min(2, len(new_txs[t])))] d_chunks.append("%s => %s" % (t, " ".join(t_chunks))) def_str = ' | '.join(d_chunks) base = phrase['base'] pron = phrase.get('pron') return """ <tr> <td>%s</td> <td>%s</td> <td>%s</td> </tr> """ % (base, pron, def_str)