예제 #1
0
def export_tcx(device_sn, raw_file_name, output_dir):
    """
    Given a garmin raw packet dump, tcx to specified output directory.
    """
    with open(raw_file_name) as file:
        result = []
        host = garmin.MockHost(file.read())
        host.device_id = device_sn
        device = garmin.Device(host)
        run_pkts = device.get_runs()
        runs = garmin.extract_runs(device, run_pkts)
        for run in runs:
            tcx_name = time.strftime("%Y%m%d-%H%M%S.tcx", run.time.gmtime)
            tcx_full_path = os.path.sep.join([output_dir, tcx_name])
            _log.info("tcx: writing %s -> %s.",
                      os.path.basename(raw_file_name), tcx_full_path)
            with open(tcx_full_path, "w") as file:
                doc = create_document(device, [run])
                file.write(
                    etree.tostring(doc,
                                   pretty_print=True,
                                   xml_declaration=True,
                                   encoding="UTF-8"))
            result.append(tcx_full_path)
        return result
예제 #2
0
def export_tcx(raw_file_name, output_dir):
    """
    Given a garmin raw packet dump, tcx to specified output directory.
    """
    with open(raw_file_name) as file:
        result = []
        host = garmin.MockHost(file.read())
        device = garmin.Device(host)
        run_pkts = device.get_runs()
        runs = garmin.extract_runs(device, run_pkts)
        for run in runs:
            tcx_name = time.strftime("%Y%m%d-%H%M%S.tcx", run.time.gmtime)
            tcx_full_path = os.path.sep.join([output_dir, tcx_name])
            _log.info("tcx: writing %s -> %s.", os.path.basename(raw_file_name), tcx_full_path)
            with open(tcx_full_path, "w") as file:
                doc = create_document([run])
                file.write(etree.tostring(doc, pretty_print=True, xml_declaration=True, encoding="UTF-8"))
            result.append(tcx_full_path)
        return result
예제 #3
0
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


import sys
import logging
import lxml.etree as etree

import antd.garmin as garmin
import antd.tcx as tcx
import antd.cfg as cfg

cfg.init_loggers(logging.DEBUG, out=sys.stderr)

if len(sys.argv) != 2:
	print "usage: %s <file>" % sys.argv[0]
	sys.exit(1)

with open(sys.argv[1]) as file:
	host = garmin.MockHost(file.read())
	host.device_id = 0
	device = garmin.Device(host)
	runs = device.get_runs()
	doc = tcx.create_document(device, garmin.extract_runs(device, runs))
	print etree.tostring(doc, pretty_print=True, xml_declaration=True, encoding="UTF-8")
예제 #4
0
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import sys
import logging
import lxml.etree as etree

import antd.garmin as garmin
import antd.tcx as tcx
import antd.cfg as cfg

cfg.init_loggers(logging.DEBUG, out=sys.stderr)

if len(sys.argv) != 2:
    print "usage: %s <file>" % sys.argv[0]
    sys.exit(1)

with open(sys.argv[1]) as file:
    host = garmin.MockHost(file.read())
    host.device_id = 0
    device = garmin.Device(host)
    runs = device.get_runs()
    doc = tcx.create_document(device, garmin.extract_runs(device, runs))
    print etree.tostring(doc,
                         pretty_print=True,
                         xml_declaration=True,
                         encoding="UTF-8")