Last active
December 23, 2015 01:48
-
-
Save abackstrom/6562311 to your computer and use it in GitHub Desktop.
Sample Python server to return formatted data for GeekTool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Run this in the background. Poll using netcat: | |
# | |
# $ nc localhost 5005 | |
# | |
# Made for use with GeekTool. http://projects.tynsoe.org/en/geektool/ | |
# | |
import pytz | |
import socket | |
from datetime import datetime | |
TCP_IP = '127.0.0.1' | |
TCP_PORT = 5005 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((TCP_IP, TCP_PORT)) | |
s.listen(1) | |
while 1: | |
try: | |
conn, addr = s.accept() | |
d = datetime.now(pytz.timezone('US/Eastern')) | |
conn.send(d.strftime("%H:%M %Z") + "\n") | |
d = datetime.now(pytz.utc) | |
conn.send(d.strftime("%H:%M %Z")) | |
conn.close() | |
except KeyboardInterrupt: | |
break | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment