Last active
October 27, 2016 22:29
-
-
Save tomasinouk/a2f43cd0aee5a5a22200 to your computer and use it in GitHub Desktop.
Takes GPS and Cellular metrics from Conel, SmartWorkx router and write *.csv file. I used different method for parsing of each metrics as an exercise. Running Python from USB stick and writing file to a USB stick.
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
# run that in start-up script | |
# echo "Time UTC (GPS);Latitude;Longtitude;Altitude;Satellites;Fix;Speed over ground;Course over Ground;Date (GPS);Date (router);Time (Router)" > location_report.csv | |
import csv | |
import time | |
import datetime | |
import os.path | |
import os | |
csv_header_text = "Time UTC (GPS);Latitude;Longtitude;Altitude;Satellites;Fix;Speed over ground;Course over Ground;Date (GPS);Date (router);Time (Router); Cell Technology;Cell ID;Signal Strength;Signal Quality\n" | |
gps_data = "Current time (UTC) : 01:27:07.0" | |
f = open('./stats.gps') | |
date_str = str(datetime.datetime.now().strftime("%Y-%m-%d")) | |
file_name = "/mnt/usb/" + date_str + "_location_report.csv" | |
if os.path.isfile(file_name): | |
print "File " , file_name, " existst" | |
output_file = open(file_name, 'a') | |
a = csv.writer(output_file, delimiter=';') | |
file_content = f.readlines() | |
# print file_content | |
else: | |
print "File ", file_name, " does not existst" | |
fo = open(file_name, 'a') | |
fo.write(csv_header_text) | |
fo.close() | |
output_file = open(file_name, 'a') | |
a = csv.writer(output_file, delimiter=';') | |
file_content = f.readlines() | |
# print file_content | |
f = os.popen('status mobile') | |
mobile_info = f.read() | |
values_mobile = {} | |
ary = [] | |
for line in mobile_info.splitlines(): | |
line = line.strip() | |
if not line: | |
continue | |
ary.append(line.split(": ")) | |
for i in range(len(ary)): | |
# print ary[i][0] | |
ary[i][0] = ary[i][0].rstrip() | |
values_mobile = dict(ary) | |
# output_file = open('location_report.csv', 'a') | |
# a = csv.writer(output_file, delimiter=';') | |
# file_content = f.readlines() | |
# # print file_content | |
def parse(msg): | |
size = len(msg) | |
i = msg.find(":") | |
# print "char", i | |
# print "size", size | |
new_string = msg[i+1:size] | |
new_string = new_string.lstrip() | |
new_string = new_string.rstrip() | |
# charge = int(new_string) | |
# print new_string | |
return new_string | |
values = [] | |
# going through each line of the file and parsing and appending to the list/array | |
for line in file_content: | |
print parse(line) | |
values.append(parse(line)) | |
# adding router date and time | |
date_str = str(datetime.datetime.now().strftime("%Y.%m.%d")) | |
values.append(date_str) | |
time_str = str(datetime.datetime.now().strftime("%H:%M:%S")) | |
values.append(time_str) | |
# append Cellular metrics | |
values.append(values_mobile['Technology']) | |
values.append(values_mobile['Cell']) | |
values.append(values_mobile['Signal Strength']) | |
values.append(values_mobile['Signal Quality']) | |
# Needs to be writerow, writerows inserts delimiter after every char in the list | |
a.writerow(values) | |
output_file.close() | |
print values | |
# print "data: ", parse(gps_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment