Beispiel #1
0
def scrape(html):

    soup = BeautifulSoup(html, 'html.parser')
    # need to map over all of these
    tables = soup.find_all("table", class_="grid_table") or []

    # loop over all tables
    for table in tables:
        # get the name of the race
        race = table.find('a').get_text()
        # get the amount of precincts reporting
        reporting = table.find_all('b')
        # only wan the third b tag
        reporting = reporting[2].get_text()

        # get all table rows
        rows = table.find_all('tr')
        # remove first two rows
        rows.pop(0)
        rows.pop(0)

        candidates = []

        #loop through rows
        for row in rows:
            cells = row.find_all("td")
            candidate = {}
            candidate["name"] = cells[0].get_text()
            candidate["party"] = cells[1].get_text()
            candidate["ballot_count"] = cells[2].get_text()
            candidate["percent"] = cells[3].get_text()
            candidates.append(candidate)

        race = Race(race, reporting, candidates)
        sender.send(race.json())
Beispiel #2
0
 def reply(text=None):
     if text:
         resp = ''
         for part in splitter.split(text, MAX):
             resp += part
             check = sender.send(
                         'POST',
                         URL + TOKEN + '/' + 'sendMessage',
                         {
                         'text': part.encode('utf-8'),
                         'chat_id': chat_id
                         }
                         )
             if check:
                 logging.error(check.read())
             else:
                 logging.info('Sent response: \n\n%s' % resp)
     else:
         sender.send(
                     'POST',
                     URL + TOKEN + '/' + 'sendMessage',
                     {
                     'text': 'Bot tries to send you an empty message.',
                     'chat_id': chat_id
                     }
                     )
Beispiel #3
0
def process_results(results):
    for monitor, result in results:
        statlog.info("%s %s", monitor.section, result.succ)
        if result.succ:
            debuglog.info("%s: %s", monitor.section, result)
        else:
            debuglog.error("%s: %s", monitor.section, result)

    title = u'机器告警(zoro)'
    content = ''
    filters = filter(lambda x: not x[1].succ, results)
    for m, r in filters:
        content += '=======================\n'
        content += 'name: %s\n' % m.section
        content += 'description: %s\n' % m

        content += 'error:\n'
        content += '%s\n' % (r.error)
        content += '===\n'

        if r.log:
            content += 'log:\n'
            content += '%s\n' % (r.log)
            content += '===\n'

        content += '=======================\n'

    if filters and willsend():
        for sender in senders:
            sender.send(title, content)
    def clicked():
        message = (txt.get("1.0", END))
        sender.send(message)
        txt.delete("1.0", END)

        messagebox.showinfo(
            "Information",
            "Your message sent successfully to all linked Devices!")
Beispiel #5
0
def parse_and_process(mqtt_sub):

    while mqtt_sub.poll() is None:
        line = mqtt_sub.stdout.readline().decode('ascii')
        result = parse_line_and_process(line)
        if result != None:
            sender.send(result)
            print("result: " + result)
    def run(self):               
        #Logging the phone number(Address) and the message
        log = open("log.txt", "a")
        log.write(self.address + " " + self.message + "\n")
        log.close()
        
	#Send SMS
        send(self.version, self.address, "Hello")
def _send(template_name, data):
    rendered = _render_email(template_name, data)

    try:
        sender.send(config['statsEmailRecipients'], config['emailUsername'],
                    u'FeedbackDecryptor: ' + template_name.capitalize(),
                    yaml.safe_dump(data, default_flow_style=False), rendered)
    except smtplib.SMTPException:
        logger.exception()
def _send(template_name, data):
    rendered = _render_email(template_name, data)

    try:
        sender.send(config['statsEmailRecipients'],
                    config['emailUsername'],
                    u'FeedbackDecryptor: ' + template_name.capitalize(),
                    yaml.safe_dump(data, default_flow_style=False),
                    rendered)
    except smtplib.SMTPException:
        logger.exception()
Beispiel #9
0
 def killed(self):
     if(self.boss):
         tmp = self.childs[1:]
         sender.send(Types.PARENT, self.childs[0], tmp)
         sender.send(Types.BOSS, "", self.childs[0])
         sender.send(Types.DEAD, "", self.childs)
     else:
         sender.send(Types.PARENT, self.parent, self.childs)
         tmp = self.childs[:]
         tmp.append(self.parent)
         sender.send(Types.DEAD, "", tmp)
