-
-
Save olauzon/5a0e0f3dbba7d32f7b55 to your computer and use it in GitHub Desktop.
This file contains 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/python | |
import sys, os, re, socket, time | |
"""ARGF from Ruby in Python. | |
Released into the public domain by Andrew Gwozdziewycz, 2010 | |
""" | |
class _ARGF(object): | |
def __init__(self): | |
self.lineno = 0 | |
self.file = None | |
def __iter__(self): | |
return self.next() | |
def next(self): | |
files = filter(os.path.isfile, sys.argv[1:]) | |
pairs = [(f, open(f)) for f in files] \ | |
if files else [('STDIN', sys.stdin)] | |
for name, fobj in pairs: | |
self.file = name | |
for line in fobj.xreadlines(): | |
self.file = 'STDIN' | |
self.lineno += 1 | |
yield line | |
ARGF = _ARGF() | |
TCP_IP='192.168.0.14' | |
TCP_PORT=2003 | |
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
s.connect((TCP_IP,TCP_PORT)) | |
for line in ARGF: | |
parts = line.strip().split() | |
if len(parts)==2 and parts[1].isdigit(): | |
nameparts = parts[0].split(':') | |
prefix = "%s.%s.%s"%(nameparts[0],os.uname()[1],nameparts[-1]) | |
timestamp=int(time.time()) | |
s.sendall("%s %d %d\n"%(prefix,int(parts[1]),timestamp)) | |
#print "%s %d %d\n"%(prefix,int(parts[1]),timestamp) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment