#!/usr/bin/env python3

import os
import subprocess
import re
import datetime
import pygsheets
import speedtest

# Set constants
DATE = datetime.datetime.now().strftime("%d-%m-%y %H:%M:%S")

def get_credentials():
    """Function to check for valid OAuth access tokens."""
    gc = pygsheets.authorize(outh_file="credentials.json")
    return gc

def submit_into_spreadsheet(download, upload, ping):
    """Function to submit speedtest result."""
    gc = get_credentials()

    speedtest = gc.open(os.getenv('SPREADSHEET', 'Speedtest'))
    sheet = speedtest.sheet1

    data = [DATE, download, upload, ping]

    sheet.append_table(values=data)

def main():
    # Check for proper credentials
    print("Checking OAuth validity...")
    credentials = get_credentials()

    # Run speedtest and store output
    print("Starting speed test...")
    spdtest = speedtest.Speedtest()
    spdtest.get_best_server()
    
    download = round(spdtest.download() / 1024 / 1024, 2)
    upload = round(spdtest.upload() / 1024 / 1024, 2)
    ping = round(spdtest.results.ping)

    print("Starting speed finished (Download: ", download, ", Upload: ", upload, ", Ping: ", ping, ")")

    # Write to spreadsheet
    print("Writing to spreadsheet...")
    submit_into_spreadsheet(download, upload, ping)
    print("Successfuly written to spreadsheet!")

if __name__ == "__main__":
    main()

@@ -949,33 +949,33 @@
 nload() / 10
-24
+00
  / 10
-24
+00
 , 2)%0A    upl
@@ -1011,17 +1011,17 @@
 / 10
-24
+00
  / 10
-24
+00
 , 2)

Fix division for bits (not bytes)