コード例 #1
0
ファイル: earthquake.py プロジェクト: Jarrey/PiBBS
def __get_recent_earthquake__():
    earthquake = __read_latest_earthquake__()
    
    data = restget(EARTHQUAKE_URL, USER_AGENT)
    
    if data == "": return earthquake
    
    if data['metadata']['count'] > 0:
        feature = data['features'][0] # first record of earthquakes
        if feature["type"].upper() == "feature".upper() and (earthquake == None or feature['id'] != earthquake['id']):
            # get coordinate  and depth of earthquake
            coordinate = feature['geometry']['coordinates']
            lon = ("{:.2f} W".format(coordinate[0])) if coordinate[0] >= 0 else ("{:.2f} W".format(abs(coordinate[0])))
            lat = ("{:.2f} N".format(coordinate[1])) if coordinate[1] >= 0 else ("{:.2f} S".format(abs(coordinate[1])))
            depth = coordinate[2]
            
            earthquake = {"id": feature['id'],
                          "time": time.localtime(feature['properties']['time'] / 1000),
                          "place": feature['properties']["place"],
                          "mag": "Mag:{:.1f}".format(feature['properties']["mag"]),
                          "lat": "Lat:{:s}".format(lat),
                          "lon": "Lon:{:s}".format(lon),
                          "dep": "Dep:{:.1f} KM".format(depth)}
    
            __save_latest_earthquake__(earthquake)
            
    return earthquake
コード例 #2
0
ファイル: weather.py プロジェクト: Jarrey/PiBBS
def __get_weather__(city, days = 5):
    global WEATHER
    
    days = max(min(5, days), 1)
    url = URL.format(city, days) + APP_KEY
    current_min = time.localtime().tm_min
    if WEATHER == None or current_min % UPDATE_INTERVAL == 0:
        w = restget(url, {'Content-Type': "application/json"})
        if w == "": return WEATHER
        WEATHER = __format_weather_result__(w, city)

    return WEATHER