Beispiel #1
0
def main():
    since_id = 1
    while True:
        timeOfDay = str(datetime.now())[11:16:1]
        if timeOfDay == '23:00':
            bucksGame = get_Bucks_game()
            send_tweet(bucksGame)
            time.sleep(45)
        since_id = check_mentions(since_id)
        time.sleep(2)
Beispiel #2
0
def twitter(params):

    from twitter import send_tweet

    logger.info('cli sends tweet')
    response = send_tweet(params.message, mention=params.mention)
    if response == True:
        parser.exit(status=0, message='success, tweet sent\n')
    else:
        parser.exit(status=-1, message='fail: %s\n' %(response))
Beispiel #3
0
import cv2
import time
import twitter

cam = cv2.VideoCapture(0)

while True:
    print('started')
    ret, frame = cam.read()
    if not ret:
        print("failed to grab frame")
        break

    img_name = "../images/metminiwx_sky_image_" + time.ctime() + '.png'
    img_name = img_name.replace('  ', ' ')
    img_name = img_name.replace(' ', '_')
    img_name = img_name.replace(':', '_')
    cv2.imwrite(img_name, frame)
    print("{} written to disk".format(img_name))

    # Tweet the picture
    tweet = 'TESTING : View of sky'
    status = twitter.send_tweet(tweet, hashtags=None, image_pathname=img_name)

    mins = 60  # 1 hour between images
    sleep_secs = mins * 60
    print(time.ctime() + ' sleeping...')
    time.sleep(sleep_secs)

cam.release()
Beispiel #4
0
def data_handler():
    import_data()
    liste_objet = dict()
    with open('declarations-exterminations-punaises-de-lit.csv',
              newline='') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quoting=csv.QUOTE_NONE)
        next(reader, None)  # skip the headers
        for row in reader:
            # recuperation des variables
            no_declaration = row[0].strip('"') if len(
                row[0].strip('"')) != 0 else "N/A"
            date_declaration = row[1].strip('"') if len(
                row[1].strip('"')) != 0 else "N/A"
            date_insp_vispre = row[2].strip('"') if len(
                row[2].strip('"')) != 0 else "N/A"
            nbr_extermin = row[3].strip('"') if len(
                row[3].strip('"')) != 0 else "N/A"
            date_debuttrait = row[4].strip('"') if len(
                row[4].strip('"')) != 0 else "N/A"
            date_fintrait = row[5].strip('"') if len(
                row[5].strip('"')) != 0 else "N/A"
            no_qr = row[6].strip('"') if len(row[6].strip('"')) != 0 else "N/A"
            nom_qr = row[7].strip('"') if len(
                row[7].strip('"')) != 0 else "N/A"
            nom_arrond = row[8].strip('"') if len(
                row[8].strip('"')) != 0 else "N/A"
            coord_x = row[9].strip('"') if len(
                row[9].strip('"')) != 0 else "N/A"
            coord_y = row[10].strip('"') if len(
                row[10].strip('"')) != 0 else "N/A"
            longitude = row[11].strip('"') if len(
                row[11].strip('"')) != 0 else "N/A"
            latitude = row[12].strip('"') if len(
                row[12].strip('"')) != 0 else "N/A"

            # Pour éviter les duplications
            check_db = db.session.query(Declarations).filter_by(
                no_declaration=no_declaration,
                date_declaration=date_declaration,
                date_insp_vispre=date_insp_vispre,
                nbr_extermin=nbr_extermin,
                date_debuttrait=date_debuttrait,
                date_fintrait=date_fintrait,
                no_qr=no_qr,
                nom_qr=nom_qr,
                nom_arrond=nom_arrond,
                coord_x=coord_x,
                coord_y=coord_y,
                longitude=longitude,
                latitude=latitude).all()
            if len(check_db) == 0:
                declaration = Declarations(no_declaration=no_declaration,
                                           date_declaration=date_declaration,
                                           date_insp_vispre=date_insp_vispre,
                                           nbr_extermin=nbr_extermin,
                                           date_debuttrait=date_debuttrait,
                                           date_fintrait=date_fintrait,
                                           no_qr=no_qr,
                                           nom_qr=nom_qr,
                                           nom_arrond=nom_arrond,
                                           coord_x=coord_x,
                                           coord_y=coord_y,
                                           longitude=longitude,
                                           latitude=latitude,
                                           affichable=True)
                if nom_qr not in liste_objet:
                    liste_objet[nom_qr] = list()
                liste_objet[nom_qr].append(declaration)
                db.session.add(declaration)
                db.session.commit()
            else:
                print("Doublon")
                pass
    csvfile.close()
    os.remove("declarations-exterminations-punaises-de-lit.csv")
    if liste_objet is not None:
        send_mail(liste_objet)
        send_tweet(liste_objet)
Beispiel #5
0
    send_mail(['*****@*****.**'], test_message, subject='test')

    logger.info('Sending new mail with all parameters')
    send_mail(
        ['*****@*****.**', '*****@*****.**'],
        'Have fun with the readme!',
        subject='mail to many recipients',
        subjecttag='Information',
        subjectdate=True,
        cc=['*****@*****.**', '*****@*****.**'],
        bcc=['*****@*****.**'],
        sender='Sample User <*****@*****.**>',
        footer='Fnord Industries 2000\nSky\'s-the-limit-lane 23\n23425 Fnord',
        files=['README.markdown']
        )

    logger.info('Sending new test aspsms')
    send_aspsms(['00991234567890'], test_message)

    logger.info('Sending new aspsms with all parameters')
    send_aspsms(
        ['00991234567890', '00119876543210'],
        'This is a very important message',
        originator='SampleUser',
        flashing=True,
        maxchars=320
        )

    logger.info('Sending new test tweet')
    send_tweet(test_message, mention=['mossfromIT'])
Beispiel #6
0
def update_forecasts(julian_day, forecast_hour_utc, met_source):
    query = {}
    container_version = predictord_funcs.get_version()

    try:
        for place in locations.locations:
            #print("===========================================================")
            print("Location : " + place['location'])

            lat, lon, pressure, ptrend, wind_deg, wind_quadrant, wind_strength, temp_avg, rain_avg, snow_avg, humidity_avg, dew_point_avg, slope , last_weather_description, last_record_id , last_record_timestamp = \
                get_forecast_prereqs(place['location'], julian_day, forecast_hour_utc, met_source)

            if lat is None:
                print('Unable to retrieve data for ' + place['location'])
                continue

            query['pressure'] = pressure
            query['trend_str'] = ptrend
            query['wind_deg'] = wind_deg

            status_code, response_dict = call_rest_api.call_rest_api(
                definitions.endpoint_base + '/get_forecast_hughes38', query)

            if status_code != 200:
                raise

            hughes38_forecast_text = response_dict['forecast_text']
            hughes38_forecast_id = response_dict['forecast_id']

            zambretti_forecast_text = 'NOT_IMPLEMENTED'
            zambretti_forecast_id = '0'  # 0 is not a valid Zambretti id

            metmini_forecast_text = 'NOT_IMPLEMENTED'
            metmini_forecast_id = -1

            api_forecast_text = 'NOT_IMPLEMENTED'  # e.g. forecast from a Weather API

            full_forecast_txt = "MetMini Forecast\n"
            full_forecast_txt += "----------------\n"
            full_forecast_txt += time.ctime() + "\n"
            full_forecast_txt += "Location  : " + place['location'] + "\n"
            full_forecast_txt += "Latitude  : " + lat.__str__() + "\n"
            full_forecast_txt += "Longitude : " + lon.__str__() + "\n"
            full_forecast_txt += "Meteorological data source : " + met_source + "\n"
            full_forecast_txt += "Hughes38  forecast for next 12 hours : " + hughes38_forecast_text + "\n"
            full_forecast_txt += "Hughes38  forecast id : " + hughes38_forecast_id.__str__(
            ) + "\n"
            full_forecast_txt += "Zambretti forecast for next 12 hours : " + zambretti_forecast_text + "\n"
            full_forecast_txt += "Zambretti forecast id : " + zambretti_forecast_id.__str__(
            ) + "\n"
            full_forecast_txt += "MetMini forecast for next 12 hours : " + metmini_forecast_text + "\n"
            full_forecast_txt += "MetMini forecast id : " + metmini_forecast_id.__str__(
            ) + "\n"
            full_forecast_txt += "API forecast for next 12 hours : " + api_forecast_text + "\n"
            full_forecast_txt += "{"
            full_forecast_txt += "pressure=" + pressure.__str__(
            ) + " mbar (ptrend=" + ptrend + ")"
            full_forecast_txt += ", wind_deg=" + wind_deg.__str__()
            full_forecast_txt += ", wind_quadrant=" + wind_quadrant.__str__()
            full_forecast_txt += ", wind_strength=F" + wind_strength.__str__()
            full_forecast_txt += ", pressure_slope=" + slope.__str__()
            full_forecast_txt += ", last_record_id=" + last_record_id.__str__()
            full_forecast_txt += "}"
            full_forecast_txt += "\n"
            full_forecast_txt += "["
            full_forecast_txt += "temp_avg=" + temp_avg.__str__()
            full_forecast_txt += ", dew_point_avg=" + dew_point_avg.__str__()
            full_forecast_txt += ", humidity_avg=" + humidity_avg.__str__()
            full_forecast_txt += ", rain_avg=" + rain_avg.__str__()
            full_forecast_txt += ", snow_avg=" + snow_avg.__str__()
            full_forecast_txt += ", last_weather_description=" + last_weather_description.__str__(
            )
            full_forecast_txt += "]"

            #print("------------------------------------------------")
            #print(full_forecast_txt)
            #print("------------------------------------------------")

            add_forecast_to_db(julian_day, place['location'], lat, lon,
                               pressure, ptrend, wind_deg, wind_quadrant,
                               wind_strength, temp_avg, rain_avg, snow_avg,
                               humidity_avg, dew_point_avg, slope, met_source,
                               last_weather_description, last_record_id,
                               hughes38_forecast_text, hughes38_forecast_id,
                               zambretti_forecast_text, zambretti_forecast_id,
                               metmini_forecast_text, metmini_forecast_id,
                               api_forecast_text, last_record_timestamp,
                               container_version)

            # only Tweet out my local forecast
            if place['location'] == "Stockcross, UK":
                tweet = '12-14 hour forecast for ' + place[
                    'location'] + ' is ' + hughes38_forecast_text.lower()
                print('Tweet = ' + tweet)
                twitter.send_tweet(tweet, lat, lon)

    except Exception as e:
        print("update_forecasts() : error : " + e.__str__())