예제 #1
0
def load_wdata(year=[2016]):
    wpath = '/Users/nickedwards/Dropbox (Thacher)/Observatory/Weather/Data/'

    if len(year)==1:
        year = year[0]
        wdata = w.get_data(dpath=wpath,year=year)
        return wdata

    elif len(year)==2:
        start_yr = year[0]
        stop_yr = year[1]

        if stop_yr < start_yr:
            print "Fix year order, so that they are chronological"
            return []

        #write loop that can deal with year differences bigger than 2
        #np.arange(2014,2018,1)
        #Out[8]: array([2014, 2015, 2016, 2017])
        #year_duration = np.arange(start_yr,stop_yr,1)
        #data = []
        #for i in year_duration[i]:
            #data[]
        if stop_yr-start_yr > 1:
            print "Fix coming soon, please only have year increments of only 1"
            return []

        start_data = w.get_data(dpath=wpath,year=start_yr)
        stop_data = w.get_data(dpath=wpath,year=stop_yr)
        # fix dtypes
        wdata = {}
        for key in start_data.keys():
            wdata[key] = np.append(start_data[key],stop_data[key])
        return wdata

    else:
        print "Fix year amount."
        return []
예제 #2
0
 def send_weather(self, event):
     locat = self.locat.GetLineText(0)
     tw.loc(self.log, locat)
     send_text = tw.get_data(self.log, locat)
     send_phno = self.phno.GetLineText(0)
     try:
         sms.sms_send(send_phno, send_text)
     except:
         self.log.AppendText(
             'Error Occured. Check proper internet connectivity\n\nIf problem persists, we regret and please contact admin.\n'
         )
     else:
         self.log.AppendText('\nWeather succesfully sent to :' + send_phno)
     finally:
         self.log.AppendText('\n\n' + 'Buzzer v1.0'.center(50, '=') +
                             '\n\n')
예제 #3
0
def send_email():
    weather_data, icon_url = get_data('KLAX')
    file_test = "test_email.html"
    html_report(weather_data, icon_url, file_test)
    msg = MIMEMultipart('alternative')
    with open(file_test, mode='rb') as fopen:
        msg = MIMEText(fopen.read(), 'html', 'html')
    msg['Subject'] = "Hourly data"
    msg['From'] = "*****@*****.**"
    msg['TO'] = "*****@*****.**"

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login('*****@*****.**', 'test@5111998')
    server.send_message(msg)
    server.close()
예제 #4
0
import weather
import json

# 爬training 資料
for y in range(2008, 2018):
    # 跑所有個月份
    for m in range(1, 13):
        if m < 10:
            m = "0" + str(m)
            # print(m)
        weather.get_data(y, m)
        print(y, "/", m)

# 放置最終合併資料
dataset = {}
for y in range(2008, 2016):
    # 將每年一月的json檔讀取當作基準
    path = "data3/" + str(y) + "-01" + ".json"
    json_data = open(path).read()
    data = json.loads(json_data)
    # print(data["ObsTime"])

    # 依序將當年其他月份資料合併
    for m in range(2, 13):
        # 可改寫法
        if m < 10:
            m = "0" + str(m)

        path1 = "data3/" + str(y) + "-" + str(m) + ".json"
        json_data1 = open(path1).read()
        # 讀成dict
예제 #5
0
def get_data(k):

    weather.get_data(k)
users = None

with open("D:\\Code\\Demo\\userdata.csv", 'r') as f:
    users = f.readlines()

numbers = ""

for user in users:
    userdata = user.split(",") 
    name = userdata[0] 
    city = userdata[1] 
    phone = userdata[2]

    # get data from weather and thinsspeak
    data = weather.get_data(city)
    summary = thingspeak.get_thingspeak_data()

    # print(summary)
    # print(data)

    # from the msg and place the data at appropriate position.
    display_data = "\n\n Hello {name}, today's temperature in {city} is at {temp} degree Celcius and it feels like {feels_like}. " \
                        "Humidity at your field reads {humidity} and Pressure is at {pressure}. Current weather description is {description}." \
                        " {summary}".format(name= name, city = city, temp = summary['temperature'], feels_like = data['feels_like'], 
                        humidity = summary['humidity'], pressure = data['pressure'], description = data['description'], summary = summary['text'])

    print(display_data)

    #Balachandra,Bhatkal,6360239412
예제 #7
0
 def test_request_response(self):
     response = get_data(APIKEY, "Poznan")
     assert_is_not_none(response)
예제 #8
0
            0, cyl_3_av[0][time], np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan
        ]
    else:
        data_dict[float(cyl_3_av[1][time])][1] = cyl_3_av[0][time]

for time in range(len(pi_1[1])):
    if not float(pi_1[1][time]) in data_dict:
        data_dict[float(pi_1[1][time])] = [
            np.nan, np.nan, pi_1[0][time], np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan
        ]
    else:
        data_dict[float(pi_1[1][time])][2] = pi_1[0][time]

weather_data = weather.get_data()
times = weather.get_times(weather_data)
pressures = weather.get_pressures(weather_data)
rainfall = weather.get_rainfall(weather_data)
temperatures = weather.get_temperatures(weather_data)
humidity = weather.get_humidity(weather_data)
solar = weather.get_solar_irradiation(weather_data)

for time in range(len(times)):
    if not float(times[time]) in data_dict:
        data_dict[float(times[time])] = [
            np.nan, np.nan, np.nan, np.nan, pressures[time],
            temperatures[time], rainfall[time], humidity[time], solar[time]
        ]
    else:
        data_dict[float(times[time])][4] = pressures[time]
예제 #9
0
import matplotlib.pyplot as plt
import muons as mu
import numpy as np
import weather as w
import pi_muons as pi
import sys

args = map(lambda x: x.replace("-", ""), sys.argv[1:])
plot_deviation = "dev" in args

# Get weather data.
weather = w.get_data()
weather_times = w.get_times(weather)

# Get data from lab muon detectors.
muon_data = mu.get_data()
# Average in time intervals.
muon_data = mu.average_with_step(muon_data, 600 * 6)
muon_times = muon_data[0]
muon_counts = muon_data[1]

if plot_deviation:
    # Take deviation from mean
    muon_avg = np.average(muon_counts)
    muon_counts = list(map(lambda x: (x - muon_avg) / muon_avg, muon_counts))

# Get data from pidetector.
pi_muons = pi.get_counts()
pi_muons_data = pi.get_counts_in_time(pi_muons, 600 * 6)
pi_times = pi_muons_data[0]
pi_counts = pi_muons_data[1]
예제 #10
0
def _format_addr(s):
    name, addr = parseaddr(s)
    return formataddr((Header(name, 'utf-8').encode(), addr))


#from_addr=input('From:')

from_addr = '****'
#password=input('Password:'******'******'
#to_addr=input('To:')

to_addr = '******'
#smtp_server=input('SMTP server:')
smtp_server = 'smtp.163.com'

content = render_email(get_data())
msg = MIMEMultipart()
msg.attach(MIMEText(content, 'html', 'utf-8'))
msg['From'] = _format_addr('Python爱好者<%s>' % from_addr)
msg['To'] = _format_addr('儿子<%s>' % to_addr)
msg['Subject'] = Header('天气预报', 'utf-8').encode()

server = smtplib.SMTP(smtp_server, 25)
#server.starttls()
server.set_debuglevel(1)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
예제 #11
0
파일: __init__.py 프로젝트: gooofy/voxforge
def get_data(k):

    weather.get_data(k)
예제 #12
0
def write_lab_data():
    times, counts = mu.get_data(no_print=True)
    data = Data().from_counts_times(counts, times)
    associate_weather(data, w.get_data())
    data.write_to_file(file_lab)