pywikitools.resourcesbot.data_structures#
Module Contents#
Classes#
Read-only data structure with evaluation result of the PDF metadata |
|
Holds information on one file that is available on the website |
|
Holds information on one worksheet in one specific language |
|
Holds information on all available worksheets in one specific language |
|
Serializes a LanguageInfo / WorksheetInfo / FileInfo / PdfMetadataSummary / TranslationProgress object |
Functions#
|
Deserializes a JSON-formatted string back into |
- class pywikitools.resourcesbot.data_structures.PdfMetadataSummary(version: str, correct: bool, pdf1a: bool, only_docinfo: bool, warnings: str)#
Read-only data structure with evaluation result of the PDF metadata
- to_string(self, include_version: bool) str#
Write a human-readable string
- to_html(self) str#
Write a HTML string (specifically for the use case of the WriteReport plugin)
- class pywikitools.resourcesbot.data_structures.FileInfo(file_type: str, url: str, timestamp: Union[datetime.datetime, str], *, translation_unit: Optional[int] = None, metadata: Optional[PdfMetadataSummary] = None)#
Holds information on one file that is available on the website This shouldn’t be modified after creation
- get_file_name(self) str#
Return file name out of url
- class pywikitools.resourcesbot.data_structures.WorksheetInfo(page: str, language_code: str, title: str, progress: TranslationProgress, version: str, version_unit: Optional[int] = None)#
Holds information on one worksheet in one specific language Only for worksheets that are at least partially translated
- add_file_info(self, file_info: Optional[FileInfo] = None, file_type: Optional[str] = None, from_pywikibot: Optional[pywikibot.page.FileInfo] = None, unit: Optional[int] = None, metadata: Optional[PdfMetadataSummary] = None)#
Add information about another file associated with this worksheet. You can call the function in two different ways: - providing file_info - providing file_type and from_pywikibot (and potentially unit and/or metadata) This will log on errors but shouldn’t raise exceptions
- get_file_infos(self) Dict[str, FileInfo]#
Returns all available files associated with this worksheet
- has_file_type(self, file_type: str) bool#
Does the worksheet have a file for download (e.g. “pdf”)?
- get_file_type_info(self, file_type: str) Optional[FileInfo]#
Returns FileInfo of specified type (e.g. “pdf”), None if not existing
- get_file_type_name(self, file_type: str) str#
Returns name of the file of the specified type (e.g. “pdf”) @return only name (not full URL) @return empty string if we don’t have the specified file type
- show_in_list(self, english_info) bool#
Should this worksheet be listed in the language information page? A worksheet will be included in the list of available resources if it has a PDF and if it has the same major version as the English original .. rubric:: Examples
English original: version 2.2; translation: 2.0 -> yes English original: version 2.0; translation: 1.3b -> no
- Parameters
english_info (WorksheetInfo) – Information on the English original worksheet
- has_same_version(self, english_info, *, check_only_major_version: bool = False) bool#
Compare our version string with the version string of the English original: is it the same? Native numerals will be converted to standard numerals. One additional character in our version will be ignored (e.g. “1.2b” is the same as “1.2”) :param english_info: Information on the English original worksheet :type english_info: WorksheetInfo :param check_only_major_version: ignore minor version part -> 1.3 and 1.1 counts as the same version
- class pywikitools.resourcesbot.data_structures.LanguageInfo(language_code: str, english_name: str)#
Holds information on all available worksheets in one specific language
- worksheet_has_type(self, name: str, file_type: str) bool#
Convienence method combining LanguageInfo.has_worksheet() and WorksheetInfo.has_file_type()
- compare(self, old) pywikitools.resourcesbot.changes.ChangeLog#
Compare ourselves to another (older) LanguageInfo object: have there been changes / updates? In case of NEW_WORKSHEET, no NEW_PDF / NEW_ODT will be emitted (even if files got added) In case of DELETED_WORKSHEET, no DELETED_PDF / DELETED_ODT will be emitted (even if files existed before) @return data structure with all changes
- list_worksheets_with_missing_pdf(self) List[str]#
Returns a list of worksheets which are translated but are missing the PDF
- pywikitools.resourcesbot.data_structures.json_decode(data: Dict[str, Any])#
Deserializes a JSON-formatted string back into TranslationProgress / FileInfo / WorksheetInfo / LanguageInfo objects. @raises AssertionError if data is malformatted
- class pywikitools.resourcesbot.data_structures.DataStructureEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#
Bases:
json.JSONEncoderSerializes a LanguageInfo / WorksheetInfo / FileInfo / PdfMetadataSummary / TranslationProgress object into a JSON string
- default(self, obj)#
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)