Running Yahoo Weather API

- We need to figure out how to get this output onto our calendar
- We need to figure out how to get this as a json file right?
import datetime
import json
# Create date variable with a random value
date = 1
# Create dateCalc to display the current time
dateCalc = datetime.datetime.now()
# If statements to change the value of date so then it can be used in the API. The day of the weeks for the API is three letter abbreviations.
if dateCalc.strftime("%A") == "Monday":
    date = "Mon"
if dateCalc.strftime("%A") == "Tuesday":
    date = "Tue"
if dateCalc.strftime("%A") == "Wednesday":
    date = "Wed"
if dateCalc.strftime("%A") == "Thursday":
    date = "Thu"
if dateCalc.strftime("%A") == "Friday":
    date = "Fri"
if dateCalc.strftime("%A") == "Saturday":
    date = "Sat"
if dateCalc.strftime("%A") == "Sunday":
    date = "Sun"
 
# Set count to 1 so the data only runs once, then this will only display the current day of this week and not next week.
count = 1
 
# Access the API
import requests
 
url = "https://yahoo-weather5.p.rapidapi.com/weather"
 # Uncomment this if there's time
# location = input()
# def getinfo(location)
# getinfo (location)
    # Do str(location) if there's time
querystring = {"location": "San Diego","format":"json","u":"f"}
 
headers = {
    "X-RapidAPI-Key": "hi",
    "X-RapidAPI-Host": "hi"
}
 
response = requests.request("GET", url, headers=headers, params=querystring)
 
# Uncomment this to access raw data
# print(response.text)
 
# Filter out the data to display only weather info today, do str(location) if there's time
print("Weather is in ◦F")
print("Forecast in", "San Diego", ":")
result = response.json().get('forecasts')
for re in result:
    if count == 1:
        if re["day"] == date:
            jsonDay = {"day": dateCalc.strftime("%A"), "low": re["low"], "high": re["high"], "text": re["text"]}
            print(dateCalc.strftime("%A"))
            print("Low:", re["low"])
            print("High:", re["high"])
            print("Weather:", re["text"])
            count = count + 1
# Need the json file for the code below, it's on the flask project
# apidata = 'apidata.json'
# with open(apidata, 'w') as data:
#     json.dump(jsonDay, data)
Weather is in ◦F
Forecast in San Diego :
Tuesday
Low: 57
High: 69
Weather: Partly Cloudy
import datetime
# Create date variable with a random value
date = 1
# Create dateCalc to display the current time
dateCalc = datetime.datetime.now()
# If statements to change the value of date so then it can be used in the API. The day of the weeks for the API is three letter abbreviations.
if dateCalc.strftime("%A") == "Monday":
    date = "Mon"
if dateCalc.strftime("%A") == "Tuesday":
    date = "Tue"
if dateCalc.strftime("%A") == "Wednesday":
    date = "Wed"
if dateCalc.strftime("%A") == "Thursday":
    date = "Thu"
if dateCalc.strftime("%A") == "Friday":
    date = "Fri"
if dateCalc.strftime("%A") == "Saturday":
    date = "Sat"
if dateCalc.strftime("%A") == "Sunday":
    date = "Sun"
 
# Set count to 1 so the data only runs once, then this will only display the current day of this week and not next week.
count = 1
 
# Access the API
import requests
 
url = "https://yahoo-weather5.p.rapidapi.com/weather"
 
location = input()
 
querystring = {"location": str(location),"format":"json","u":"f"}
 
headers = {
    "X-RapidAPI-Key": "hi",
    "X-RapidAPI-Host": "hi"
}
 
response = requests.request("GET", url, headers=headers, params=querystring)
 
# Uncomment this to access raw data
# print(response.text)
 
# Filter out the data to display only weather info today
print("Weather is in ◦F")
print("Forecast in", str(location), ":")
result = response.json().get('forecasts')
for re in result:
    if count == 1:
        if re["day"] == date:
            print(dateCalc.strftime("%A"))
            print("Low:", re["low"])
            print("High:", re["high"])
            print("Weather:", re["text"])
            count = count + 1

# apidata = 'apidata.json'
# with open(apidata, 'w') as wd:
#     wd.writelines(response.json())
Weather is in ◦F
Forecast in Manchester :
Thursday
Low: 42
High: 52
Weather: Mostly Cloudy

Weather API (in Java)

import axios from "axios";

const options = {
  method: 'GET',
  url: 'https://yahoo-weather5.p.rapidapi.com/weather',
  params: {location: 'sunnyvale', format: 'json', u: 'f'},
  headers: {
    'X-RapidAPI-Key': 'hi',
    'X-RapidAPI-Host': 'hi'
  }
};

axios.request(options).then(function (response) {
	console.log(response.data);
}).catch(function (error) {
	console.error(error);
});
evalmachine.<anonymous>:1
import axios from "axios";
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at run ([eval]:1020:15)
    at onRunRequest ([eval]:864:18)
    at onMessage ([eval]:828:13)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:758:12)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
import requests
 
url = "https://yahoo-weather5.p.rapidapi.com/weather"
 
location = input()
 
querystring = {"location": str(location),"format":"json","u":"f"}
 
headers = {
    "X-RapidAPI-Key": "hi",
    "X-RapidAPI-Host": "hi"
}
 
response = requests.request("GET", url, headers=headers, params=querystring)

print(response)


# gets the weather data and prints to a file
apidata = 'apidata.json'
with open(apidata, 'w') as wd:
    wd.writelines(response.text)
<Response [200]>