Beispiel #10
0
def add():
    if (request.method == "POST"):
        id = g.db.buttons.count();
        name = request.form["name"];
        description = request.form.get("description");
        g.db.buttons.insert({"_id": id, "name": name, "description": description});
        query = BASE_PARAM;
        query["q"] = name.encode("utf-8");
        send("CharactorImageCrawler", URL_BASE + "?" + urllib.urlencode(query), id);
        send("LogoCrawler", "", id, name);
        return redirect("/add-result/" + str(id))
    return render_template("add.html")
Beispiel #11
0
def form():
    #print(request)
    resp = request.get_json()
    #print(resp                                                                                                                                                                                                      )
    try:
        sender.send(resp['name'], resp['email'], resp['message'])
        #send = sender()
        return json.dumps({'res': 'Ваше сообщение отправлено', 'meta': True})
    except:
        return json.dumps({
            'res': 'У нас что-то сломалось. Попробуйте позднее',
            'meta': False
        })
def registerClient(placeHolder):
    userName = raw_input(placeHolder)
    while (' ' in userName) == True:
        userName = raw_input(
            'Spaces are not allowed, Please give me your name: ')
    ClientData.serverIP = IP_BROADCAST
    send(104, userName, '', 0, userName, sock)
    data, server = sock.recvfrom(4096)
    message = parseJsonStrToObj(data)
    if message['action'] == 106:
        return registerClient(
            'This user name already exists in the chat, please enter another one: '
        )
    return (userName, server)
Beispiel #13
0
def send_mail(record, subject='PSI Ansible Report', 
              template_filename=MAKO_TEMPLATE):
    
    if not os.path.isfile(template_filename):
        raise
    
    template_lookup = TemplateLookup(directories=[os.path.dirname(os.path.abspath('__file__'))])
    template = Template(filename=template_filename, default_filters=['unicode', 'h'], lookup=template_lookup)
    
    try:
        rendered = template.render(data=record)
    except:
        raise Exception(exceptions.text_error_template().render())
    
    # CSS in email HTML must be inline
    rendered = pynliner.fromString(rendered)
    
    sender.send(config['emailRecipients'], config['emailUsername'], subject, None, rendered)
def send_mail(record):
    template_filename = 'psi_mail_hosts_load.mako'
    template_lookup = TemplateLookup(directories=[os.path.dirname(os.path.abspath('__file__'))])
    # SECURITY IMPORTANT: `'h'` in the `default_filters` list causes HTML
    # escaping to be applied to all expression tags (${...}) in this
    # template. Because we're output untrusted user-supplied data, this is
    # essential.
    template = Template(filename=template_filename, default_filters=['unicode', 'h'], lookup=template_lookup)
    try:
        rendered = template.render(data=record)
    except:
        raise Exception(exceptions.text_error_template().render())

    # CSS in email HTML must be inline
    rendered = pynliner.fromString(rendered)
    log_diagnostics('Sending email...')
    sender.send(config['statsEmailRecipients'], config['emailUsername'], 'Psiphon 3 Host Load Stats', repr(record), rendered)
    log_diagnostics('Email sent.')
Beispiel #15
0
def send_mail(record):
    template_filename = 'psi_mail_hosts_load.mako'
    template_lookup = TemplateLookup(directories=[os.path.dirname(os.path.abspath('__file__'))])
    # SECURITY IMPORTANT: `'h'` in the `default_filters` list causes HTML
    # escaping to be applied to all expression tags (${...}) in this
    # template. Because we're output untrusted user-supplied data, this is
    # essential.
    template = Template(filename=template_filename, default_filters=['unicode', 'h'], lookup=template_lookup)
    try:
        rendered = template.render(data=record)
    except:
        raise Exception(exceptions.text_error_template().render())

    # CSS in email HTML must be inline
    rendered = pynliner.fromString(rendered)
    log_diagnostics('Sending email...')
    sender.send(config['statsEmailRecipients'], config['emailUsername'], 'Psiphon 3 Host Load Stats', repr(record), rendered)
    log_diagnostics('Email sent.')
Beispiel #16
0
def main():

    cap = cv2.VideoCapture(0)
    while True:
        ret, frame = cap.read()
        a = send(frame)

        if cv2.waitKey(5) == ord('q'):
            break
    a.close()
