Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. def get_note_fields(note, get_empty=False):
  2.     """
  3.    Get a list of field data for download.
  4.  
  5.    Check all field names and return source and destination fields for
  6.    downloading audio.
  7.    """
  8.     field_names = [item[0] for item in note.items()]
  9.     field_data_list = []
  10.     for afk in audio_field_keys:
  11.         for fn in field_names:
  12.             if afk in fn.lower():
  13.                 if meaning_in_reading_field:
  14.                     try:
  15.                         # Here, too, first try reading, then try other
  16.                         # fields.
  17.                         field_data_list.append(
  18.                             field_data(
  19.                                 note, fn, readings=True, get_empty=get_empty))
  20.                     except (KeyError, ValueError):
  21.                         # No or empty readings field.
  22.                         pass
  23.                     try:
  24.                         field_data_list.append(
  25.                             field_data(
  26.                                 note, fn, readings=False, get_empty=get_empty))
  27.                     except (KeyError, ValueError):
  28.                         # No or empty 'normal' field
  29.                         pass
  30.                 else:
  31.                     # We have to call field_data twice to get the base
  32.                     # text and reading.
  33.                     try:
  34.                         fd_base = field_data(
  35.                             note, fn, readings=False, get_empty=get_empty)
  36.                     except (KeyError, ValueError):
  37.                         continue
  38.                     try:
  39.                         fd_read = field_data(
  40.                             note, fn, readings=True, get_empty=get_empty)
  41.                     except (KeyError, ValueError):
  42.                         # No reading field after all.
  43.                         pass
  44.                     else:
  45.                         # Now we have to put together the two
  46.                         # results. I guess i could have used a named
  47.                         # tuple above. Oh, well. Kludge branch.
  48.                         field_data_list.append(
  49.                             (fd_base[0], fd_base[1], fd_base[2], fd_base[3],
  50.                              fd_read[4], True))
  51.                     # Use what we have from the first try, so that we
  52.                     # try GoogleTTS (wiktionary) as well.
  53.                     field_data_list.append(fd_base)
  54.     return field_data_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement