Exemple #1
0
def text():
    data = extractor.loadStuySite()
    schedule = extractor.getSchedule(data[1], data[2])
    bellDay = extractor.getBellDay(schedule)
    delays = MTAService.getDelays(MTAService.getSubways())
    forecast = Weather.getForecastString(Weather.getForecast())
    high = Weather.getHigh()
    low = Weather.getLow()
    now = Weather.getTemp()
    resp = twiml.Response()
    message = ""
    #---schedule---
    if bellDay == "Closed" :
        message += "School is closed."
    elif bellDay == "Weekend" :
        message += "It's a weekend."
    elif bellDay == "Unknown" :
        message += "Schedule unavailable."
    else :
        #'a' or 'an' depending on the next word:
        #B1/B2 ('a') or A1/A2/Unknown ('an')
        gymDay = extractor.getGymDay(schedule)
        #if gymDay[0] == "B" : article = "a"
        #else : article = "an"
        #"Today is %s %s day."%(article, gymDay) shortened for text
        message += "Schedule: %s. Phys. ed.: %s."%(bellDay, gymDay)
    #---weather---
        message += " Today will be %s. High: %d. Low: %d. Currently %d degrees."%(forecast, high, low, now)
    #---MTA---
    if delays :
        message += " Delays on the " + delays[0]
        #account for more than one line with delays
        if len(delays) > 1 :
            for i in xrange (len(delays)-1):
                message += ", %s"%(delays[i+1])
            message += " lines."
        else :
            message += " line."
    else :
        message += " There are no train delays!"
    resp.sms(message)
    return str(resp)
Exemple #2
0
def main():
    data = extractor.loadStuySite()
    news = extractor.getNews(data[0])
    schedule = extractor.getSchedule(data[1], data[2])
    bellDay = extractor.getBellDay(schedule)
    gymDay = extractor.getGymDay(schedule)
    date = extractor.getDate()

    temp = Weather.getTemp()
    forecastCode = Weather.getForecast()
    forecastURL = url_for("static", filename="images/" + Weather.getForecastURL(forecastCode))
    forecastString = Weather.getForecastString(forecastCode)

    delays = []  # MTAService.getDelays(MTAService.getSubways())

    # detecting a mobile device
    user_agent_string = request.user_agent.string
    mobile_user_agent_families = [
        "Firefox Mobile",
        "Opera Mobile",
        "Opera Mini",
        "Mobile Safari",
        "webOS",
        "IE Mobile",
        "Playstation Portable",
        "Nokia",
        "Blackberry",
        "Palm",
        "Silk",
        "Android",
        "Maemo",
        "Obigo",
        "Netfront",
        "AvantGo",
        "Teleca",
        "SEMC-Browser",
        "Bolt",
        "Iris",
        "UP.Browser",
        "Symphony",
        "Minimo",
        "Bunjaloo",
        "Jasmine",
        "Dolfin",
        "Polaris",
        "BREW",
        "Chrome Mobile",
        "UC Browser",
        "Tizen Browser",
    ]
    mobile_os_families = ["Windows Phone 6.5", "Windows CE", "Symbian OS", "iOS"]
    ua_family = user_agent_parser.ParseUserAgent(user_agent_string)["family"]
    os_family = user_agent_parser.ParseOS(user_agent_string)["family"]

    if ua_family in mobile_user_agent_families or os_family in mobile_os_families:
        return render_template(
            "mobile.html",
            news=news,
            schedule=schedule,
            bellDay=bellDay,
            gymDay=gymDay,
            date=date,
            temp=temp,
            forecastURL=forecastURL,
            forecastString=forecastString,
            delays=delays,
        )

    else:
        return render_template(
            "home.html",
            news=news,
            schedule=schedule,
            bellDay=bellDay,
            gymDay=gymDay,
            date=date,
            temp=temp,
            forecastURL=forecastURL,
            forecastString=forecastString,
            delays=delays,
        )
Exemple #3
0
def schedule():
    digit = request.form['Digits']
    resp = twiml.Response()
    audio = []

#---pressed 1: schedule---
    if int(digit) == 1 :
        print "1 case: schedule"
        data = extractor.loadStuySite()
        schedule = extractor.getSchedule(data[1], data[2])
        bellDay = extractor.getBellDay(schedule)
        #sentence for schedule type, plus phys. ed. cycle if applicable
        if bellDay == "Closed" :
            audio.append("Closed.mp3")
        elif bellDay == "Weekend" :
            audio.append("Closed.mp3")
        elif bellDay == "Unknown" :
            audio.append("Unknown.mp3")
        else :
            gymDay = extractor.getGymDay(schedule)
            #depends on mp3s with same names as bellDay, gymDay  options
            audio.append("%s.mp3"%(bellDay))
            audio.append("cycle.mp3")
            audio.append("cycle-%s.mp3"%(gymDay))   
         
#---pressed 2: weather---
    elif int(digit) == 2 :
        print "2 case: weather"
        forecast = Weather.getForecast()
        temp = Weather.getTemp()
        high = Weather.getHigh()
        low = Weather.getLow()
        adjectives = [20,22,23,24,25,26,27,28,29,30,31,32,33,34,36]
        nouns = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,35,37,38,39,40,41,42,43,44,45,46,47]
        #if adjective, e.g. "cold"
        #"Today it will be __"
        if forecast in adjectives:
            audio.append("adjective.mp3")
        #if noun, e.g. "thunderstorms"
        #"Today there will be __"
        elif forecast in nouns:
            audio.append("noun.mp3")
        #special cases, e.g. hurricane, have their own intros
        audio.append("weather-%d.mp3"%(forecast))        
        #"Today the high will be __ Fahrenheit."
        audio.append("high.mp3")
        #one of the number mp3s
        if high < 0 :
            audio.append("negative.mp3")
        audio.append("%d.mp3"%(abs(high)))
        audio.append("fahrenheit.mp3")
        #"and the low will be __ Fahrenheit."
        audio.append("low.mp3")
        if low < 0 :
            audio.append("negative.mp3")
        audio.append("%d.mp3"%(low))
        audio.append("fahrenheit.mp3")
        #"It is now __ Fahrenheit"
        audio.append("now.mp3")
        if temp < 0 :
            audio.append("negative.mp3")
        audio.append("%d.mp3"%(temp))
        audio.append("fahrenheit.mp3")

#---pressed 3: MTA---
    elif int(digit) == 3 :
        print "3 case: MTA"
        delays = MTAService.getDelays(MTAService.getSubways())
        if delays :
            audio.append("delays.mp3")
            for each in delays :
                for char in xrange(len(each)) :
                    audio.append("%s.mp3"%(str(each[char])))
                audio.append("line.mp3")

#---pressed 4: credits---
    elif int(digit) == 4 :
        audio.append("credits.mp3")

#---pressed another button---
    else :
        print "Not valid number. Bad user."
        #"You pressed some other number. Bad user."
        audio.append("baduser.mp3")

    #"Press any button to go back."
    audio.append("back.mp3")
    #play all queued audio, accepting any button as an interrupt
    gather = resp.gather(numDigits=1, action="/chance", timeout=10)
    for each in audio:
        url = url_for("static", filename=("audio/%s"%(each)))
        gather.play(url)
    return str(resp)