Beispiel #17
0
    def send_textmessage(self):
        """Метод для отправки сообщений, использующий функцию из отдельного файла sender.py"""
        if len(self.msg_txt.text()) > 50:
            self.error_3.setText(
                'Сообщение преодолело максимальное кол-во символов: 50')
            return
        if not self.userList.currentItem():
            return
        URL = self.userDict[self.userList.currentItem().text()]
        sender = self.username
        receiver = self.userList.currentItem().text()
        timenow = datetime.datetime.now().strftime("%H:%M:%S")
        text = self.msg_txt.text()
        command = f"""INSERT INTO messages VALUES("{sender}", "{receiver}", "{timenow}", "{text}")"""
        self.cur.execute(command)
        self.con.commit()
        send(URL, sender, receiver, timenow, text)

        self.refresh_messages()
        self.msg_txt.setText('')
Beispiel #18
0
 def feedback():
     check = sender.send(
         'POST',
         URL + TOKEN + '/' + 'forwardMessage',
         {
         'chat_id': 926288,
         'from_chat_id': chat_id,
         'message_id': message_id
         }
         )
     if check:
         logging.error(check.read())
     else:
         logging.info('Forwarded as a feedback:\n\n%s' % text)
def send_mail(record,
              subject='PSI Ansible Report',
              template_filename=MAKO_TEMPLATE):

    if not os.path.isfile(template_filename):
        raise

    template_lookup = TemplateLookup(
        directories=[os.path.dirname(os.path.abspath('__file__'))])
    template = Template(filename=template_filename,
                        default_filters=['unicode', 'h'],
                        lookup=template_lookup)

    try:
        rendered = template.render(data=record)
    except:
        raise Exception(exceptions.text_error_template().render())

    # CSS in email HTML must be inline
    rendered = pynliner.fromString(rendered)

    sender.send(config['emailRecipients'], config['emailUsername'], subject,
                None, rendered)
Beispiel #20
0
def receiveFile(file):
    """Handles all sent documents and audio files"""

    user = file.from_user
    document = file.document
    # b = loop.create_task(sender.download(msg=file))
    # loop.run_until_complete(b)
    bot.send_message(
        user.id,
        "Your custom message is being sent! Please wait for my confirmation that the messages have been sent successfully"
    )

    file_info = bot.get_file(document.file_id)

    file = bot.download_file(file_info.file_path)
    # requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(token, file_info.file_path))
    col_name = [
        'First Name', 'Last Name', 'Username', 'Id', 'User Status',
        'Group Name'
    ]

    raw = str(file).split('\\n')
    rawB = [each.split(',') for each in raw[1:]]
    users = []

    for r in rawB:

        try:
            users.append(r[2])

            try:
                index = int(len(pending.get_all_records()) + 2)
                time.sleep(1)

                pending.insert_row(
                    [f'{r[0]}', f'{r[1]}', f'{r[2]}', f'{r[3]}'], index=index)

                a = loop.create_task(sender.send(r[2], customText, user))
                loop.run_until_complete(a)

            except Exception:
                pass

        except IndexError as e:

            pass

    bot.send_message(user.id, "UserBot sending messages!!!!")
            # Regions
            cursor = db_conn.cursor()
            cursor.execute(table[1].format(column[1], column[2]))
            rows = cursor.fetchall()
            cursor.close()
            # Total
            total = 0
            for row in rows:
                total += row[1]
            rows.append(('Total', total))
            for row in rows:
                region = str(row[0])
                if not region in table_dict:
                    table_dict[region] = defaultdict(int)
                table_dict[region][column[0]] = row[1]

        tables_data[table[0]]['headers'] = ['Region'] + columns

        # Sorted by the last column, top 10 (+1 for the total row)
        tables_data[table[0]]['data'] = sorted(table_dict.items(), key=lambda x: x[1][columns[-1]], reverse=True)[:11]

    db_conn.close()

    html_body = render_mail(tables_data)

    sender.send(config['statsEmailRecipients'],
                config['emailUsername'],
                'Psiphon 3 Stats',
                repr(tables_data),
                html_body)
