Example #1
0
    def refresh(self):
        conn = datapoint.Manager(api_key="put key here")
        site = conn.get_nearest_site(-0.0005, 51.4769)
#        print site.name, site.id
        
        forecast = conn.get_forecast_for_site(site.id, "3hourly")
        self.current = forecast.now()
Example #2
0
def regional_forecast_view(request, region_id):
    #
    # To do - add some error checking...
    #
    conn = datapoint.Manager(api_key=settings.DATAPOINT_API)
    regions = conn.regions.get_all_regions()
    region_name = ''
    #maybe a better way of searching...
    for region in regions:
        if region.id == str(region_id):
            region_name = region.name
            break

    Forecast_section = namedtuple('Forecast_section', 'head text')
    forecast_sections = []

    forecast = conn.regions.get_raw_forecast(region_id)['RegionalFcst']
    # Issued date is a string with 'T' delimiting time
    issued_str = forecast['issuedAt']
    fd, ft = issued_str.split('T')
    issued = datetime.strptime((fd + ' ' + ft), '%Y-%m-%d %H:%M:%S')

    sections = forecast['FcstPeriods']['Period']
    #breakpoint()
    for section in forecast['FcstPeriods']['Period']:
        paragraph = []
        content = section['Paragraph']
        # deal with paragraphs containing multiple sections
        if isinstance(content, dict):
            paragraph.append(content)
        else:
            paragraph = content

        #breakpoint()

        for line in paragraph:
            #breakpoint()

            fs = Forecast_section(line['title'], line['$'])
            forecast_sections.append(fs)

            #text = text + ('{}\n{}\n'.format(line['title'], line['$']))

    #breakpoint()

    return render(request, 'weather/forecast/full.html', {
        'forecast': forecast_sections,
        'region': region_name,
        'issued': issued,
    })
#!/usr/bin/env python
"""
A variation on current_weather.py which uses postcodes rather than lon lat.
"""

import datapoint
import postcodes_io_api

# Create datapoint connection
conn = datapoint.Manager(api_key="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")

# Get longitude and latitude from postcode
postcodes_conn = postcodes_io_api.Api()
postcode = postcodes_conn.get_postcode('SW1A 2AA')
latitude = postcode['result']['latitude']
longitude = postcode['result']['longitude']

# Get nearest site and print out its name
site = conn.get_nearest_forecast_site(latitude, longitude)
print(site.name)

# Get a forecast for the nearest site
forecast = conn.get_forecast_for_site(site.location_id, "3hourly")

# Get the current timestep using now() and print out some info
now = forecast.now()
print(now.weather.text)
print("%s%s%s" % (
    now.temperature.value,
    '\xb0',  #Unicode character for degree symbol
    now.temperature.units))
Example #4
0
 def __init__(self):
     self.manager = datapoint.Manager(api_key=os.environ['API_KEY'])
     self.regions = self.manager.regions
Example #5
0
 def __init__(self):
     self.manager = datapoint.Manager(api_key="")
 def setUp(self):
     self.manager = datapoint.Manager(api_key=os.environ['API_KEY'])
 def setUp(self):
     self.manager = datapoint.Manager(api_key="")
Example #8
0
    # Get the current timestep from the forecast
    current_timestep = forecast.now()
    msg_txt = str(current_timestep.temperature.value) +" "+ current_timestep.temperature.units
    cbmessage = codebug_tether.sprites.StringSprite(msg_txt)
    print(current_timestep.temperature.value,current_timestep.temperature.units)
    for i in range(0,-70,-1):
      cb.draw_sprite(i, 0, cbmessage)
      time.sleep(0.25)
#___________________________________________________________
# Main program starts here

# Get a connection to CodeBug
cb = codebug_tether.CodeBug()
 
# Create connection to DataPoint with your API key
conn = datapoint.Manager(api_key="a3447661-0e61-4826-b59d-2cd1a9a613c2")

# Get longitude and latitude from postcode
postcodes_conn = postcodes_io_api.Api()
postcode = postcodes_conn.get_postcode('SK8 1ES')
latitude = postcode['result']['latitude']
longitude = postcode['result']['longitude']

# Get the nearest site for my latitude and longitude
site = conn.get_nearest_forecast_site(latitude, longitude)
print(site.name)

while True:
    if cb.get_input('A') == 1:
        show_forecast(conn, cb, site)
    cb.clear()