Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload takes too long.
#1
Hi all,

I have an upload script which uploads data every 5 minutes at every 00:00 00:05 00:10 00:15 and so on during 24/7.

But sometimes the upload takes too long.
The interval must be exactly at every 5 minutes and zero seconds,
Or for example when an upload is at 00:05:01 the next upload has to be at 00:10:01 with the same amount of seconds after the minute.
As you can see in the example upload below, one upload is done at 16:50:11 and the next upload is done at 16:55:01.
So thats shorter then exactly 5 minutes and zero seconds and thats why it gets an error and wont upload.
Ive also tried the "schedule.every(5).minutes.do(task)" but that wont start at exactly every 00:00:00 00:05:00 00:10:00 and has the same non exact interval.
My python script is included.


Received KNMI WOW 200 {}
Wed, 01 Apr 2020 16:50:11
winddir= 329.2
windspeedmph= 9.74
windgustmph= 14.28
windgustdir= 329.9
humidity= 44.24
dewptf= 31.54
tempf= 52.69
rainin= 0
dailyrainin= 0
baromin= 30.16438
solarradiation= 473.0833
Received KNMI WOW 429 The custom error module does not recognize this error.
Wed, 01 Apr 2020 16:55:01
winddir= 329.9
windspeedmph= 6.027
windgustmph= 13.15
windgustdir= 329.9
humidity= 44.29
dewptf= 31.36
tempf= 52.46
rainin= 0
dailyrainin= 0
baromin= 30.16297
solarradiation= 524.5936

import requests
import time
import schedule    
import csv
import urllib

WUurl = "https://wow.metoffice.gov.uk/automaticreading?"
siteid = "xxxxxxxx" 
siteAuthenticationKey = xxxxxx 
WUcreds = "siteid=" + siteid + "&siteAuthenticationKey="+ siteAuthenticationKey
date_str = "&dateutc=now"
action_str = "&action=updateraw"

def task():
        WeatherUnderground= open("C:\\Campbellsci\\LoggerNet\\CR1000_upload.dat", "r")
        csvReader = csv.reader(WeatherUnderground)
        for field in csvReader:
         a = (field[12])
         b = (field[17])
         c = (field[19])
         d = (field[16])
         e = (field[8])
         f = (field[7])
         g = (field[5])
         h = (field[27])
         i = (field[25])
         j = (field[10])
         k = (field[23])
         l = (field[16])
        winddir=a
        windspeedmph=b
        windgustmph=c
        windgustdir=d
        humidity=e  
        dewptf=f
        tempf=g
        rainin=h
        dailyrainin=i
        baromin=j
        solarradiation=k
        softwaretype=1

        r= requests.get(
        WUurl +
        WUcreds +
        date_str +
        "&winddir=" +
        str(winddir)+
        "&windspeedmph=" +
        str(windspeedmph)+
        "&windgustmph=" +
        str(windgustmph)+
        "&windgustdir=" +
        str(windgustdir)+
        "&humidity=" +
        str(humidity)+
        "&dewptf=" +
        str(dewptf)+
        "&tempf=" +
        str(tempf)+
        "&rainin=" +
        str(rainin)+
        "&dailyrainin=" +
        str(dailyrainin)+
        "&baromin=" +
        str(baromin)+
        "&solarradiation=" +
        str(solarradiation)+
        str(softwaretype)+    
        action_str)
        timeout=60 
        
        print("Received KNMI WOW " + str(r.status_code) + " " + str(r.text),flush=True)
        print (time.strftime("%a, %d %b %Y %H:%M:%S"), flush=True)
        print ("winddir= " + a, flush=True)
        print ("windspeedmph= " + b, flush=True)
        print ("windgustmph= " + c, flush=True)
        print ("windgustdir= " + d, flush=True)
        print ("humidity= " + e, flush=True)
        print ("dewptf= " + f, flush=True)
        print ("tempf= " + g, flush=True)
        print ("rainin= " + h, flush=True)
        print ("dailyrainin= " + i, flush=True)
        print ("baromin= " + j, flush=True)
        print ("solarradiation= " + k, flush=True)

while True:
 try:
     task()
     time.sleep(300 - time.time() % 300)
     refresh()
 except:
    pass
    time.sleep(1)

else:
 time.sleep(300)
Reply


Messages In This Thread
Upload takes too long. - by Makada - Apr-01-2020, 03:12 PM
RE: Upload takes too long. - by deanhystad - Apr-01-2020, 04:33 PM
RE: Upload takes too long. - by Makada - Apr-01-2020, 04:42 PM
RE: Upload takes too long. - by BrendanD - Apr-01-2020, 05:24 PM
RE: Upload takes too long. - by Makada - Apr-01-2020, 05:49 PM
RE: Upload takes too long. - by BrendanD - Apr-01-2020, 06:06 PM
RE: Upload takes too long. - by Makada - Apr-01-2020, 06:26 PM
RE: Upload takes too long. - by BrendanD - Apr-01-2020, 07:19 PM
RE: Upload takes too long. - by Makada - Apr-01-2020, 07:22 PM
RE: Upload takes too long. - by BrendanD - Apr-01-2020, 08:21 PM
RE: Upload takes too long. - by Makada - Apr-01-2020, 08:29 PM
RE: Upload takes too long. - by Makada - Apr-02-2020, 03:15 PM
RE: Upload takes too long. - by BrendanD - Apr-02-2020, 06:20 PM
RE: Upload takes too long. - by Makada - Apr-02-2020, 07:04 PM
RE: Upload takes too long. - by BrendanD - Apr-02-2020, 07:39 PM
RE: Upload takes too long. - by Makada - Apr-02-2020, 07:49 PM
RE: Upload takes too long. - by BrendanD - Apr-02-2020, 08:32 PM
RE: Upload takes too long. - by Makada - Apr-02-2020, 08:37 PM
RE: Upload takes too long. - by BrendanD - Apr-02-2020, 08:43 PM
RE: Upload takes too long. - by Makada - Apr-02-2020, 08:58 PM
RE: Upload takes too long. - by BrendanD - Apr-02-2020, 10:58 PM
RE: Upload takes too long. - by Makada - Apr-03-2020, 04:07 AM
RE: Upload takes too long. - by Makada - Apr-03-2020, 03:38 PM
RE: Upload takes too long. - by BrendanD - Apr-03-2020, 03:41 PM
RE: Upload takes too long. - by Makada - Apr-03-2020, 04:34 PM
RE: Upload takes too long. - by BrendanD - Apr-03-2020, 05:30 PM
RE: Upload takes too long. - by Makada - Apr-04-2020, 10:17 AM
RE: Upload takes too long. - by BrendanD - Apr-04-2020, 02:12 PM
RE: Upload takes too long. - by Makada - Apr-05-2020, 11:56 AM
RE: Upload takes too long. - by Makada - Apr-06-2020, 08:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Run a timer when a functions starts to see how long the function takes to complete Pedroski55 2 2,167 Apr-19-2020, 06:28 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020