speedtest to use json... FIX LATER: Convertion
This commit is contained in:
		
							
								
								
									
										33
									
								
								bot.sh
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								bot.sh
									
									
									
									
									
								
							@@ -20,12 +20,27 @@ echo Image grabbed
 | 
			
		||||
#################################################################################
 | 
			
		||||
echo Doing speedtest
 | 
			
		||||
# Run speedtest and output to a file
 | 
			
		||||
speedtest > $speedtest_result
 | 
			
		||||
speedtest --json > $speedtest_result
 | 
			
		||||
# Extract information from the speedtest output
 | 
			
		||||
isp_name=$(grep -oP 'Hosted by \K.*(?= \[)' $speedtest_result)
 | 
			
		||||
latency=$(grep -oP 'Hosted by.*\[.*\]: \K[0-9.]+(?= ms)' $speedtest_result)
 | 
			
		||||
download_speed=$(grep -oP 'Download: \K.*(?= Mbit/s)' $speedtest_result)
 | 
			
		||||
upload_speed=$(grep -oP 'Upload: \K.*(?= Mbit/s)' $speedtest_result)
 | 
			
		||||
 | 
			
		||||
# Parsing JSON data
 | 
			
		||||
download=$(jq '.download' "$speedtest_result")
 | 
			
		||||
upload=$(jq '.upload' "$speedtest_result")
 | 
			
		||||
ping=$(jq '.ping' "$speedtest_result")
 | 
			
		||||
bytes_received=$(jq '.bytes_received' "$speedtest_result")
 | 
			
		||||
bytes_sent=$(jq '.bytes_sent' "$speedtest_result")
 | 
			
		||||
isp=$(jq -r '.client.isp' "$speedtest_result")
 | 
			
		||||
country=$(jq -r '.client.country' "$speedtest_result")
 | 
			
		||||
cc=$(jq -r '.client.cc' "$speedtest_result")
 | 
			
		||||
 | 
			
		||||
# Converting download and upload speeds from bytes per second to Mbit/s
 | 
			
		||||
download_mbps=$(echo "scale=3; $download / 125000" | bc)
 | 
			
		||||
upload_mbps=$(echo "scale=3; $upload / 125000" | bc)
 | 
			
		||||
 | 
			
		||||
# Converting bytes to MB
 | 
			
		||||
bytes_received_mb=$(echo "scale=2; $bytes_received / 1048576" | bc)
 | 
			
		||||
bytes_sent_mb=$(echo "scale=2; $bytes_sent / 1048576" | bc)
 | 
			
		||||
 | 
			
		||||
echo Speedtest complete
 | 
			
		||||
#################################################################################
 | 
			
		||||
 | 
			
		||||
@@ -53,10 +68,10 @@ echo Weather checked
 | 
			
		||||
caption="
 | 
			
		||||
$current_weather
 | 
			
		||||
 | 
			
		||||
🌐 *ISP*: $isp_name
 | 
			
		||||
🏓 *Latency*: $latency ms
 | 
			
		||||
⬇️  *Download*: $download_speed Mbit/s
 | 
			
		||||
⬆️  *Upload*: $upload_speed Mbit/s
 | 
			
		||||
🌐 *ISP*: $isp, $country, $cc
 | 
			
		||||
🏓 *Latency*: $ping ms
 | 
			
		||||
⬇️  *Download*: $download_mbps Mbit/s, Used: $bytes_received_mb MB
 | 
			
		||||
⬆️  *Upload*: Upload: $upload_mbps Mbit/s, Used: $bytes_sent_mb MB
 | 
			
		||||
"
 | 
			
		||||
#################################################################################
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user