@anonymous/

HappySolidMoto

Python

Learn how to make API calls in Python with requests

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env python3
# Make an api call

####### install the needed modules #######
import json, requests

####### url vars ####### 
api_token = 'b79d78227e937f5f7c7c2a4403852ed5'
lat = '40.7128'
lon = '-74.0060'
url = 'https://api.darksky.net/forecast/'+api_token+'/'+lat+','+lon
print(url)

####### make api call #######
data = requests.get(url).json()

####### parse data #######
temp = data['currently']['temperature']
wind_speed = data['currently']['windSpeed']
print(temp)
print(wind_speed)

# Use string interpolation to create a unnique message

####### Continue Hacking #######

# take in user input to get start date and end date

# make this a functional program

# apply to nasa apis https://api.nasa.gov/api.html#NeoWS

# Use circuit python to control leds based on weather