Beispiel #1
0
async def notify_user():
    """ sends email to notify user of event
    """
    global notif_queue
    while True:
        logger.info("Get notification from queue, current notif count: " +
                    str(notif_queue.qsize()))
        notif = await notif_queue.get()
        send_email('*****@*****.**', decode_gmail_pass("gmail_pass.b"), notif)
Beispiel #2
0
def contact():

    if request.method == 'POST': 
        flash('you tried to make a post')
        name = request.form['name']
        email = request.form['email']
        message = request.form['message']
        send_email(to=email, subject="Contact Form", body=message)
        return redirect(url_for('login'))
    return render_template('contact.html')
Beispiel #3
0
def response_submitted(alert_id):
    """
    Action performed when a response is provided.

    Text the creator of the alert:
        - email, phone, and things able to help with of the responding user.
    """
    if request.method == 'POST':
        submitted_message = request.form['message']
        responding_user = current_user
        try:
            alert = Alert.query.get(int(alert_id))
        except Exception as e:
            return 'Error {}'.format(e), 404

        user_to_message = alert.user
        response_message = "%s" % responding_user.email
        if responding_user.phone_number:
            response_message += ", %s" % responding_user.phone_number

        response_message += " is availble for: "
        availble = {
            "shelter": responding_user.shelter,
            "clothes": responding_user.clothes,
            "food": responding_user.food,
            "other": responding_user.other,
        }
        response_message += "%s" % ", ".join(k for k, v in availble.items() if v)
        response_message += " Message: " + submitted_message

        if user_to_message.phone_number:
            send_sms(
                user_to_message.phone_number,
                response_message
            )

        send_email(
            to=user_to_message.email,
            subject="Alert Response",
            body=response_message,
        )

        Response(user=current_user, alert=alert, message=submitted_message).save()

        flash('Your response has been sent to the advocate, thank you!', 'success')
        return redirect(url_for('dashboard'))
    else:
        try:
            alert = Alert.query.get(int(alert_id))
        except Exception as e:
            return 'Error {}'.format(e), 404

        return render_template('respond_to.html', alert=alert, user=current_user, form=ResponseForm())
Beispiel #4
0
def get_log_info(log_file, rows=-150, subject='监控'):
	import os
	from email_client import send_email
	try:
		logfile = "%s/%s" % (LOG_PATH, log_file)
		os.system("sed -i /InsecurePlatformWarning/d %s" % logfile)
		os.system("sed -i /SAWarning/d %s" % logfile)
		os.system("sed -i /util.ellipses_string/d %s" % logfile)
		with open(logfile) as f:
			send_email(SUBJECT=subject, TEXT="".join(f.readlines()[rows:]))
	except Exception,e:
		pass
Beispiel #5
0
 def get(self):
     create_customer(self)  # create the database entry
     customer_id = self.get_argument('customer_id')
     email_address = self.get_argument('email_address')
     email_sent = send_email(email_address)
     enrolled = enroll(customer_id)
     self.write('OK')
     self.finish()
Beispiel #6
0
    raw_html = response.text
    jQuery = PyQuery(raw_html)
    job_list = None
    for job_css in JOB_CSS_SEARCH_LIST:
        job_list = jQuery(job_css).text()
        if job_list:
            break
    if not job_list:
        logger.info('Running job checker against: ' + SERVER_HOST +
                    ' and could not parse page')
        email_message[
            'Subject'] = "Job Checker could not parse page at: " + SERVER_HOST
        body = "Raw HTML FROM: " + SERVER_HOST + ":\n" + jQuery.html(
            method='html')
        email_message.attach(MIMEText(body, 'plain'))
        send_email(email, email_message)
    else:
        match = JOB_REGEX.search(job_list)
        email_message['Subject'] = "Jobs Available at: " + SERVER_HOST
        body = "Content Retrieved from " + SERVER_HOST + ":\n" + job_list
        email_message.attach(MIMEText(body, 'plain'))
        logger.debug('Found job_list: ' + job_list)
        if not match:
            logger.info('Jobs have appeared so sending email.')
            send_email(email, email_message)
        else:
            logger.info('Found no jobs so not sending email')
except Exception as error:
    logger.error('Found error in email process:', exc_info=True)
    email_message['Subject'] = SERVER_HOST + " Job Emailer Fault"
    exc_type, exc_value, exc_traceback = sys.exc_info()
Beispiel #7
0
        print('OmniPy\n\n'
              '--help, -h           Display this help message and exit\n'
              '--delete-config, -d  Delete configuration and exit\n')
        sys.exit()

    if arg == '--delete-config' or arg == '-d':
        Config.delete_config()
        print('Settings deleted.')
        sys.exit()

