Esempio n. 1
0
except request.exception.RequestException as err:
    logging.error('Cannot request data from CET: ' + str(err))

except twitter.error.TwitterError:
    logging.error('Cannot post CET data to Twitter: ' + str(err))

# ### DATA FROM METRO AND CPTM ### #
logging.info('Retrieving data from Metro')
try:
    metropage = requests.get(METROURL)
    metrocontent = metropage.content.decode('utf-8')
    logging.info('Parsing metro status')
    metro = Metro()
    metro.feed(metrocontent)

    lines = metro.getLines()
    update = ''
    for idx in sorted(lines.keys()):
        if lines[idx]['status'] == 'Operação Normal' or lines[idx][
                'status'] == '':
            continue
        if update != '':
            update += ', '
        update += lines[idx]['color'] + ': ' + lines[idx]['status']

    if update != '':
        update = 'Situação #MetroSP. ' + update
        logging.info('Posting situacao MetroSP: ' + update)
        api.PostUpdate(update)
        bot.broadcastUsers(update)
    else: