Skip to content
Snippets Groups Projects
util.py 642 B
Newer Older
  • Learn to ignore specific revisions
  • from datetime import datetime, timedelta
    
    
    
    def get_pub_ip():
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.settimeout(0)
        try:
            # doesn't even have to be reachable
            s.connect(('10.254.254.254', 1))
            ip = s.getsockname()[0]
        except Exception:
            ip = '127.0.0.1'
        finally:
            s.close()
    
        return ip
    
    
    def next_minute() -> datetime:
        now = datetime.now()
    
        # Calculate the first second of the next minute
    
        start_of_minute = datetime(now.year, now.month, now.day, now.hour, now.minute, 0, 0)
    
        start_of_minute += timedelta(minutes=1)
    
        return start_of_minute