conf = Config()
title = sys.argv[1]

if argv_len > 3:
    body = sys.argv[2]
else:
    body = ''

# Check all params
if conf.ait():
    send_email(
        conf.omni_email,
        conf.from_email,
        conf.password,
        title,
        body,
        conf.smtp_adr,
        conf.smtp_port)
else:
    print('Bad config, try editing it,\nor start over by deleting by running with \'-d\' flag')
Beispiel #8
0
def dashboard():
    """Dashboard."""
    if current_user.role == 'admin':
        # Admin user, show register form
        form = RegisterForm()
        form_error = False
        deleted_user = session.pop('deleted_user', False)
        if request.method == 'POST' and form.validate_on_submit():
            user = User(
                email=form.email.data,
                password=form.password.data,
                phone_number=form.phone_number.data,
                other=form.other.data,
                shelter=form.shelter.data,
                food=form.food.data,
                clothes=form.clothes.data,
                role=form.role.data
            )
            user.save()
            verify_email(user.email)
            flash('User registered succesfully', 'success')
            return redirect(url_for('dashboard'))
        elif request.method == 'POST' and not form.validate_on_submit():
            form_error = True
        return render_template('dashboard/admin.html', 
            form=form, 
            form_error=form_error,
            users=User.get_users(),
            alerts=Alert.get_alerts(),
            delete_user_form=DeleteUserForm(),
            deleted_user=deleted_user)
    elif current_user.role == 'advocate':
        # Advocate user, show alert form
        form = AlertForm()
        if request.method == 'POST' and form.validate_on_submit():
            alert = Alert(
                description=form.description.data,
                other=form.other.data,
                shelter=form.shelter.data,
                food=form.food.data,
                clothes=form.clothes.data,
                gender=form.gender.data,
                age=form.age.data,
                user=current_user
            )
            alert.save()
            users_to_notify = User.get_provider(alert.food, alert.clothes, alert.shelter, alert.other)
            for user in users_to_notify:
                print("found user to notify {}".format(user))
                body = "There is a new 15th night alert. Go to " + \
                       HOST_NAME + \
                       "/respond_to/" + \
                       str(alert.id) + " to respond."
                send_sms(to_number=user.phone_number, body=body)
                send_email(user.email, '15th Night Alert', body)
            flash('Alert sent successfully', 'success')
            return redirect(url_for('dashboard'))

        return render_template('dashboard/advocate.html', form=form)
    else:
        # Provider user, show alerts
        return render_template(
                'dashboard/provider.html',
                user=current_user,
                alerts=Alert.get_active_alerts_for_provider(current_user)
        )
Beispiel #9
0
today = date.today()

url = ("""https://www.imdb.com/showtimes/location/{}?ref_=shlc_ref_rt_usr&
sort=moviemeter,asc&st_dt={}&mode=showtimes_grid&page=1&user_rating=7.0%2C""" .format(today, today))

r = requests.get(url)
r_html = r.text

soup = BeautifulSoup(r_html, features="html.parser")

ratings = soup.find_all("div", {"id":"user_rating"})
movies = soup.find_all("div", class_="title")
# movies = soup.find_all("div", class_="lister-item mode-grid")
# movies = soup.find_all("div", class_="lister-item-image ribbonize")

print("Movies that have an IMDb rating > 7.0 and currently showing in theaters: ")
movie_id = 0
result = "\n"
for movie_title in movies:
    if movie_title.a:
        print(movie_title.a.text.replace("\n", " ").strip(), ratings[movie_id].strong.text)
        result += movie_title.a.text.replace("\n", " ").strip() + " --- IMDb rating: "
        result += ratings[movie_id].strong.text + "\n"
    else:
        print(movie_title.contents[0].strip())
    movie_id += 1

print(result)
send_email('*****@*****.**', result, "Some movies?")
Beispiel #10
0
    sys.exit()

for arg in sys.argv[1:]:
    if arg == '--help' or arg == '-h':
        print('OmniPy\n\n'
              '--help, -h           Display this help message and exit\n'
              '--delete-config, -d  Delete configuration and exit\n')
        sys.exit()

    if arg == '--delete-config' or arg == '-d':
        Config.delete_config()
        print('Settings deleted.')
        sys.exit()

conf = Config()
title = sys.argv[1]

if argv_len > 3:
    body = sys.argv[2]
else:
    body = ''

# Check all params
if conf.ait():
    send_email(conf.omni_email, conf.from_email, conf.password, title, body,
               conf.smtp_adr, conf.smtp_port)
else:
    print(
        'Bad config, try editing it,\nor start over by deleting by running with \'-d\' flag'
    )