two simple questions:
1. The Hour and Minute values returned are in the format '18' and '30' including the quote marks. I don't know if this is a Python thing, but I want simple numerical values, not a text string. How do I strip out the quote marks and ensure that I am left with a numerical value (one that I can do some maths with at a later date).
2. When I run the code in a terminal window, it obviously loops round, looking at the gps dongle every few seconds and displaying the results. I want to stop the program running, but keep the last set of results displayed in the terminal window so I can copy and paste the output. Ctrl+C just shuts it completely. Any suggestions?
Answers in words of one syllable or less please, it's taken me all day to write the following and get it to work:
- Code: Select all
#timetest1.py
#
from datetime import datetime
import time, os, gps, calendar
session = gps.gps(host="localhost", port="2947")
session.poll()
session.stream()
while 1:
os.system("clear")
session.poll()
print "Just for info:"
print "time GPS " , session.fix.time
print "time utc " , session.utc, session.fix.time
print "***************"
timestamp = session.fix.time
print "Simple check for syntax:"
print repr(timestamp)
print "****************"
print "[1]"
time_gmtuple = time.gmtime(timestamp)
print "This is the time according to the GPS dongle"
print repr(time_gmtuple) #***
print "******************"
print "[2]"
print "As for [1] but converted to a sort of string"
dt_obj = datetime.utcfromtimestamp(timestamp)
print repr(dt_obj)
print "******************"
print "[3]"
print "Extract the <Hours> value from the string"
extract_hrs = dt_obj.strftime("%H")
print repr(extract_hrs)
print "******************"
print "[4]"
print "Extract the <Minutes> value from the string"
extract_min = dt_obj.strftime("%M")
print repr(extract_min)
for i in session.satellites:
print "t", i
time.sleep(5)