<commit_before>package main

import (
	"archive/zip"
	"bytes"
	"context"
	"crypto/sha1"
	"encoding/base64"
	"encoding/binary"
	"encoding/hex"
	"encoding/json"
	"encoding/xml"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"strconv"
	"strings"
	"time"

	"github.com/pkg/errors"
)

const (
	appKey     = "com.runtastic.android"
	appSecret  = "<KEY>"
	appVersion = "6.9.2"

	baseAppURL  = "https://appws.runtastic.com"
	baseHubsURL = "https://hubs.runtastic.com"

	cookieAppSession = "_runtastic_appws_session"

	headerAccept             = "Accept"
	headerAppKey             = "X-App-Key"
	headerAppVersion         = "X-App-Version"
	headerAuthToken          = "X-Auth-Token"
	headerContentDisposition = "Content-Disposition"
	headerContentType        = "Content-Type"
	headerDate               = "X-Date"

	outputFormat = "2006-01-02 15.04.05"
	timeFormat   = "2006-01-02 15:04:05"

	httpTimeout  = 5 * time.Second
	retryTimeout = 2 * time.Second
	totalTimeout = 15 * time.Second
)

var (
	email    = flag.String("email", "", "Email (required)")
	password = flag.String("password", "", "Password (required)")

	errAuthenticationFailed = errors.New("Invalid email address or password")
	errMissingCredentials   = errors.New("Missing email address or password")
	errNoSessions           = errors.New("There were no activities to backup")

	// Info is used for logging information.
	Info = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime)

	// Error is used for logging errors.
	Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime)
)

type sessionID string

type loginRequest struct {
	Email                string   `json:"email"`
	AdditionalAttributes []string `json:"additionalAttributes"`
	Password             string   `json:"password"`
}

type user struct {
	ID          string `json:"userId"`
	AccessToken string `json:"accessToken"`
	SessionID   string
}

type activities struct {
	SyncedUntil string    `json:"syncedUntil"`
	HasMore     string    `json:"moreItemsAvailable"`
	Sessions    []session `json:"sessions"`
}

type session struct {
	ID                sessionID `json:"id"`
	DeletedAt         string    `json:"deletedAt"`
	GPSTraceAvailable string    `json:"gpsTraceAvailable"`
}

type sessionData struct {
	RunSessions struct {
		ID        string `json:"id"`
		StartTime string `json:"startTime"`
		EndTime   string `json:"endTime"`
		GPSData   struct {
			Trace string `json:"trace"`
		} `json:"gpsData"`
	} `json:"runSessions"`
}

type gpx struct {
	ID       sessionID `xml:"-"`
	XMLName  xml.Name  `xml:"gpx"`
	Version  float32   `xml:"version,attr"`
	Creator  string    `xml:"creator,attr"`
	Metadata metadata
	Track    track
}

type metadata struct {
	XMLName   xml.Name    `xml:"metadata"`
	StartTime rfc3339Time `xml:"time"`
	EndTime   time.Time   `xml:"-"`
}

type track struct {
	XMLName xml.Name `xml:"trk"`
	Segment trackSegment
}

type trackSegment struct {
	XMLName xml.Name `xml:"trkseg"`
	Points  []trackPoint
}

type trackPoint struct {
	XMLName   xml.Name    `xml:"trkpt"`
	Longitude float32     `xml:"lon,attr"`
	Latitude  float32     `xml:"lat,attr"`
	Elevation float32     `xml:"ele,omitempty"`
	Time      rfc3339Time `xml:"time,omitempty"`
}

type rfc3339Time struct {<commit_msg>Add xmlns to root element<commit_after>package main

import (
	"archive/zip"
	"bytes"
	"context"
	"crypto/sha1"
	"encoding/base64"
	"encoding/binary"
	"encoding/hex"
	"encoding/json"
	"encoding/xml"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"strconv"
	"strings"
	"time"

	"github.com/pkg/errors"
)

const (
	appKey     = "com.runtastic.android"
	appSecret  = "<KEY>"
	appVersion = "6.9.2"

	baseAppURL  = "https://appws.runtastic.com"
	baseHubsURL = "https://hubs.runtastic.com"

	cookieAppSession = "_runtastic_appws_session"

	headerAccept             = "Accept"
	headerAppKey             = "X-App-Key"
	headerAppVersion         = "X-App-Version"
	headerAuthToken          = "X-Auth-Token"
	headerContentDisposition = "Content-Disposition"
	headerContentType        = "Content-Type"
	headerDate               = "X-Date"

	outputFormat = "2006-01-02 15.04.05"
	timeFormat   = "2006-01-02 15:04:05"

	httpTimeout  = 5 * time.Second
	retryTimeout = 2 * time.Second
	totalTimeout = 15 * time.Second
)

var (
	email    = flag.String("email", "", "Email (required)")
	password = flag.String("password", "", "Password (required)")

	errAuthenticationFailed = errors.New("Invalid email address or password")
	errMissingCredentials   = errors.New("Missing email address or password")
	errNoSessions           = errors.New("There were no activities to backup")

	// Info is used for logging information.
	Info = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime)

	// Error is used for logging errors.
	Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime)
)

type sessionID string

type loginRequest struct {
	Email                string   `json:"email"`
	AdditionalAttributes []string `json:"additionalAttributes"`
	Password             string   `json:"password"`
}

type user struct {
	ID          string `json:"userId"`
	AccessToken string `json:"accessToken"`
	SessionID   string
}

type activities struct {
	SyncedUntil string    `json:"syncedUntil"`
	HasMore     string    `json:"moreItemsAvailable"`
	Sessions    []session `json:"sessions"`
}

type session struct {
	ID                sessionID `json:"id"`
	DeletedAt         string    `json:"deletedAt"`
	GPSTraceAvailable string    `json:"gpsTraceAvailable"`
}

type sessionData struct {
	RunSessions struct {
		ID        string `json:"id"`
		StartTime string `json:"startTime"`
		EndTime   string `json:"endTime"`
		GPSData   struct {
			Trace string `json:"trace"`
		} `json:"gpsData"`
	} `json:"runSessions"`
}

type gpx struct {
	ID       sessionID `xml:"-"`
	XMLName  xml.Name  `xml:"http://www.topografix.com/GPX/1/1 gpx"`
	Version  float32   `xml:"version,attr"`
	Creator  string    `xml:"creator,attr"`
	Metadata metadata
	Track    track
}

type metadata struct {
	XMLName   xml.Name    `xml:"metadata"`
	StartTime rfc3339Time `xml:"time"`
	EndTime   time.Time   `xml:"-"`
}

type track struct {
	XMLName xml.Name `xml:"trk"`
	Segment trackSegment
}

type trackSegment struct {
	XMLName xml.Name `xml:"trkseg"`
	Points  []trackPoint
}

type trackPoint struct {
	XMLName   xml.Name    `xml:"trkpt"`
	Longitude float32     `xml:"lon,attr"`
	Latitude  float32     `xml:"lat,attr"`
	Elevation float32     `xml:"ele,omitempty"`
	Time      rfc3339Time `xml:"time,omitempty"`
}

type rfc3339Time struct {
{'fraction_non_alphanumeric': 0.131668208448967, 'fraction_numerical': 0.018193031144002468, 'mean_word_length': 3.403937542430414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 41}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1702304', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2214, 'n_words': 507}