feel<\/em> cooler. Okay, let’s focus back on our code, first we print out the current weather info: <\/p>\n\n\n\ndef getFormattedDateTime(datestr):\n p_datestr_format = ''.join(datestr.rsplit(\":\", 1))\n date_object = datetime.strptime(p_datestr_format, '%Y-%m-%dT%H:%M:%S%z')\n return date_object.strftime(\"%H:%M %A, %d %B %Y Timezone:%z\")\n\nurl = f\"http:\/\/dataservice.accuweather.com\/currentconditions\/v1\/{location_key}?apikey={API_KEY}&details=true\"\njson_data = getJSONfromUrl(url)\nunit = \"Metric\" if (metric == \"c\") else \"Imperial\"\nmetric_tag = \"true\" if (metric == \"c\") else \"false\"\n\nfor p in json_data:\n current_weather=p[\"WeatherText\"]\n current_temp=p[\"Temperature\"][unit]\n wind_speed=p[\"Wind\"][\"Speed\"][unit]\n date_w_format = getFormattedDateTime(p[\"LocalObservationDateTime\"])\n\nchar_length = 50\nprint(f\"Location: {location}, {admin_area}, {country}\") \nprint(f\"Local observation time: {date_w_format}\")\nprint(f\"Current weather status: {current_weather}\")\nprint(f\"Current temperature: {current_temp['Value']} {current_temp['Unit']}\")\nprint(f\"Wind speed: {wind_speed['Value']} {wind_speed['Unit']}\")\nprint(f\"\\n{'='*char_length}\")\n<\/pre>\n\n\n\nWhen we use “Los Angeles” as forecast location, <\/p>\n\n\n\n
$export ACW_API_KEY=abcde\n$python accuw_forecast.py -l \"Los Angeles\" -m c<\/code><\/pre>\n\n\n\nIt should print out: <\/p>\n\n\n\n
Location: Los Angeles, CA, United States\nLocal observation time: 02:23 Friday, 31 May 2019 Timezone:-0700\nCurrent weather status: Cloudy\nCurrent temperature: 15.6 C\nWind speed: 5.6 km\/h<\/code><\/pre>\n\n\n\nIt looks good and the 5-day forecast part is similar to the the current weather part: <\/p>\n\n\n\n
url = f\"http:\/\/dataservice.accuweather.com\/forecasts\/v1\/daily\/5day\/{location_key}?apikey={API_KEY}&details=true&metric={metric_tag}\"\njson_data = getJSONfromUrl(url)\n\nprint(f\"5-day summery: {json_data['Headline']['Text']}\")\nfor d in json_data[\"DailyForecasts\"]:\n print(f\"{'-'*char_length}\")\n print(f\"Date: {getFormattedDateTime( d['Date'])}\")\n print(f\"Min temperature: {d['Temperature']['Minimum']['Value']} {d['Temperature']['Minimum']['Unit']}\")\n print(f\"Max temperature: {d['Temperature']['Maximum']['Value']} {d['Temperature']['Maximum']['Unit']}\")\n print(f\"Description: {d['Day']['LongPhrase']}\")\n print(f\"Rain probability: {d['Day']['RainProbability']} %\")\n print(f\"Wind speed: {d['Day']['Wind']['Speed']['Value']} {d['Day']['Wind']['Speed']['Unit']}\")\n<\/pre>\n\n\n\nAnd our output should look like: <\/p>\n\n\n\n
==================================================\n5-day summery: Mostly cloudy this weekend\n--------------------------------------------------\nDate: 07:00 Friday, 31 May 2019 Timezone:-0700\nMin temperature: 13.9 C\nMax temperature: 22.2 C\nDescription: Low clouds giving way to sunshine\nRain probability: 4 %\nWind speed: 9.7 km\/h\n--------------------------------------------------\nDate: 07:00 Saturday, 01 June 2019 Timezone:-0700\nMin temperature: 13.9 C\nMax temperature: 21.1 C\nDescription: Low clouds followed by some sun\nRain probability: 10 %\nWind speed: 9.7 km\/h\n......<\/code><\/pre>\n\n\n\nThat’s it! We’ve just finished another weather forecast program. Then we go for our next topic— Quality Assurance.<\/p>\n\n\n\n
Quality Assurance on AccuWeather program<\/h3>\n\n\n\n
We believe everyone codes in the future, no matter it is coded by human or A.I.. In order to code better than others, we run quality assurance to make good our products. Then it comes up another question, what is quality assurance? <\/p>\n\n\n\n
Quality assurance (QA) is a set of processes to ensure our products meet requirements. It is including but not limited to testing. It can be applied to the planning stage of the Software Development Life Cycle (SDLC). Do you remember we think about getting bulk locations from the first ACW run? And the case to avoid forecasting locations with the same name? <\/p>\n\n\n\n
Yes, those are processes of QA to ensure the program is robust. We also include wind speed in the ACW to let users consider the wind chill factor. We should document those QA processes, so we can apply the pattern for similar projects.<\/p>\n\n\n\n
Since we are running QA, why don’t we test our program once again? This time, just run the program without arguments, to test the Profile<\/em> functionality. <\/p>\n\n\n\n$python accuw_forecast.py<\/code><\/pre>\n\n\n\nThen it should print out:<\/p>\n\n\n\n
Location: Los Angeles, CA, United States\nLocal observation time: 10:53 Friday, 31 May 2019 Timezone:-0\nCurrent weather status: Cloudy\nCurrent temperature: 18.3 C\nWind speed: 0.0 km\/h\n\n==================================================\n5-day summery: Mostly cloudy this weekend\n--------------------------------------------------\nDate: 07:00 Friday, 31 May 2019 Timezone:-0700\nMin temperature: 14.4 C\nMax temperature: 22.8 C\nDescription: Low clouds giving way to sunshine\nRain probability: 4 %\nWind speed: 6.4 km\/h\n--------------------------------------------------\nDate: 07:00 Saturday, 01 June 2019 Timezone:-0700\nMin temperature: 13.9 C\nMax temperature: 21.1 C\nDescription: Low clouds followed by some sun\nRain probability: 10 %\nWind speed: 9.7 km\/h\n--------------------------------------------------\nDate: 07:00 Sunday, 02 June 2019 Timezone:-0700\nMin temperature: 14.4 C\nMax temperature: 21.1 C\nDescription: Low clouds followed by some sun\nRain probability: 12 %\nWind speed: 9.7 km\/h\n--------------------------------------------------\nDate: 07:00 Monday, 03 June 2019 Timezone:-0700\nMin temperature: 15.0 C\nMax temperature: 22.6 C\nDescription: Low clouds followed by sunshine\nRain probability: 3 %\nWind speed: 9.3 km\/h\n--------------------------------------------------\nDate: 07:00 Tuesday, 04 June 2019 Timezone:-0700\nMin temperature: 15.6 C\nMax temperature: 23.6 C\nDescription: Low clouds followed by sunshine\nRain probability: 0 %\nWind speed: 9.3 km\/h<\/pre>\n\n\n\n