예제 #1
0
    def run(self):
        location = 'Australia/Googong'
        response_astro = None
        # WundergroundSunsetSunriseThread.__start_sthread(self)
        while not GlobalSettings.WunderExitFlag:
            ctime = datetime.datetime.now().time()
            # Update at 1 am
            # if (ctime.hour == 1) or response_astro is None:
            print(self.threadID + ': Updating Weather @ ' +
                  str(datetime.datetime.now()))
            r = weather.Extract(self.api_keys['Wunderground'])
            response_astro = r.astronomy(location).data
            response_weather = r.daycast(
                location).data['simpleforecast']['forecastday'][0]
            ctime = response_astro['current_time']
            sunrise = response_astro['sunrise']
            print(self.threadID + ': Sunrise: ' + str(sunrise['hour']) + ':' +
                  str(sunrise['minute']))
            sunset = response_astro['sunset']
            print(self.threadID + ': Sunset: ' + str(sunset['hour']) + ':' +
                  str(sunset['minute']))
            day_high = float(response_weather['high']['celsius'])
            print(self.threadID + ': Temp High: ' + str(day_high) + 'C')
            day_low = float(response_weather['low']['celsius'])
            print(self.threadID + ': Temp Low: ' + str(day_low) + 'C')

            if day_high >= self.high_temp or day_high <= self.low_temp:
                if int(ctime['hour']) < int(sunrise['hour']):
                    print(self.threadID + ': Stop')
                    WundergroundSunsetSunriseThread.__stop_sthread(self)

                elif int(ctime['hour']) == int(sunset['hour']):
                    if int(ctime['minute']) >= int(sunset['minute']):
                        print(self.threadID + ': Stop')
                        WundergroundSunsetSunriseThread.__stop_sthread(self)

                elif int(ctime['hour']) > int(sunset['hour']):
                    print(self.threadID + ': Stop')
                    WundergroundSunsetSunriseThread.__stop_sthread(self)

                else:
                    print(self.threadID + ': Start')
                    WundergroundSunsetSunriseThread.__start_sthread(self)
            else:
                print(self.threadID + ': Stop')
                WundergroundSunsetSunriseThread.__stop_sthread(self)

            WundergroundSunsetSunriseThread.__sleeping(self, 30 * 60)
        print(self.threadID + ': Exiting...')
    def updateWeather(self):
        print(self.name + ': Updating Weather Service')

        r = weather.Extract(self.api)
        response_astro = r.astronomy(self.location).data
        response_weather = r.daycast(
            self.location).data['simpleforecast']['forecastday'][0]
        temp_current = float(r.today_now(self.location).data['temp_c'])

        sunrise = response_astro['sunrise']
        sunset = response_astro['sunset']
        day_high = float(response_weather['high']['celsius'])
        if temp_current > day_high:
            day_high = temp_current
        day_low = float(response_weather['low']['celsius'])
        if temp_current < day_low:
            day_low = temp_current

        print(self.name + ': Sunrise:\t' + str(sunrise['hour']) + ':' +
              str(sunrise['minute']))
        print(self.name + ': Sunset:\t' + str(sunset['hour']) + ':' +
              str(sunset['minute']))
        print(self.name + ': CurTC:\t' + str(temp_current) + 'C')
        print(self.name + ': MaxTC:\t' + str(day_high) + 'C')
        print(self.name + ': MinTC:\t' + str(day_low) + 'C')

        self.weather = \
            {
                'sunrise': sunrise,
                'sunset': sunset,
                'temp':
                    {
                        'high': day_high,
                        'low': day_low,
                        'current': temp_current
                    }
            }

        current_time = datetime.datetime.now()
        self.update_time = current_time + datetime.timedelta(minutes=30)
예제 #3
0
파일: dt.py 프로젝트: whalsey/2018-7-6_DSE
logging.debug(targets)

# merge with property data
logging.debug("READING IN 2016 PROPERTIES...")
properties = pd.read_csv("../Input/properties_2016.csv")

logging.debug("MERGING TWO DATASETS")
combined = pd.merge(targets, properties, on=['parcelid'])

logging.debug(combined.head(3).transpose())

# add weather information
import arrow  # learn more: https://python.org/pypi/arrow
from WunderWeather import weather  # learn more: https://python.org/pypi/WunderWeather

api_key = ''
extractor = weather.Extract(api_key)

for id, row in combined.iterrows():
    zip = int(row['regionidzip']).__str__()
    date = arrow.get(row['transactiondate'], "YYYY-MM-DD")

    logging.debug("{}, {}, {}".format(zip, date, date.format('YYYMMDD')))

    date_weather = extractor.date(zip, date.format('YYYYMMDD'))

    logging.debug(date_weather)

    break

# add house sales information
예제 #4
0
# Purpose: To scrape all the weather data within the given time range
# 	    and write it into a csv file
#
# command: python3 thisfile output
# output: ../../../data/weather_201507_201606.csv

from WunderWeather import weather
import arrow
import csv
from datetime import date, timedelta
import sys

KEY = '534fe8de0c6c00ce'
LOCATION = 'NY/New York'
EXTRACTOR = weather.Extract(KEY)

COLUMNS = [
    'VendorID', 'tpep_pickup_datetime', 'tpep_dropoff_datetime',
    'passenger_count', 'trip_distance', 'pickup_longitude', 'pickup_latitude',
    'RatecodeID', 'store_and_fwd_flag', 'dropoff_longitude',
    'dropoff_latitude', 'payment_type', 'fare_amount', 'extra', 'mta_tax',
    'tip_amount', 'tolls_amount', 'improvement_surcharge', 'total_amount'
]


def get_all_dates(start_y, start_m, start_d, end_y, end_m, end_d):
    '''
	Get all the date time within the given time range.

	Input:
	  int, e.g. 2017, 1, 1, 2017, 12, 31
예제 #5
0
def getCurrentTemperature(here):
	here = "MD/Hagerstown"
	extractor = weather.Extract(api_key)
	[location,current] = extractor.features(here,(('geolookup',''),('now','')))
#	return "Current Temperature in {0} is: {1}" (location.data.city,current.temp_f)
	print("Current Temperature in {0} is: {1}" (location.data.city,current.temp_f))