コード例 #1
0
ファイル: servers.py プロジェクト: TheDerpySage/BB
class Reporting(object):
    def __init__(self, bot, channel_id, givenServers, givenServices):
        self.servers = givenServers
        self.services = givenServices
        #the report list keeps track of down servers already reported so we dont repeat notifications
        self.report = []
        #the channel we send notifications to
        self.channel = bot.get_channel(channel_id)
        self.emailer = Emailer(bb_config.host, bb_config.username,
                               bb_config.password)

    async def process(self):
        temp = self.report.copy()
        for x in self.servers:
            # x[name, ip]
            if bool_ping(x[1]):
                if x[0] in self.report:
                    temp.remove(x[0])
                    await self.channel.send(":white_check_mark: " + x[0] +
                                            " is back up.")
                #else still up so no need to repeat
            else:
                if x[0] not in self.report:
                    temp.append(x[0])
                    await self.channel.send(":no_entry: " + x[0] +
                                            " is unresponsive.")
                #else still unresponsive so no need to repeat
        for x in self.services:
            # x[name, ip, port]
            if bool_socket(x[1], x[2]):
                if x[0] in self.report:
                    temp.remove(x[0])
                    await self.channel.send(":white_check_mark: " + x[0] +
                                            " is back up.")
            else:
                if x[0] not in self.report:
                    temp.append(x[0])
                    await self.channel.send(":no_entry: " + x[0] + " is down.")
        # Get our differences based on our two reports
        recovered = set(self.report) - set(temp)
        died = set(temp) - set(self.report)
        # Overwrite the report
        self.report = temp
        # Notify if there's something worth reporting
        if bb_config.send_alerts_to != '':
            if recovered or died:
                body = ""
                if died:
                    body += "The following have stopped responding\n"
                    for x in died:
                        body += x.split('.')[0] + "\n"
                    body += "\n"
                if recovered:
                    body += "The following have recovered\n"
                    for x in recovered:
                        body += x.split('.')[0] + "\n"
                    body += "\n"
                body += "Please login and check running services."
                self.emailer.send_email(bb_config.send_alerts_to, 'Alert!',
                                        body)
コード例 #2
0
ファイル: crawl.py プロジェクト: ckylape/quick-cache-warmer
    protocol = os.environ.get('PROTOCOL', 'https')
    domain = os.environ.get('DOMAIN', False)

    # Send a Slack Webhook
    if webhook:
        payload = {
            'attachments': [{
                "fallback":
                subject,
                "color":
                "#36a64f",
                "pretext":
                "Quick Cache Warmer",
                "text":
                "Warmed %i pages in %i minutes on %s://%s" %
                (num_warmed, finished, protocol, domain)
            }]
        }
        r = requests.post(webhook, data=json.dumps(payload))
    else:
        # Send the Email
        try:
            emailer.send_email(html, subject, attachments)
            sys.exit(0)
        except EmailerError as e:
            print e
            sys.exit(-1)

    # safely exit
    sys.exit(0)
コード例 #3
0
from datetime import datetime as dt
import time
import requests
from emailer import Emailer
'''
The program below sends an email everyday  at 10am
With the currency rate between US Dollars and Euros
'''

e = Emailer()
while True:
    your_hour = dt.now().hour
    if your_hour == 10:
        url = 'http://127.0.0.1:5000/rate'
        conversion_info = {"FROM": "USD", "TO": "EUR"}
        try:
            r = requests.post(url, json=conversion_info)
            rate = r.json()[u'rate']
            e.connect()
            e.make_email(rate)
            e.send_email()
            e.disconnect()
        except:
            print('ERROR')
    time.sleep(3600)
