Created
March 8, 2019 06:35
-
-
Save dpfrakes/eabc018acff09b8384f4e8ca0dfb5602 to your computer and use it in GitHub Desktop.
Run speedtest and upload results to AWS DynamoDB
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
import boto3 | |
import speedtest | |
from decimal import Decimal | |
# Initialize variables | |
s = speedtest.Speedtest() | |
s.get_best_server() | |
# Run tests | |
s.download() | |
s.upload() | |
# Upload results to AWS | |
dynamodb = boto3.resource('dynamodb', region_name='us-east-1') | |
table = dynamodb.Table('speedtest_results') | |
response = table.put_item( | |
TableName='speedtest_results', | |
Item={ | |
'Server ID': s.results.server['id'], | |
'Sponsor': s.results.server['sponsor'], | |
'Server Name': s.results.server['name'], | |
'Timestamp': s.results.timestamp, | |
'Distance': Decimal(str(s.results.server['d'])), | |
'Ping': Decimal(str(s.results.ping)), | |
'Download': Decimal(str(s.results.download)), | |
'Upload': Decimal(str(s.results.upload)), | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment