loading
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
import requests

for model in ["cari7", "parma"]:

  # store end point URL
  hostname = "https://cosmicrays.amentum.space/"+model+"/effective_dose"
  # requests lets you specify query string params as a dictionary, neat-o!
  payload = {
      'year' : '2019',
      'month' : '1',
      'day' : '1',
      'latitude' : '50',
      'longitude' : '50',
      'particle' : 'total',
      'altitude' : 10, # km,
      'utc' : 0
  }
  # hit the API 
  try:
    response = requests.get(hostname, params=payload)
    response.raise_for_status()
  except requests.exceptions.HTTPError as e:   
    print(response.json()['error'])
    print(e.args)

  # convert JSON in rsponse to a python dictionary
  dose_rate = response.json()["dose rate"]
  # 
  print(f"Effective dose calculated by {model} is {dose_rate['value']} {dose_rate['units']}")