Python weather

Discussion in 'General Discussion' started by BoothJoe, Mar 7, 2016.

  1. BoothJoe

    BoothJoe Registered

    Joined:
    Oct 12, 2015
    Messages:
    202
    Likes Received:
    8
    I wrote a really simple Python weather tool for RF2 because Gerald Jacobson's static weather tool wasn't working after the switch to Weatherunderground (he's now posted an updated version that works splendidly). The purpose was to begin learning Python because I'm finding I need some fatter tools at work to help manage Unix servers. The Python script works, so I thought I'd post it here in case anyone had a use for it or wanted to use it (free without attribution required) somewhere else. Let me repeat...it's very simple. There is no fancy error checking. It's really designed for offline, solitaire racing. You run the script (Python 2.7 required), enter the track you want, set the start times for practice, qualifying and race, choose a date from history and that's about it. It assumes you will do your practice, qualifying and race all in one day (which because RF2 doesn't really support uninterrupted race weekends I end up doing anyway). Besides Python 2.7, you need a free API key from weatherunderground. At the top of the script file, you need to put in the tracks and latitude/longitude. I included a bunch there and put some more in at the bottom of the file that could be cut and pasted to the dict definition at the top.

    The script will update an existing wet file for the track. It will also create a player1.JSON file, which is where the start and duration times live. I didn't want to rewrite player.JSON in case something went wrong...I don't want my player.JSON getting crapped up. This makes me make a copy of player.JSON before renaming player1.JSON. I've only discovered two issues. The first is that not all of the weather conditions (e.g. Heavy snow) aren't listed in the script because I didn't think they were relevant, and this will cause the script to die. The second is there weren't any weather date/observations for the location. This can happen if you choose a date before they kept records in a location or if that lat/long doesn't keep that kind of data.

    Anyway, if you find a use for it, here it is. It took me several days to figure things out with the wet files, player.JSON and the weatherunderground API so it might help someone understand some stuff. Also, if ISI or weatherunderground makes some weather changes, you can enhance or fix it yourself.
     
    Last edited by a moderator: Mar 7, 2016
  2. BoothJoe

    BoothJoe Registered

    Joined:
    Oct 12, 2015
    Messages:
    202
    Likes Received:
    8
    One kind of critical thing I forgot to mention. What this script does is use the Weatherunderground historic weather database to pull weather observations for a specific location (whichever lat/long you enter). Weather observations are not consistently timed across the world. They could be every hour on the hour. They could be at x:53. There could be several in a row done at the same minute (e.g. 1:53, 2:53, 3:53) and then suddenly there are observations for 3:55 and 3:59 and 4:15, etc). Using this tool (or using Gerald's much nicer one), you could get the same weather that existed at Monaco on May 22, 2005.
     
  3. BoothJoe

    BoothJoe Registered

    Joined:
    Oct 12, 2015
    Messages:
    202
    Likes Received:
    8
    Here's a version of the Python weather tool written in Python 3.51. I don't think there's any new functionality; I just cleaned some stuff up since I'm using this to teach myself python for work. No one was interested in the Python 2 version, so I won't go into any longwinded description. Suffice it to say that this tool allows you to get historic weather using weatherunderground, choose PQR start times and durations and plug that into the wet file for the track and into player.json.
     
  4. argo0

    argo0 Registered

    Joined:
    Jan 22, 2012
    Messages:
    624
    Likes Received:
    8
    Thanks for sharing your work

    Sent from my SM-N9005 using Tapatalk
     

Share This Page