Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload takes too long.
#24
Here is my example of just reading the csv into values and parsing the date. I have added code that will abort if it tries to read more than one line from a csv. Note that your code reads each line of the csv and tries to upload each line to WOW without any pauses, because your requests call is inside the loop reading your csv file.
import csv
import datetime

with open('test.csv', 'r') as csv_file:
    csv_reader = csv.reader(csv_file)
    total_rows = 0
    for row in csv_reader:
        total_rows +=1
        assert total_rows == 1
        year = row[1]
        day_of_year = row[2]
        hhmm = row[3]
        hh = hhmm[:2]
        mm = hhmm[2:]
        winddir = row[12]
        windspeedmph = row[17]
        windgustmph = row[19]
        windgustdir = row[16]
        humidity = row[8]
        dewptf = row[7]
        tempf = row[5]
        rainin = row[27]
        dailyrainin = row[25]
        baromin = row[10]
        solarradiation = row[23]
        l = row[16]
softwaretype=1
year = int(year)
day_of_year = int(day_of_year) - 1
hour = int(hhmm[:2])
minute = int(hhmm[2:])
first_day_of_year = datetime.date(year, 1, 1)
dateutc = first_day_of_year + datetime.timedelta(days=day_of_year)
dateutc = datetime.datetime.combine(dateutc, datetime.time(hour, minute))
dateutc_string = f'&dateutc={dateutc:%Y-%m-%d+%H:%M:%S}'
dateutc_string = dateutc_string.replace(':', '%3a')
Finally, it does not make sense to have a python script running continuously for a scheduled task. If you are on windows you should set up a scheduled task that runs your python code every five minutes. On linux you would have to use crontab or one of its more modern variants. Personally, as someone who works regularly with ocean and met data, five minutes is overkill. If you change your AWS output frequency to 10 minutes and your upload frequency to ten minutes, you will never be rejected by WOW. You trade frequency for reliability. Also, if you are clever, you can catch when the WOW upload fails, wait five minutes and try the same upload string again. You get two chances over ten minutes to upload. If you choose 15 minutes, you could have three upload attempts.

Finally (I am full of hot air...), I would suggest using pywws instead of a home-baked solution.
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,119 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