Exemplo n.º 1
0
    def get_data(self):
        '''Returns the JSON file with data on images.'''
        client_id = Parser().config.get("imgur")
        if not client_id.get("client_id"):
            headers = {
                "Authorization": "Client-ID 53bdf7a3b30690b"
            }
        else:
            headers = {
                "Authorization": "Client-ID {}".format(
                    client_id.get("client_id")
                )
            }

        params = {
            "include": "media,tags,account"
        }
        match = re.match(self.valid_url, self.link)
        imgur_id = match.group('id')
        if not match.group("col"):
            url = "https://api.imgur.com/post/v1/media/{}".format(imgur_id)
        else:
            url = "https://api.imgur.com/post/v1/albums/{}".format(imgur_id)

        r = requests.get(url, headers=headers, params=params)
        if r.status_code == requests.codes.ok:
            return r.json()

        self.logger.warning("Imgur API returns a bad status code: {}".format(r.status_code))
        return None
Exemplo n.º 2
0
    def update_branding_email(self, branding_id, template, file_path):
        """
        Update the template of a branding
        """
        params = {'files': file_path}

        parser = Parser(self.TOUCH_BRANDING_PARAMS, [])
        params, files = parser.parse_data(params)

        connection = Connection(self.token)

        connection.add_files(files)
        connection.set_url(self.production, self.BRANDINGS_TEMPLATES_URL % (branding_id, 'emails', template))

        return connection.put_request()
Exemplo n.º 3
0
    def update_branding_logo(self, branding_id, file_path):
        """
        Update the logo of a branding
        """
        params = {'files': file_path}

        parser = Parser(self.TOUCH_BRANDING_PARAMS, [])
        params, files = parser.parse_data(params)

        connection = Connection(self.token)

        connection.add_files(files)
        connection.set_url(self.production, self.BRANDINGS_LOGO_URL % (branding_id, 'logo'))

        return connection.put_request()
Exemplo n.º 4
0
    def __init__(self):
        self.logger = logging.getLogger(__name__)

        parser = Parser()
        self.config = parser.config
        self.reddit = None
        self.start_reddit()
Exemplo n.º 5
0
    def update_branding(self, branding_id, params):
        """
        Update a existing branding
        @branding_id: Id of the branding to update
        @params: Same params as method create_branding, see above
        @return: A dict with updated branding data
        """
        parser = Parser(self.TOUCH_BRANDING_PARAMS, [])
        parser.validate_data(params)

        connection = Connection(self.token)

        connection.add_header('Content-Type', 'application/json')
        connection.set_url(self.production, self.BRANDINGS_ID_URL % branding_id)
        connection.add_params(params)

        return connection.patch_request()
Exemplo n.º 6
0
    def create_signature(self, files, recipients, params):
        """
        Create a new Signature request.
        @files
            Files to send
                ex: ['/documents/internet_contract.pdf', ... ]
        @recipients
            A dictionary with the email and fullname of the person you want to sign.
            If you wanna send only to one person:
               - [{"email": "*****@*****.**", "fullname": "John"}]
            For multiple recipients, yo need to submit a list of dicts:
               - [{"email": "*****@*****.**", "fullname": "John"}, {"email":"*****@*****.**", "fullname": "Bob"}]
            You can attach a phone number to each recipient, and then, the user will receive a security code in his smartphone.
               - [{"email": "*****@*****.**", "fullname": "John", "phone": "XXXX"}]
        @params: An array of params
            - subject: Subject of the email (optional)
            - body: Body of the email (optional)
            - in_person_sign: If you want to do an in person sign (system will not send an email to the user, but return the
                         sign url instead) (optional)
            - sequential: If you want to do a sequential sign (for multiple recipients, the sign goes in sequential way)
                          (optional)
            - mandatory_photo: A list of booleans that tell if photo capture will be asked to finish the signature process. (optional)
            The index of array references the document number, so first value will apply to first document.
            - mandatory_voice: A list of booleans that tell if audio recording will be asked to finish the signature process. (optional)
            The index of array references the document number, so first value will apply to first document.
            - mandatory_pages: A list of list of pages the signer must sign (optional)
            The index of array references the document number, so first value will apply to first document.
                ex: [[1, 2, 5], [1]]
            - branding_id: The id of the branding you want to use. If no branding_id, system use the account default
                           branding. (optional)
        """
        params['files'] = files
        params['recipients'] = recipients

        parser = Parser(self.CREATE_SIGN_PARAMS, [])
        params, files = parser.parse_data(params)

        connection = Connection(self.token)
        connection.set_url(self.production, self.SIGNS_URL)
        connection.add_params(params)
        connection.add_files(files)

        return connection.post_request()