コード例 #4
0
class TinderBot:
    def __init__(self):
        self.statistics = {
            'total_matches': 0,
            'swipes': 0,
            'cur_matches': 0,
            'match_rate': 0
        }
        statistics_path = 'tinder_statistics.csv'
        if os.path.exists(statistics_path):  # Get current statistics
            with open(statistics_path, newline='') as csvfile:
                csv_data = csv.reader(csvfile, delimiter=' ', quotechar='|')
                for row in csv_data:
                    self.statistics[row[0]] = float(row[1])
        else:
            open(statistics_path, 'w').close()
        self.current_matches = []
        match_ids_path = "match_ids.txt"  # Get already existing matches
        if os.path.exists(match_ids_path):
            with open(match_ids_path, 'r') as ids_file:
                for _id in ids_file:
                    self.current_matches.append(_id.rstrip("\n\r"))
        else:
            open(match_ids_path, 'w').close()
        self.account_token = config.tinder_token
        self.matches = {}
        self.last_like_at = None
        self.last_auth_at = None
        track_time = "track_time.txt"
        if os.path.exists(track_time) and os.stat(track_time).st_size != 0:
            with open(track_time, 'r') as track_f:
                for i, time in enumerate(track_f):  # this iterate only twice
                    if i == 0:
                        self.last_like_at = datetime.strptime(
                            time.split('@')[1].rstrip('\n\r'),
                            '%m/%d/%y %H:%M:%S')
                    if i == 1:
                        self.last_auth_at = datetime.strptime(
                            time.split('@')[1].rstrip('\n\r'),
                            '%m/%d/%y %H:%M:%S')
        else:
            f = open(track_time, 'w')
            f.write('last_liked@none\n')
            f.write('last_auth@none\n')
            f.close()
        self.emailer = Emailer()

    def fix_time_file(self):  # True if fixing liking time, false if auth time
        date_time = datetime.now().strftime('%m/%d/%y %H:%M:%S')
        f = open('track_time.txt', 'r')
        l = []
        for line in f:
            l.append(line.split('@'))
        f.close()
        f = open('track_time.txt', 'w')
        l[0][1] = self.last_like_at.strftime(
            '%m/%d/%y %H:%M:%S') if self.last_like_at else None
        l[1][1] = self.last_auth_at.strftime(
            '%m/%d/%y %H:%M:%S') if self.last_auth_at else None
        for line in l:
            append_to_file = line[1] if line[1] else 'none'
            f.write(line[0] + '@' + append_to_file + '\n')
        f.close()

    def isSwipeTime(self):
        if self.last_like_at:
            time_elapsed = (datetime.now() - self.last_like_at
                            )  # time as datetime object
            time_elapsed = time_elapsed.total_seconds()
            time_boundary = 21600  # 12 hours -- time to swipe again
            return (time_elapsed / time_boundary) > 1
        return True  # First iteration

    def update_statistics_file(self):
        with open('tinder_statistics.csv', 'w', newline='') as csvfile:
            writer = csv.writer(csvfile,
                                delimiter=' ',
                                quotechar='|',
                                quoting=csv.QUOTE_MINIMAL)
            for stat in self.statistics:
                writer.writerow([stat] + [self.statistics[stat]])

    def isLucasOn(self):
        try:
            requests.get(config.aws_host)
        except:
            print('LUCAS IS NOT CONNECTED')
            return False
        else:
            print('LUCAS IS CONNECTED')
            return True

    def swipe_right(self):
        LIKES_LIMIT = 45  #Tinder has a limit of 100 like per 12 hours, like 45/6 hours so we are safe.
        try:
            track_iterator = 0
            while track_iterator <= LIKES_LIMIT:
                recommendations = tinder_api.get_recs_v2()['data']['results']
                for rec in recommendations:
                    girl_id = rec['user']['_id']
                    try:
                        like_response = tinder_api.like(girl_id)
                    except:
                        print('WHATS HAPPENING')
                        return
                    print('LIKED')
                    self.statistics['swipes'] += 1
                    track_iterator += 1
                    if track_iterator == LIKES_LIMIT:  # Check if its time to stop liking
                        self.last_like_at = datetime.now()
                        self.fix_time_file()
                        self.update_statistics_file()
                        break

                    time.sleep(10)
            print('DONE LIKING')
        except:
            print('COULD NOT FINISH LIKING')

    def isNewMatch(self, match_id):
        return match_id not in self.current_matches

    def fix_id_file(self):
        open('match_ids.txt', 'w').close()
        f = open('match_ids.txt', 'a')
        for _id in self.current_matches:
            f.write(str(_id) + '\n')
        f.close()

    def onMatch(self, match):
        ## onMatch will be called always if its the first iteration, so we update self.match before check if is new match
        girl = match['person']
        bio = girl['bio'] if 'bio' in girl else ''
        self.matches[match['_id']] = {
            'name':
            girl['name'],
            'age':
            get_girls_age(datetime.now(), girl['birth_date']),
            'messages': {
                message_obj['message']: i
                for i, message_obj in enumerate(match['messages'])
            },
            'photos': [
                photo_obj['processedFiles'][0]['url']
                for photo_obj in girl['photos']
            ],  # get url for each photo of the girl
            'bio':
            bio
        }
        if self.isNewMatch(match['_id']):  ## New match!!
            self.statistics['total_matches'] += 1
            self.statistics['match_rate'] = self.statistics[
                'total_matches'] / self.statistics[
                    'swipes'] if self.statistics['swipes'] != 0 else 0
            self.update_statistics_file()
            f = open('match_ids.txt', 'a')
            f.write(str(match['_id']) + '\n')
            f.close()  # updates ids file
            self.current_matches.append(str(match['_id']))
            girl = self.matches[match['_id']]
            self.emailer.connect()  # Email Lucas about new match
            self.emailer.make_email(girl, 'match')
            self.emailer.send_email()
            self.emailer.disconnect()
            print('NEW MATCH')
            while not self.isLucasOn():
                time.sleep(10)
            try:
                url = config.aws_host + "/match"
                json_data = {"name": girl['name'], "age": str(girl['age'])}
                r = requests.post(url, json=json_data)
                response = r.json()
            except Exception as e:
                print(e)
                return {
                    "error":
                    "Something went wrong when trying to communicate with Lucas."
                }
            if bool(int(response["will_unmatch"])):  # unmatch person
                match_id = match['_id']
                self.current_matches.remove(match_id)
                self.fix_id_file()
                del self.matches[match_id]
                return tinder_api.unmatch(match_id)
            else:
                return tinder_api.send_msg(match['_id'], response['message'])

    def onNewMessage(self, new_messages, match_id):
        her_messages = get_her_messages(self.matches[match_id]['name'],
                                        new_messages)
        my_messages = get_my_messages(self.matches[match_id]['name'],
                                      new_messages)
        did_she_text_last = (her_messages[-1] == new_messages[-1]) if (
            len(her_messages) != 0) else False
        if 'WRONG HOLE' in her_messages or 'WIERD' in her_messages:  # unmatch person
            print('ARE YOU HERE FOR REAL?')
            self.current_matches.remove(match_id)
            self.fix_id_file()
            del self.matches[match_id]
            return tinder_api.unmatch(match_id)
        if 'MORE' == her_messages[-1]:
            tinder_api.send_msg(
                match_id, create_message(self.matches[match_id]['name'],
                                         "more"))
            print("MORE MESSAGE SENT")
        if did_she_text_last and AUTOMATIC_MESSAGES['YES DADDY'].rstrip(
                '\n\r'
        ) not in my_messages:  # This means that I am talking to her now
            if 'YES DADDY' in her_messages or 'LETS GO' in her_messages:
                tinder_api.send_msg(
                    match_id,
                    create_message(self.matches[match_id]['name'],
                                   "YES DADDY"))
                print("NEW DATE FOUND -- YES DADDY MESSAGE SENT")
                self.emailer.connect()  # Tell Lucas about new date
                girl = self.matches[match_id]
                self.emailer.make_email(girl, 'date')
                self.emailer.send_email()
                self.emailer.disconnect()
            else:
                tinder_api.send_msg(
                    match_id,
                    create_message(self.matches[match_id]['name'],
                                   "invalid_reply"))
                print("INVALID REPLY MESSAGE SENT")

    def update(self):
        try:
            matches = tinder_api.get_updates()['matches']
        except:
            print('COULD NOT UPDATE')
        time.sleep(1)
        self.statistics['cur_matches'] = len(matches)
        for match in matches:
            match_id = match['_id']
            if match_id not in self.matches:  # new match!
                self.onMatch(match)
            else:
                new_messages = [
                    message_obj['message'] for message_obj in match['messages']
                ]
                old_messages = self.matches[match_id]['messages']
                if self.matches[
                        match_id] and old_messages != new_messages:  # new message!
                    self.onNewMessage(new_messages, match_id)

    def isAuthTime(
            self
    ):  # Every 24 hours we need a new tinder_token to make requests
        if self.last_auth_at:
            time_elapsed = (datetime.now() - self.last_auth_at
                            )  # time as datetime object
            time_elapsed = time_elapsed.total_seconds()
            time_boundary = 86400  # 24 hours -- time to auth again
            return (time_elapsed / time_boundary) > 1
        return True  # First iteration

    def update_token(self, token):
        r = open('config.py', 'r')
        new_file = ['tinder_token = "{}"\n'.format(token)]
        for i, l in enumerate(r):
            if i != 0:
                new_file.append(l)
        r.close()
        r = open('config.py', 'w')
        for l in new_file:
            r.write(l)
        r.close()

    def handle_authentication(self):
        self.emailer.connect()  # Tell Luca to get SMS code
        self.emailer.make_alert_email()
        self.emailer.send_email()
        self.emailer.disconnect()
        while not self.isLucasOn():
            time.sleep(10)
        print("SENDING SMS...")
        log_code = sendCode(config.lucas_phone_number)
        try:
            r = requests.get(config.aws_host + '/auth_code')
        except Exception as e:
            print(e)
            print("ERROR CONNECTING WITH LUCAS")
        else:
            response = r.json()
            new_token = getToken(str(config.lucas_phone_number),
                                 str(response['sms_code']), log_code)
            self.update_token(new_token)
            time.sleep(5)
            try:
                tr = tinder_api.get_self()
                while 'error' in tr:
                    print('ERROR WITH TOKEN')
                    tell_lucas = requests.get(config.aws_host + '/failure')
                    log_code = sendCode(config.lucas_phone_number)
                    r = requests.get(config.aws_host + '/auth_code')
                    response = r.json()
                    new_token = getToken(str(config.lucas_phone_number),
                                         str(response['sms_code']), log_code)
                    self.update_token(new_token)
                    time.sleep(5)
                    tr = tinder_api.get_self()
                tell_lucas = requests.get(config.aws_host + '/success')
                print("NEW TOKEN UPDATED SUCCESSFULLY")
                self.last_auth_at = datetime.now()
                self.fix_time_file()
            except:
                print('ERROR AUTHENTICATING')
                exit()

    def run(self):
        while True:
            if self.isAuthTime():
                self.handle_authentication()
            if self.isSwipeTime():
                self.swipe_right()
            print('UPDATING')
            self.update()
            time.sleep(10)
コード例 #5
0
ファイル: main.py プロジェクト: JoshMarron/youtube-notifier
with open("video_log.txt", "a+") as f:
    already_checked = f.readlines()

# Request the videos and retrieve response in an array
requester = VideoRequest(CHANNEL_ID, PLAYLIST_ID, NUM_ITEMS)
requester.request_videos(NUM_ITEMS)
videos = requester.parse_response()

# Sort the videos with the corresponding query in the title into a new array
successes = []
for vid in videos:
    if "desired_query" in vid.title:
        successes.append(vid)

# Check that these videos have not already been notified for
for vid in successes:
    found = False
    if not already_checked:
        found = False

    for line in already_checked:
        if vid.video_id in line:
            found = True
            break

    # If the video has not already been checked, add it to the file and send an email notification
    if not found:
        mailer.send_email(vid.video_id, vid.title)
        with open("video_log.txt", "a+") as f:
            f.write(vid.video_id + " " + vid.title + '\n')
コード例 #6
0
                table += "<td>{}</td>".format(esc_field)
        table += "</tr>"

    table += "</table>"

if not errors:
    subject = "OKAY: Night Check"
    success = nc.get_okay()
    table = "<h4>The following scripts ran successfully:<h4>\n"
    table += """
        <table cellpadding='10'>
            <tr>
                <th>Execution Time</th>
                <th>Script Name</th>
            <tr>
    """
    for okay in success:
        table += """
            <tr>
                <td>{}</td>
                <td>{}</td>
            </tr>
        """.format(okay[0], okay[1])

new_email = Emailer(table, subject)
new_email.set_recipients(EMAIL_LIST)
new_email.send_email()
"""
nc.add_error("THIS IS URGENT",1);
"""
コード例 #7
0
        print(oldS3Sheet.save_data_to_sheet(buckets))
    
    elif args[1] == 'purge_instances':
        numberOfInstancesDeleted = terminate_instances(oldInstancesSheet, allInstancesSheet)
        summaryRow['EC2 Cleanup'] = 'Deleted {} instances'.format(numberOfInstancesDeleted)
        delete_stacks()

    elif args[1] == 'generate_ec2_deletion_summary':
        summaryEmail = get_old_instances_email_summary(oldInstancesSheet, allInstancesSheet, summarySheet)
        if summaryEmail is not None:
            smtp_addr = os.environ['SMTP_ADDR']
            smtp_username = os.environ['SMTP_USERNAME']
            smtp_password = os.environ['SMTP_PASSWORD']
            smtp_sender = os.environ['SMTP_SENDER']
            smtp_receivers = os.environ['SMTP_RECEIVERS'].split(',')
            emailer = Emailer(smtp_addr, smtp_username, smtp_password)
            emailer.send_email(smtp_sender, smtp_receivers, 'AWS Cleanup Notification', summaryEmail)
        skip_summary = True
    
    elif args[1] == 'purge_vpcs':
        numberOfVpcsDeleted = delete_vpcs()
        summaryRow['VPC Cleanup'] = 'Deleted {} vpcs'.format(numberOfVpcsDeleted)
        numberOfEipsDeleted = delete_unassigned_eips(get_all_eips())
        summaryRow['EC2 Cleanup'] = 'Deleted {} eips'.format(numberOfEipsDeleted)

    else:
        pass

    if not skip_summary:
        summarySheet.append_data_to_sheet([summaryRow])