Checks the validity of fields extracted from a element. Args: fields: A dictionary of fields extracted from a element. Returns: True if fields correspond to a valid article or redirect entry.
(fields)
| 31 | |
| 32 | |
| 33 | def validate_fields(fields): |
| 34 | """Checks the validity of fields extracted from a <PAGE> element. |
| 35 | |
| 36 | Args: |
| 37 | fields: A dictionary of fields extracted from a <PAGE> element. |
| 38 | |
| 39 | Returns: |
| 40 | True if fields correspond to a valid article or redirect entry. |
| 41 | """ |
| 42 | # If the namespace is not 0, then we are looking at something like an image |
| 43 | # or a template, and do not want to further process it. |
| 44 | if fields.get("ns") != "0": |
| 45 | return False |
| 46 | # We also want to check that the page has a title and text (if there is no |
| 47 | # text then we are looking at some kind of upload). |
| 48 | if not ("title" in fields and "text" in fields): |
| 49 | return False |
| 50 | return True |
| 51 | |
| 52 | |
| 53 | def generate_pages(xml_file): |
no test coverage detected
searching dependent graphs…