Dweepy to record temperature data: Difference between revisions
Jump to navigation
Jump to search
(Created page with "= Get all data = <syntaxhighlight lang="python"> import dweepy url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-11-bundoora') print(url) </syntaxhighlight> = Get temperature data = <syntaxhighlight lang="python"> import dweepy url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-11-bundoora') print(url) dict = url[0] internalTemp = dict['content'][('intTemp')] print(f'The internal temperature is {internalTemp}') externalTemp = dict['content'][('extTemp')] prin...") |
No edit summary |
||
| Line 1: | Line 1: | ||
= Get Dweet using Browser = | |||
<syntaxhighlight lang="python"> | |||
https://dweet.io/get/latest/dweet/for/MPPS-Tiny-House-11-bundoora? | |||
</syntaxhighlight> | |||
= Get all data = | = Get all data = | ||
Latest revision as of 07:15, 24 February 2024
Get Dweet using Browser
https://dweet.io/get/latest/dweet/for/MPPS-Tiny-House-11-bundoora?
Get all data
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-11-bundoora')
print(url)
Get temperature data
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-11-bundoora')
print(url)
dict = url[0]
internalTemp = dict['content'][('intTemp')]
print(f'The internal temperature is {internalTemp}')
externalTemp = dict['content'][('extTemp')]
print(f'The outside temperature is {externalTemp}')
datetime = dict['content'][('date')]
Plot data
import dweepy
import pandas as pd
import plotly.express as px
#https://github.com/paddycarey/dweepy - Reference
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-11-bundoora')
print(url)
dict = url[0]
internalTemp = dict['content'][('intTemp')]
print(f'The internal temperature is {internalTemp}')
externalTemp = dict['content'][('extTemp')]
print(f'The outside temperature is {externalTemp}')
datetime = dict['content'][('date')]
# Saving data
data = str(datetime) + "," + str(internalTemp) + "," + \
str(externalTemp) + "\n"
print(f'The data is = {data}')
f = open('/home/pi/Tiny_House_11/tiny_house_11_data.txt','a')
f.write(data)
f.close()
print("The data has been saved")
# Step 2: Read the data from the text file into a Pandas DataFrame
data = pd.read_csv('/home/pi/Tiny_House_11/tiny_house_11_data.txt')
# Step 3: Create a Plotly figure with two scatter plots
fig = px.scatter(data, x='datetime', y=['intTemp', 'extTemp'],
labels={'datetime': 'Date and Time', 'value': 'Temperature (°C)'},
title='Internal vs. External Temperature')
# Step 4: Customize the plot layout
fig.update_layout(xaxis_title='Date and Time', yaxis_title='Temperature (°C)')
# Step 5: Save the plot as an HTML file
fig.write_html('/home/pi/Tiny_House_11/temperature_plot_tiny_house_11.html')
print("Temperature 11 plot saved as temperature_plot.html")