Exemplo n.º 7
0
    def create_branding(self, params):
        """
        Create a new branding
        @params: An array of params (all params are optional)
            - primary: If set, this new branding will be the default one.
            - corporate_layout_color: Default color for all application widgets (hex code)
            - corporate_text_color: Default text color for all application widgets (hex code)
            - application_texts: A dict with the new text values
                - sign_button: Text for sign button
                - send_button: Text for send button
                - decline_button: Text for decline button:
                - decline_modal_title: Title for decline modal (when you click decline button)
                - decline_modal_body: Body for decline modal (when you click decline button)
                - photo: Photo message text, which tells the user that a photo is needed in the current process
                - multi_pages: Header of the document, which tells the user the number of pages to sign
                ex: { 'photo': 'Hey! Take a photo of yourself to validate the process!'}
            - subject_tag: This tag appears at the subject of all your messages
                ex: [ your_tag ] Pending document
            - reminders: A list with reminder times (in seconds). Every reminder time, a email will be sent, if the
                        signer didn't sign the document
                ex: [ 3600 ] (At 30 minutes of sending the email))
            - expire_time: The signature time (in seconds). When the expire time is over, the document cannot be signed.
                           Set 0 if you want a signature without expire time.
            - callback_url: A url to redirect the user, when the process is over.
            - events_url: A url to send system event notifications
            - signature_pos_x: Default position x of signature
            - signature_pos_y: Default position y of signature
            - terms_and_conditions_label: The terms text that appears when you need to check the button to accept.
            - terms_and_conditions_body: Custom text that appears below signature conditions

        @return: A dict with branding data
        """
        parser = Parser(self.TOUCH_BRANDING_PARAMS, [])
        parser.validate_data(params)

        connection = Connection(self.token)

        connection.add_header('Content-Type', 'application/json')
        connection.set_url(self.production, self.BRANDINGS_URL)
        connection.add_params(params, json_format=True)

        return connection.post_request()
Exemplo n.º 8
0
    def get_data(self):
        '''Returns the JSON file with data on images.'''
        imgur_cookie = Parser().config.get("imgur")
        if not imgur_cookie:
            imgur_cookie = {}
        else:
            imgur_cookie = {
                "Cookie":
                "authautologin={};".format(imgur_cookie.get("authautologin"))
            }

        page_html = self.get_html(imgur_cookie)
        if page_html:
            page_html_text = page_html.text
            data_string = re.search('image( ){15}: (?P<data>(.)+)',
                                    page_html_text)
            if data_string:
                data = data_string.group('data')[:-1]
                data = json.loads(data)
                return data
        self.logger.warning("Imgur album page returning None")
        return None
Exemplo n.º 9
0
    def create_email(self, files, recipients, subject, body, params):
        """
        Create a new certified email

        @files
             Files to send
                ex: ['/documents/internet_contract.pdf', ... ]
        @recipients
            A dictionary with the email and fullname of the person you want to sign.
            If you wanna send only to one person:
               - [{"email": "*****@*****.**", "fullname": "John"}]
            For multiple recipients, yo need to submit a list of dicts:
               - [{"email": "*****@*****.**", "fullname": "John"}, {"email":"*****@*****.**", "fullname": "Bob"}]
        @subject
            Email subject
        @body
            Email body
        @params
            Optional parameters
            send_email_event: Chooses the event that will trigger the audit trail generation
                - delivered: When email is delivered
                - seen: When app is opened (only emails with pdfs attached)
                - opened: When document is opened (only emails with pdfs attached)
        """
        params['files'] = files
        params['recipients'] = recipients
        params['subject'] = subject
        params['body'] = body

        parser = Parser(self.CREATE_EMAIL_PARAMS, [])
        params, files = parser.parse_data(params)

        connection = Connection(self.token)
        connection.set_url(self.production, self.EMAILS_URL)
        connection.add_params(params)
        connection.add_files(files)

        return connection.post_request()
Exemplo n.º 10
0
    def load_config(self):
        parser = Parser()
        data = parser.config

        try:
            int(data["media_download"]["retries"])
            int(data["media_download"]["wait_time"])
            self.retries = data["media_download"]["retries"]
            self.wait_time = data["media_download"]["wait_time"]

        except TypeError:
            self.logger.warning(
                "TypeError: Media download retries or wait time is not an integer."
            )
            self.retries = 5
            self.wait_time = 60
Exemplo n.º 11
0
def main():
    options, args = Init.parse_input()
    all_nodes = Init.validate_path(options.filepath)
    for node in all_nodes:
        hourly_breakdown, system_stats = Parser.start(all_nodes[node],
                                                      options.verbose)
        if options.json == True:
            export_json(node, hourly_breakdown, system_stats)
            print(
                f"Created '{node}-access_logs_parsed.json' in working directory"
            )
        else:
            Graph.graph_parsed(node, hourly_breakdown, system_stats,
                               options.dark_mode, options.verbose,
                               options.throttle_graph)
            combine_png_to_pdf(node)
            print(f"Created pdf of all graphs for {node} found at {node}.pdf")
Exemplo n.º 12
0
                with open(filepath) as f:
                    line = f.readline()
                    while line:
                        subR = "{}".format(line.strip())
                        feeder(subR, parser)
                        line = f.readline()
            else:
                feeder(subR, parser)
            if parser.cycles > 1:
                logger.info("Waiting {} seconds".format(parser.wait))
                time.sleep(parser.wait)
            current_cycle += 1


if __name__ == '__main__':
    parser = Parser()

    config = parser.config

    # verbose / logger
    log_path = config['general']['log_file']
    log_path = os.path.dirname(log_path)
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    if config["general"]["logger_append"]:
        filemode = 'a'
    else:
        filemode = 'w'
    if config['general']['log_timestamp']:
        now = datetime.now()
        log_path = config['general']['log_file']