Пример #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)
Пример #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,
        )