Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Last active December 23, 2015 01:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abackstrom/6562311 to your computer and use it in GitHub Desktop.
Save abackstrom/6562311 to your computer and use it in GitHub Desktop.
Sample Python server to return formatted data for GeekTool.
#!/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