Skip to content
Snippets Groups Projects
Select Git revision
  • 5ade1cc5ca0c5f6fd549e11ef5b159d79dac39b8
  • devel default
  • master
  • fo
  • jirka/typing
  • fo-base
  • mj/submit-images
  • jk/issue-96
  • jk/issue-196
  • honza/add-contestant
  • honza/mr7
  • honza/mrf
  • honza/mrd
  • honza/mra
  • honza/mr6
  • honza/submit-images
  • honza/kolo-vs-soutez
  • jh-stress-test-wip
  • shorten-schools
19 results

setup.py

Blame
  • utils.py 1.12 KiB
    import sys, os
    import traceback
    import datetime
    from typing import Optional
    
    def eprint(*args, flush=True):
        print(*args, file=sys.stderr, flush=flush)
    
    
    async def catch_all(corutine, exitcode=None):
        try:
            await corutine
        except Exception as e:
            eprint(traceback.format_exc())
            if exitcode is not None:
                exit(exitcode)
    
    local_timezone = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
    dt_pinf = datetime.datetime(2100, 1, 1, tzinfo=local_timezone)
    dt_minf = datetime.datetime(2000, 1, 1, tzinfo=local_timezone)
    
    
    def format_dt_to_user(dt: datetime.datetime) -> str:
        return dt.strftime("%Y-%m-%d %H:%M:%S")
    
    def parse_dt_from_user(val: str) -> Optional[datetime.datetime]:
        return datetime.datetime.strptime(val, "%Y-%m-%d %H:%M:%S").replace(tzinfo=local_timezone)
    
    def format_delay_s(s):
        if s is None:
            return ""
        if s < 0: return "- " + format_delay_s(-s)
        if s == 0: return "on time"
        if s < 60: return f"{s} s"
        if s < 10*60: return f"{s//60} min {s%60} s"
        if s < 60*60: return f"{s//60} min"
        if s < 60*60: return f"{s//60//60} h {s//60} min"