shared submodule¶
Functions, objects and properties shared across many classes in this project.
-
abclinuxuapi.shared.
ABCLINUXU_URL
= 'https://www.abclinuxu.cz'¶ Base URL of the abclinuxu.
-
abclinuxuapi.shared.
SESSION
= <requests.sessions.Session object>¶ Session which is used in non-private requests.
-
abclinuxuapi.shared.
download
(url, params=None, method='GET', session=None, as_text=True, data=None)¶ Download data from url using method. Send params if defined.
Parameters: - url (str) – Absolute URL from which the data will be downloaded.
- params (dict, default None) – Send parameters (GET/POST).
- data (dict, default None) – Data which will be sent as body of the request.
- method (str, default "GET") – Use this method to send the request.
- session (obj, default None) – If
None
, sharedSESSION
object is used. - as_text (bool, default True) – Return content as
UTF-8
encoded string. If falsebytes
are returned.
Returns: Content depending on the as_text attribute.
Return type: str/bytes
-
abclinuxuapi.shared.
first
(inp_data)¶ Return first element from inp_data, or raise StopIteration.
Note
This function was created because it works for generators, lists, iterators, tuples and so on same way, which indexing doesn’t.
Also it have smaller cost than list(generator)[0], because it doesn’t convert whole inp_data to list.
Parameters: inp_data (iterable) – Any iterable object. Raises: StopIteration
– When the inp_data is blank.
-
abclinuxuapi.shared.
date_to_timestamp
(date)¶ Convert abclinuxu relative or absolute date string in czech words to timestamp.
Parameters: date (str) – One of many abclinuxu representations of date string. Returns: Timestamp. Return type: int
-
abclinuxuapi.shared.
date_izolator
(lines)¶ Return all lines, that looks like it may be date in one of many abclinuxu formats.
Parameters: lines (list) – List of strings with lines which ma by dates. Returns: List of lines, which looks like they may contain dates. Return type: list
-
abclinuxuapi.shared.
alt_izolator
(lines)¶ Return all lines, that looks like it may be date “~~%d.%m. ~~” format.
Parameters: lines (list) – List of strings with lines which ma by dates. Returns: List of lines, which looks like they may contain dates. Return type: list
-
abclinuxuapi.shared.
parse_timestamp
(meta)¶ Parse numeric timestamp from the date representation.
Parameters: meta (str) – Meta html from the blogpost body. Returns: Timestamp. Return type: int
-
abclinuxuapi.shared.
ts_to_concept_date
(timestamp)¶ Convert numeric timestamp into format used by abclinuxu for concepts.
Parameters: timestamp (int) – Timestamp as float/int. Returns: Converted timestamp. Return type: str
-
abclinuxuapi.shared.
url_context
(rel_url)¶ Add rel_url to the absolute context with
ABCLINUXU_URL
.Parameters: rel_url (str) – Relative URL. Returns: Absolute URL. Return type: str
-
abclinuxuapi.shared.
handle_errors
(dom)¶ Look for error divs in given dom tree.
Parameters: dom (obj) – dhtmlparser.HTMLElement
instance.Raises: UserWarning
– With content of the error div if the div was found.
-
abclinuxuapi.shared.
check_error_div
(data, error_div)¶ Dunno about this, it was created long time ago and I have no idea.
-
abclinuxuapi.shared.
check_error_page
(data)¶ Handle other, special kind of errors.