diff options
Diffstat (limited to 'game/python-extra/mwclient/util.py')
-rw-r--r-- | game/python-extra/mwclient/util.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/game/python-extra/mwclient/util.py b/game/python-extra/mwclient/util.py new file mode 100644 index 0000000..afa9954 --- /dev/null +++ b/game/python-extra/mwclient/util.py @@ -0,0 +1,24 @@ +import time +import io + + +def parse_timestamp(t): + """Parses a string containing a timestamp. + + Args: + t (str): A string containing a timestamp. + + Returns: + time.struct_time: A timestamp. + """ + if t is None or t == '0000-00-00T00:00:00Z': + return time.struct_time((0, 0, 0, 0, 0, 0, 0, 0, 0)) + return time.strptime(t, '%Y-%m-%dT%H:%M:%SZ') + + +def read_in_chunks(stream, chunk_size): + while True: + data = stream.read(chunk_size) + if not data: + break + yield io.BytesIO(data) |