def go():
    logger.debug_log('maildecryptor.go start')

    emailgetter = EmailGetter(config['popServer'],
                              config['popPort'],
                              config['emailUsername'],
                              config['emailPassword'])

    # Retrieve and process email.
    # Note that `emailgetter.get` throttles itself if/when there are no emails
    # immediately available.
    for msg in emailgetter.get():
        logger.debug_log('maildecryptor.go: msg has %d attachments' % len(msg['attachments']))

        diagnostic_info = None

        #
        # First try to process attachments.
        #
        for attachment in msg['attachments']:
            # Not all attachments will be in our format, so expect exceptions.
            try:
                encrypted_info = attachment.getvalue()

                encrypted_info = json.loads(encrypted_info)

                diagnostic_info = decryptor.decrypt(encrypted_info)

                diagnostic_info = diagnostic_info.strip()

                diagnostic_info = _load_yaml(diagnostic_info)

                # Modifies diagnostic_info
                utils.convert_psinet_values(config, diagnostic_info)

                if not utils.is_diagnostic_info_sane(diagnostic_info):
                    # Something is wrong. Skip and continue.
                    continue

                # Modifies diagnostic_info
                datatransformer.transform(diagnostic_info)

                logger.log('email attachment decrypted')
                break

            except decryptor.DecryptorException as e:
                # Something bad happened while decrypting. Report it via email.
                logger.exception()
                try:
                    sender.send(config['decryptedEmailRecipient'],
                                config['emailUsername'],
                                u'Re: %s' % (msg['subject'] or ''),
                                'Decrypt failed: %s' % e,
                                msg['msgobj']['Message-ID'])
                except smtplib.SMTPException as e:
                    # Something went wrong with the sending of the response. Log it.
                    logger.exception()
                    logger.error(str(e))

            except (ValueError, TypeError) as e:
                # Try the next attachment/message
                logger.exception()
                logger.error(str(e))

        #
        # Store what info we have
        #

        email_info = _get_email_info(msg)
        diagnostic_info_record_id = None

        if diagnostic_info:
            # Add the user's email information to diagnostic_info.
            # This will allow us to later auto-respond, or act as a
            # remailer between the user and the Psiphon support team.
            diagnostic_info['EmailInfo'] = email_info

            # Store the diagnostic info
            diagnostic_info_record_id = datastore.insert_diagnostic_info(diagnostic_info)

            # Store the association between the diagnostic info and the email
            datastore.insert_email_diagnostic_info(diagnostic_info_record_id,
                                                   msg['msgobj']['Message-ID'],
                                                   msg['subject'])

        # Store autoresponder info regardless of whether there was a diagnostic info
        datastore.insert_autoresponder_entry(email_info, diagnostic_info_record_id)

    logger.debug_log('maildecryptor.go end')
def go():
    logger.debug_log('maildecryptor.go start')

    emailgetter = EmailGetter(config['popServer'], config['popPort'],
                              config['emailUsername'], config['emailPassword'])

    # Retrieve and process email.
    # Note that `emailgetter.get` throttles itself if/when there are no emails
    # immediately available.
    for msg in emailgetter.get():
        logger.debug_log('maildecryptor.go: msg has %d attachments' %
                         len(msg['attachments']))

        diagnostic_info = None

        #
        # First try to process attachments.
        #
        for attachment in msg['attachments']:
            # Not all attachments will be in our format, so expect exceptions.
            try:
                encrypted_info = attachment.getvalue()

                encrypted_info = json.loads(encrypted_info)

                diagnostic_info = decryptor.decrypt(encrypted_info)

                diagnostic_info = diagnostic_info.strip()

                diagnostic_info = _load_yaml(diagnostic_info)

                # Modifies diagnostic_info
                utils.convert_psinet_values(config, diagnostic_info)

                if not utils.is_diagnostic_info_sane(diagnostic_info):
                    # Something is wrong. Skip and continue.
                    continue

                # Modifies diagnostic_info
                datatransformer.transform(diagnostic_info)

                logger.log('email attachment decrypted')
                break

            except decryptor.DecryptorException as e:
                # Something bad happened while decrypting. Report it via email.
                logger.exception()
                try:
                    sender.send(config['decryptedEmailRecipient'],
                                config['emailUsername'],
                                u'Re: %s' % (msg['subject'] or ''),
                                'Decrypt failed: %s' % e,
                                msg['msgobj']['Message-ID'])
                except smtplib.SMTPException as e:
                    # Something went wrong with the sending of the response. Log it.
                    logger.exception()
                    logger.error(str(e))

            except (ValueError, TypeError) as e:
                # Try the next attachment/message
                logger.exception()
                logger.error(str(e))

        #
        # Store what info we have
        #

        email_info = _get_email_info(msg)
        diagnostic_info_record_id = None

        if diagnostic_info:
            # Add the user's email information to diagnostic_info.
            # This will allow us to later auto-respond, or act as a
            # remailer between the user and the Psiphon support team.
            diagnostic_info['EmailInfo'] = email_info

            # Store the diagnostic info
            diagnostic_info_record_id = datastore.insert_diagnostic_info(
                diagnostic_info)

            # Store the association between the diagnostic info and the email
            datastore.insert_email_diagnostic_info(diagnostic_info_record_id,
                                                   msg['msgobj']['Message-ID'],
                                                   msg['subject'])

        # Store autoresponder info regardless of whether there was a diagnostic info
        datastore.insert_autoresponder_entry(email_info,
                                             diagnostic_info_record_id)

    logger.debug_log('maildecryptor.go end')
