我一直在将树莓派上的一个循环循环的天气数据写入csv约两天。但是,它停止将行添加到csv。实际上,它似乎重写了昨晚的最后一行,并且没有获取更多数据点。但是,我有一个指示灯,如果有错误,该指示灯应该熄灭,并且仍在点亮。那么可能是什么问题? LED能否一直亮着?
03/08/19 15:17,Partly Cloudy,partly-cloudy-day,101,241,0,0,2.4,-0.96,-11.53,0.35,1025.31,3.45,5.56,237,0.55,1,14.11,420.84
03/08/19 16:17,Clear,clear-day,71,239,0,0,2.03,-1.76,-12.02,0.34,1024.72,3.95,6.68,235,0.08,0,12.89,418.95
03/08/19 17:17,Clear,clear-day,51,73,0,0,0.7,-2.83,-11.06,0.41,1024.09,3.21,6.73,225,0,0,13.39,417.63
03/08/19 18:17,Clear,clear-night,80,274,0,0,-0.34,-4.17,-10.83,0.45,1024.14,3.31,5.11,233,0.02,0,14.93,417.08
03/08/19 19:17,Clear,clear-night,10,262,0,0,-0.77,-3.76,-9.25,0.53,1024.25,2.34,3.49,239,0.04,0,14.44,415.87
03/08/19 20:17,Clear,clear-night,10,268,0,0,-1.1,-2.94,-8.4,0.58,1024.42,1.46,1.57,236,0,0,15,416.49
03/08/19 21:17,Clear,clear-night,10,263,0,0,-1.47,-3.23,-8.09,0.61,1024.39,1.38,1.44,225,0,0,15.58,417.33
03/08/19 22:17,Clear,clear-night,8,261,0,0,-1.85,-1.85,-7.96,0.63,1023.68,0.99,1.4,226,0,0,15.66,416.98
03/08/19 23:17,Clear,clear-night,10,262,0,0,-2.35,-2.35,-8.04,0.65,1023.23,1.05,1.59,257,0,0,15.84,415.14
03/09/19 00:17,Clear,clear-night,10,268,0,0,-2.56,-4.54,-7.83,0.67,1023.11,1.43,1.65,240,0,0,16,412.74
03/09/19 01:17,Clear,clear-night,10,263,0,0,-2.81,-4.78,-8.16,0.67,1022.78,1.4,4.53,218,0,0,15.77,410.65
03/09/19 02:17,Clear,clear-night,317,298,0,0,-3.38,-3.38,-8.33,0.69,1022.88,0.82,1.33,252,0,0,15.8,417.96
03/09/19 03:17,Clear,clear-night,877,213,0,0,-3.63,-6.68,-7.95,0.72,1023.21,1.99,4.01,278,0.01,0,16.09,416.21
03/09/19 04:17,Clear,clear-night,206,182,0,0,-4.99,-7.87,-8.92,0.74,1023.07,1.74,1.74,222,0,0,15.06,415.76
03/09/19 05:17,Clear,clear-night,449,22,0,0,-4.44,-4.44,-8.47,0.73,1023.56,0.87,1.58,132,0,0,15.27,417.22
03/09/19 06:17,Clear,clear-day,51,103,0,0,-5.1,-9.27,-8.97,0.74,1023.82,2.67,2.67,342,0,0,13.87,418.91
03/09/19 07:17,Clear,clear-day,314,297,0,0,-4.02,-6.7,-7.77,0.75,1024.42,1.71,2.17,242,0,0,15.16,418.96
03/09/19 08:17,Clear,clear-day,610,244,0,0,-1.92,-1.92,-6.53,0.71,1024.85,0.89,2.91,309,0,1,14.84,417.68
03/09/19 09:17,Clear,clear-day,451,22,0,0,1.2,-0.84,-4.82,0.64,1025.5,1.83,2.95,346,0,2,15.93,415.41
03/09/19 10:17,Clear,clear-day,570,234,0,0,3.79,3.79,-6.23,0.48,1026.07,1.31,2.06,12,0,3,16.09,411.98
03/09/19 11:17,Clear,clear-day,655,216,0,0,4.47,3.33,-7.25,0.42,1025.87,1.52,4.52,5,0,3,16.09,407.16
03/09/19 12:17,Clear,clear-day,578,212,0,0,5.4,3.61,-8.23,0.37,1026,2.24,2.72,23,0,3,14.76,401.82
03/09/19 13:17,Clear,clear-day,523,224,0,0,5.85,4.73,-8.81,0.34,1025.8,1.65,1.99,43,0,3,13.79,398.74
03/09/19 14:17,Clear,clear-day,589,234,0,0,6.24,6.24,-9.21,0.32,1026.22,1.22,2.22,41,0,2,13.47,395.09
03/09/19 15:17,Clear,clear-day,446,248,0,0,6.76,6.12,-8.96,0.32,1025.84,1.36,2.7,40,0,1,12.5,391.32
03/09/19 16:17,Clear,clear-day,410,245,0,0,6.9,6.9,-9.05,0.31,1026.6,0.95,2.35,69,0,0,12.09,387.73
03/09/19 17:17,Clear,clear-day,568,283,0,0,5.95,5.95,-9.85,0.31,1027.19,1.11,2.57,81,0.01,0,9.51,384.44
03/09/19 18:17,Clear,clear-night,293,224,0,0,3.46,2.15,-8.87,0.4,1028.31,1.53,3.61,74,0.02,0,6.42,381.38
03/09/19 19:17,Clear,clear-night,124,264,0,0,3.01,1.56,-8.45,0.43,1028.99,1.59,2.93,112,0.04,0,12.78,375.79
03/09/19 20:17,Clear,clear-night,566,283,0,0,1.93,0.28,-7.62,0.49,1029.74,1.61,3.81,132,0.08,0,13.18,374.52
03/09/19 21:17,Clear,clear-night,317,298,0,0,0.53,0.53,-7.03,0.57,1029.73,1.06,2.59,142,0.17,0,15.58,373.91
03/09/19 22:17,Clear,clear-night,315,298,0,0,0.11,0.11,-7,0.59,1029.54,0.76,4.9,158,0.2,0,16.09,372.87
03/09/19 23:17,Clear,clear-night,378,276,0,0,-0.19,-0.19,-6.82,0.61,1030.64,0.45,1.53,219,0,0,15.76,371.21
03/10/19 00:17,Partly Cloudy,partly-cloudy-night,10,256,0,0,-0.83,-0.83,-6.66,0.65,1030.98,0.45,1.22,44,0.28,0,15.76,368.93
03/10/19 01:17,Clear,clear-night,8,281,0,0,-0.91,-0.91,-6.27,0.67,1031.33,0.66,1.76,31,0.14,0,15.58,366.6
03/10/19 03:17,Clear,clear-night,8,288,0,0,-0.89,-2.79,-6.11,0.68,1030.7,1.52,3.47,56,0.11,0,15.64,360.86
-
import time
import requests
import csv
import json
import RPi.GPIO as GPIO
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
for k in [1,2,3,4]:
GPIO.output(7,GPIO.LOW)
time.sleep(2)
GPIO.output(7,GPIO.HIGH)
time.sleep(2)
try:
csvkeys=['time', 'summary', 'icon', 'nearestStormDistance', 'nearestStormBearing', 'precipIntensity', 'precipProbability', 'temperature',\
'apparentTemperature', 'dewPoint', 'humidity', 'pressure', 'windSpeed', 'windGust', 'windBearing', 'cloudCover', 'uvIndex', 'visibility', 'ozone']
URL = {url with api key}
while 1:
r=requests.get(URL)
data=r.json()
csvrow=[]
for k in csvkeys:
if k=='time':
csvrow.append(time.strftime("%D %H:%M", time.localtime(int(data['currently']['time']))))
else:
csvrow.append(data['currently'][k])
with open('Weather Project CSV', mode='a') as wpj:
wpj = csv.writer(wpj, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
wpj.writerow(csvrow)
time.sleep(3600)
except:
print('Error Encountered')
GPIO.output(7,GPIO.LOW)