I must say that you came very far in one day. Looks like you have experience with these kind of things. It took me much longer to understand how I had to parse the weather information with help of JSON Helper.
I changed your program the following way:
set theFile to "Macintosh HD:Users:domenicobettinelli:Documents:sevendayforecast.txt"
tell application "JSON Helper"
set weatherdata to fetch JSON from "https://api.darksky.net/forecast/APIKEY/LATITUDE,LONGITUDE"
end tell
set i to 0
set b to 1
repeat with i from 0 to 7
set dailySummary to summary of item b of |data| of daily of weatherdata as string
set dailyTempLow to temperatureLow of item b of |data| of daily of weatherdata as string
set dailyTempHigh to temperatureHigh of item b of |data| of daily of weatherdata as string
if i = 0 then
set dailyDay to weekday of (current date)
set thisText to dailyDay & " : " & dailySummary & " HI: " & dailyTempHigh & "F, LO: " & dailyTempLow & "F" & return as string
writeToFile(thisText, theFile, false)
else
set dailyDay to (weekday of ((current date) + i * days))
set thisText to dailyDay & " : " & dailySummary & " HI: " & dailyTempHigh & "F, LO: " & dailyTempLow & "F" & return as string
writeToFile(thisText, theFile, true)
end if
set i to i + 1
set b to b + 1
end repeat
--- Handler that writes text to the file
--- boolAppend : boolean -- True append to existing file. False overwrite existing file
on writeToFile(theText, theFile, boolAppend)
local theText, theFile, boolAppend, otf
try
set theFile to theFile as string
set otf to open for access file theFile with write permission
if boolAppend is false then set eof of otf to 0
write theText to otf as «class utf8» starting at eof
close access otf
return true
on error eMsg number eNum
try
close access file otf
end try
error "Can't writeToFile: " & eMsg number eNum
end try
end writeToFile
The resulting weather forecast (for Amsterdam):
Thursday : Mostly cloudy until evening. HI: 64,5F, LO: 50,47F
Friday : Clear throughout the day. HI: 70,33F, LO: 50,17F
Saturday : Mostly cloudy throughout the day. HI: 70,39F, LO: 50,21F
Sunday : Mostly cloudy throughout the day. HI: 61,64F, LO: 43,13F
Monday : Partly cloudy until afternoon. HI: 64,18F, LO: 47,78F
Tuesday : Clear throughout the day. HI: 69,93F, LO: 54,24F
Wednesday : Clear throughout the day. HI: 74,2F, LO: 57,39F
Thursday : Mostly cloudy starting in the evening. HI: 74,51F, LO: 54,55F