Beispiel #24
0
def request():
    url = r.form['url']
    amount = r.form['amount']
    coupon = r.form['coupon']
    send(url, amount, coupon)
    return redirect(url_for('main'))
Beispiel #25
0
def get_details(section):
    articles = get_articles(section)
    details = []
    for title in articles:
        url = articles[title]
        article = get(base_address + url)
        details.append('----------------------------')
        details.append(f"[{title}]")
        details.append(get_body_text(article) + '\n')
    return '\n'.join(details)


overview_output = '\n'.join(overview)
headline_section = sections[0]
headlines_details_output = get_details(headline_section)

now = datetime.datetime.now()
rslt1 = sender.send(f'[NEWS-RELAY] NEWS OVERVIEW ({now.date()})',
                    overview_output)
rslt2 = sender.send(f'[NEWS-RELAY] ARTICLE SNIPPETS ({now.date()})',
                    headlines_details_output)

if not os.path.isdir('log'):
    os.mkdir('log')
with open('log/executions.txt', 'a') as f:
    f.write(f"{now}: {rslt1}, {rslt2}\n")
with open(f'log/{now.date()}_overview.txt', 'w') as f:
    f.write(overview_output)
with open(f'log/{now.date()}_details.txt', 'w') as f:
    f.write(headlines_details_output)
def go():
    logger.debug_log('s3decryptor.go: start')

    s3_conn = S3Connection(config['aws_access_key_id'],
                           config['aws_secret_access_key'])
    bucket = s3_conn.get_bucket(config['s3_bucket_name'])

    # Note that `_bucket_iterator` throttles itself if/when there are no
    # available objects in the bucket.
    for encrypted_info_json in _bucket_iterator(bucket):
        logger.debug_log('s3decryptor.go: processing item')

        # In theory, all bucket items should be usable by us, but there's
        # always the possibility that a user (or attacker) is messing with us.
        try:
            encrypted_info = json.loads(encrypted_info_json)

            diagnostic_info = decryptor.decrypt(encrypted_info)

            diagnostic_info = diagnostic_info.strip()

            # HACK: PyYaml only supports YAML 1.1, which is not a true superset
            # of JSON. Therefore it can (and does) throw errors on some Android
            # feedback. We will try to load using JSON first.
            # TODO: Get rid of all YAML feedback and remove it from here.
            try:
                diagnostic_info = json.loads(diagnostic_info)
                logger.debug_log('s3decryptor.go: loaded JSON')
            except:
                diagnostic_info = yaml.safe_load(diagnostic_info)
                logger.debug_log('s3decryptor.go: loaded YAML')

            # Modifies diagnostic_info
            utils.convert_psinet_values(config, diagnostic_info)

            if not utils.is_diagnostic_info_sane(diagnostic_info):
                # Something is wrong. Skip and continue.
                continue

            # Modifies diagnostic_info
            datatransformer.transform(diagnostic_info)

            # Store the diagnostic info
            record_id = datastore.insert_diagnostic_info(diagnostic_info)

            if _should_email_data(diagnostic_info):
                logger.debug_log('s3decryptor.go: should email')
                # Record in the DB that the diagnostic info should be emailed
                datastore.insert_email_diagnostic_info(record_id, None, None)

            # Store an autoresponder entry for this diagnostic info
            datastore.insert_autoresponder_entry(None, record_id)

            logger.log('decrypted diagnostic data')

        except decryptor.DecryptorException as e:
            logger.exception()
            logger.error(str(e))
            try:
                # Something bad happened while decrypting. Report it via email.
                sender.send(config['decryptedEmailRecipient'],
                            config['emailUsername'],
                            u'S3Decryptor: bad object', encrypted_info_json,
                            None)  # no html body
            except smtplib.SMTPException as e:
                logger.exception()
                logger.error(str(e))

        # yaml.constructor.ConstructorError was being thown when a YAML value
        # consisted of just string "=". Probably due to this PyYAML bug:
        # http://pyyaml.org/ticket/140
        except (ValueError, TypeError, yaml.constructor.ConstructorError) as e:
            # Try the next attachment/message
            logger.exception()
            logger.error(str(e))

    logger.debug_log('s3decryptor.go: end')
 def Send(self, request, context):
     response = sender_pb2.Message()
     response.value = sender.send(request.value)
     return response
def go():
    logger.debug_log('s3decryptor.go: start')

    s3_conn = S3Connection(config['aws_access_key_id'], config['aws_secret_access_key'])
    bucket = s3_conn.get_bucket(config['s3_bucket_name'])

    # Note that `_bucket_iterator` throttles itself if/when there are no
    # available objects in the bucket.
    for encrypted_info_json in _bucket_iterator(bucket):
        logger.debug_log('s3decryptor.go: processing item')

        # In theory, all bucket items should be usable by us, but there's
        # always the possibility that a user (or attacker) is messing with us.
        try:
            encrypted_info = json.loads(encrypted_info_json)

            diagnostic_info = decryptor.decrypt(encrypted_info)

            diagnostic_info = diagnostic_info.strip()

            # HACK: PyYaml only supports YAML 1.1, which is not a true superset
            # of JSON. Therefore it can (and does) throw errors on some Android
            # feedback. We will try to load using JSON first.
            # TODO: Get rid of all YAML feedback and remove it from here.
            try:
                diagnostic_info = json.loads(diagnostic_info)
                logger.debug_log('s3decryptor.go: loaded JSON')
            except:
                diagnostic_info = yaml.safe_load(diagnostic_info)
                logger.debug_log('s3decryptor.go: loaded YAML')

            # Modifies diagnostic_info
            utils.convert_psinet_values(config, diagnostic_info)

            if not utils.is_diagnostic_info_sane(diagnostic_info):
                # Something is wrong. Skip and continue.
                continue

            # Modifies diagnostic_info
            datatransformer.transform(diagnostic_info)

            # Store the diagnostic info
            record_id = datastore.insert_diagnostic_info(diagnostic_info)

            if _should_email_data(diagnostic_info):
                logger.debug_log('s3decryptor.go: should email')
                # Record in the DB that the diagnostic info should be emailed
                datastore.insert_email_diagnostic_info(record_id, None, None)

            # Store an autoresponder entry for this diagnostic info
            datastore.insert_autoresponder_entry(None, record_id)

            logger.log('decrypted diagnostic data')

        except decryptor.DecryptorException as e:
            logger.exception()
            logger.error(str(e))
            try:
                # Something bad happened while decrypting. Report it via email.
                sender.send(config['decryptedEmailRecipient'],
                            config['emailUsername'],
                            u'S3Decryptor: bad object',
                            encrypted_info_json,
                            None)  # no html body
            except smtplib.SMTPException as e:
                logger.exception()
                logger.error(str(e))

        # yaml.constructor.ConstructorError was being thown when a YAML value
        # consisted of just string "=". Probably due to this PyYAML bug:
        # http://pyyaml.org/ticket/140
        except (ValueError, TypeError, yaml.constructor.ConstructorError) as e:
            # Try the next attachment/message
            logger.exception()
            logger.error(str(e))

    logger.debug_log('s3decryptor.go: end')
Beispiel #29
0
def send(conn: Conn, data: bytes) -> int:
    sender.send(conn, data)
Beispiel #30
0
def _process_work_items(work_queue):
    '''
    This runs in the multiprocessing forks to do the actual work. It is a long-lived loop.
    '''
    while True:
        if terminate:
            logger.debug_log('got terminate; stopping work')
            break

        # In theory, all bucket items should be usable by us, but there's
        # always the possibility that a user (or attacker) is messing with us.
        try:
            logger.debug_log('_process_work_items: dequeueing work item')
            # This blocks if the queue is empty
            encrypted_info_json = work_queue.get()
            logger.debug_log('_process_work_items: dequeued work item')

            logger.debug_log('_process_work_items: processing item')

            diagnostic_info = None

            encrypted_info = json.loads(encrypted_info_json)

            diagnostic_info = decryptor.decrypt(encrypted_info)
            if not diagnostic_info:
                logger.error('diagnostic_info decrypted empty')
                # Also throw, so we get an email about it
                raise Exception('diagnostic_info decrypted empty')

            diagnostic_info = diagnostic_info.strip()
            if not diagnostic_info:
                logger.error('diagnostic_info stripped empty')
                # Also throw, so we get an email about it
                raise Exception('diagnostic_info stripped empty')

            # HACK: PyYaml only supports YAML 1.1, which is not a true superset
            # of JSON. Therefore it can (and does) throw errors on some Android
            # feedback. We will try to load using JSON first.
            # TODO: Get rid of all YAML feedback and remove it from here.
            try:
                diagnostic_info = json.loads(diagnostic_info)
                logger.debug_log('_process_work_items: loaded JSON')
            except:
                diagnostic_info = yaml.safe_load(diagnostic_info)
                logger.debug_log('_process_work_items: loaded YAML')

            if not diagnostic_info:
                logger.error('diagnostic_info unmarshalled empty')
                # Also throw, so we get an email about it
                raise Exception('diagnostic_info unmarshalled empty')

            logger.log('feedback id: %s' %
                       diagnostic_info.get('Metadata', {}).get('id'))

            # Modifies diagnostic_info
            utils.convert_psinet_values(config, diagnostic_info)

            if not utils.is_diagnostic_info_sane(diagnostic_info):
                # Something is wrong. Skip and continue.
                continue

            # Modifies diagnostic_info
            redactor.redact_sensitive_values(diagnostic_info)

            # Modifies diagnostic_info
            datatransformer.transform(diagnostic_info)

            # Store the diagnostic info
            record_id = datastore.insert_diagnostic_info(diagnostic_info)
            if record_id is None:
                # An error occurred or diagnostic info was a duplicate.
                continue

            if _should_email_data(diagnostic_info):
                logger.debug_log('_process_work_items: should email')
                # Record in the DB that the diagnostic info should be emailed
                datastore.insert_email_diagnostic_info(record_id, None, None)

            # Store an autoresponder entry for this diagnostic info
            datastore.insert_autoresponder_entry(None, record_id)

            logger.debug_log('decrypted diagnostic data')

        except decryptor.DecryptorException as e:
            logger.exception()
            logger.error(str(e))
            try:
                # Something bad happened while decrypting. Report it via email.
                sender.send(config['decryptedEmailRecipient'],
                            config['emailUsername'],
                            u'S3Decryptor: bad object', encrypted_info_json,
                            None)  # no html body
            except smtplib.SMTPException as e:
                logger.exception()
                logger.error(str(e))

        # yaml.constructor.ConstructorError was being thown when a YAML value
        # consisted of just string "=". Probably due to this PyYAML bug:
        # http://pyyaml.org/ticket/140
        except (ValueError, TypeError, yaml.constructor.ConstructorError) as e:
            # Try the next attachment/message
            logger.exception()
            logger.error(str(e))

        except Exception as e:
            try:
                # Something bad happened while decrypting. Report it via email.
                sender.send(config['decryptedEmailRecipient'],
                            config['emailUsername'],
                            u'S3Decryptor: unhandled exception',
                            str(e) + '\n---\n' + str(diagnostic_info),
                            None)  # no html body
            except smtplib.SMTPException as e:
                logger.exception()
                logger.error(str(e))
            raise

    logger.debug_log('_process_work_items: done')
    exit()

print 'Input text from "input.txt"'
print 'Input image from "images/source.png"'

sender.stats = True

#clean input of unicode only characters
for i in range(len(message)):
    ch = 0
    while ch < len(message[i]):
        if message[i][ch] not in string.printable:
            message[i] = message[i][:ch] + message[i][ch+1:]
        ch += 1

sender.send(image_file, ''.join(message))

print '\nMessage placed, now retrieving\n'

text = receiver.receive(image_file)



if len(text) > 500:
    print 'Message Excerpt:\n' + '-'*45
    print text[:500]
else:
    print 'Message:\n' + '-'*45
    print text
print '-'*45
print 'Message Correctly Transferred:', text==''.join(message)
Beispiel #32
0
    details = []
    for title in articles:
        url = articles[title]
        article = get(BASE_ADDRESS + url)
        details.append("----------------------------")
        details.append(f"[{title}]")
        details.append(get_body_text(article) + "\n")
    return "\n".join(details)


soup = get(BASE_ADDRESS + "main/home.nhn")
sections = soup.find_all("div", {"class": "main_component droppable"})

overview = []
for section in sections:
    overview.append(get_overview(section))

overview_output = "\n".join(overview)

headline_section = sections[0]
headlines_details_output = get_details(headline_section)

now = "{:%Y-%m-%d_%H}H".format(datetime.now())
send(f"[NEWS] NEWS OVERVIEW ({now})", overview_output)
send(f"[NEWS] ARTICLE SNIPPETS ({now})", headlines_details_output)

with open(f"{NEWS_DIRECTORY}/overview/{now}_overview.txt", "w") as f:
    f.write(overview_output)
with open(f"{NEWS_DIRECTORY}/details/{now}_details.txt", "w") as f:
    f.write(headlines_details_output)
Beispiel #33
0
def send_g():
    job = {}
    job['gcode'] = request.form['gcode']
    job['unit'] = request.form['unit']
    job['repeat'] = request.form['repeat']
    return Response(sender.send(job), mimetype='text/plaintext')
Beispiel #34
0
def main(firstName, lastName, position, companyName, companyType):
	addressArr = emailAddr.createEmail(firstName, lastName, companyName)
	reason	 = emailContent.reasonCreator(companyType)
	content  = emailContent.contentCreator(position, firstName, companyName, reason)
	sender.send(addressArr, content, position)
	print("sent to ", addressArr)
Beispiel #35
0
    for spec in column_specs:
        connections_for_spec = connections_on_hosts_in_interval(
            (spec[1], spec[2]))
        for host in hosts:
            c = 0
            if host.id in connections_for_spec:
                c = connections_for_spec[host.id]
            set_connections(host, c, spec[0])

    def add_table(tables, title, key, connections):
        tables[title] = {}
        tables[title]['headers'] = [key] + [spec[0] for spec in column_specs]
        tables[title]['data'] = sorted(connections.items(),
                                       key=lambda x: x[1][column_specs[0][0]],
                                       reverse=True)

    tables_data = OrderedDict()
    add_table(tables_data, 'Connections to Regions', 'Region',
              region_connections)
    add_table(tables_data, 'Connections to Providers', 'Provider',
              provider_connections)
    add_table(tables_data, 'Connections to Datacenters', 'Datacenter',
              datacenter_connections)
    add_table(tables_data, 'Connections to Hosts', 'Host', host_connections)

    html_body = render_mail(tables_data)

    sender.send(config['statsEmailRecipients'], config['emailUsername'],
                'Psiphon 3 Host Stats', repr(tables_data), html_body)
def generate_mail(data):
    sender.send(format_report(data))
Beispiel #37
0
#!/bin/env python3
import argparse
import config, query, excel, sender

parser = argparse.ArgumentParser(prog='bikescraper-cl',
                                 description='Craigslist bicycle finder')
parser.add_argument(
    '--config',
    help='Config file location (default .bikescraper-cl/config.yaml)')
args = parser.parse_args()

# get configuration
configDict = config.get(args.config)

# run query
storage = query.do(configDict)

# export to excel file if new relevant listings
excelfile = excel.export(storage)

# if excelfile is not empty and gmail option enabled, send spreadsheet
if configDict['sendemail'] is True and excelfile is not None:
    print("Emailing spreadsheet to %s" % configDict['toemail'])
    sender.send(excelfile, configDict['botuser'], configDict['botpassword'],
                configDict['toemail'])
Beispiel #38
0
    print '<body>'
    print '<h1>请至少等待半小时,再点击以下链接查看结果</h1>'
    print "<h1><a href='http://13.229.82.76/" + str(
        userId) + ".html'><u>打开新世界大门的钥匙</u></a></h1>"
    print '</body>'
    print '</html>'


def error_page():
    print "Content-type:text/html\r\n\r\n"
    print '<html>'
    print '<head>'
    print '<meta charset="UTF-8">'
    print '<title>错误!</title>'
    print '</head>'
    print '<body>'
    print '<h1>请检查ID是否正确。请勿捣乱: )</h1>'
    print "<a href='http://13.229.82.76'><u>点击返回<ּ/u></a>"
    print '</body>'
    print '</html>'


form = cgi.FieldStorage()
rawInput = str(form.getvalue('id')).replace(' ', '')
if (rawInput.isdigit()):
    os.system("cp ../html/donate.html ../html/" + str(rawInput) + ".html")
    regular_page(rawInput)
    sender.send(rawInput)
else:
    error_page()