Created
March 24, 2016 15:17
-
-
Save sjmf/b517f5bf4eb5291e9088 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 | |
""" | |
This script can quickly reformat a BuildAX CSV file to unix timestamp, | |
excluding tx power and PIR counts | |
In: 2015/05/15,14:51:56,427A538D,-44,2,34,20,3225,30.74,231,0,30,30367,1 | |
Out: 1431697916,427A538D,-44,2,34,3225,30.74,23.1,0,30367,1 | |
""" | |
import re | |
import sys | |
from time import mktime | |
from datetime import datetime | |
# Regex for getting datetime | |
time_re = re.compile('\d{4}(/\d{2}){2},(\d{2}:?){3}') | |
for line in sys.stdin: | |
utime = time_re.search(line).group(0) | |
utime = str(int(mktime(datetime.strptime(utime, "%Y/%m/%d,%H:%M:%S").timetuple()))) | |
out = line.split(',') | |
sys.stdout.write(utime +','+ | |
','.join(out[2:6]) + ',' + | |
','.join(out[7:9]) + ',' + | |
str(float(out[9]) / 10) + ',' + | |
str(out[10]) + ',' + | |
','.join(out[-2:]) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment