Пример #1
0
def linker(target, path, proto, folder, out):
    fullpath = str(folder) + "/" + str(out)
    fulllinks = str(folder) + "/links.txt"
    url = 0
    parsing = 0
    i = 0
    progress = 0
    percent = 0
    nb_lines = total_lines(folder, out)

    if os.path.exists(fullpath):
        print(status.ok(), "File found: " + fullpath)
        f = open(fullpath, 'r')
        if os.path.exists(fulllinks):
            os.remove(fulllinks)
        r = open(fulllinks, 'w+')
        print(status.st(), "Searching Urls")
        line = f.readline()
        while line:
            progress += 1
            sys.stdout.write("Found: " + colors.green() + str(url) +
                             colors.reset() + " Progress: " + colors.cyan() +
                             "%d" % percent + colors.reset() + "%")
            sys.stdout.flush()
            sys.stdout.write('\b' *
                             (7 + 11 + len(str(url)) + len(str(percent))))
            sys.stdout.flush()
            while i < len(line) - 1:
                if line[i] == '/' and line[i -
                                           1] == "\"" and line[i + 1] != '>':
                    while line[i] != "\"" and i < len(line) - 1:
                        r.write(line[i])
                        i += 1
                    r.write('\n')
                    url += 1
                if line[i] == '/' and line[i -
                                           1] == "'" and line[i + 1] != '>':
                    while line[i] != "'" and i < len(line) - 1:
                        r.write(line[i])
                        i += 1
                    r.write('\n')
                i += 1
            i = 0
            line = f.readline()
            percent = ((nb_lines / progress) * 100)
        f.close()
        r.close()
        print("Found: " + colors.green() + str(url) + colors.reset() +
              " Progress: " + colors.cyan() + "%d" % percent + colors.reset() +
              "% => '" + colors.purple() + fulllinks + colors.reset() + "'")
    else:
        print(status.ok(), "File not found: " + fullpath)
Пример #2
0
def st():
    start = colors.reset() + "[" + colors.cyan() + "----" + colors.reset(
    ) + "]"
    return (start)
Пример #3
0
def resume(posts, followers, following):
    print("%s %s: %s%s%s Posts | %s%s%s Followers | %s%s%s Following" %
          (status.info(), settings.USER, colors.cyan(), posts, colors.reset(),
           colors.cyan(), followers, colors.reset(), colors.cyan(), following,
           colors.reset()))
Пример #4
0
def template_product(product_type, templates, stdin=True, rtf=False):
    spec_template = products.specification_templates[product_type]
    if stdin:
        print "{0} a product description. Hit {1} a few times after pasting. Press {2} to continue".format(
            green('PASTE'), green('ENTER'), green('CTRL+C'))
        result = raw_input(
            "--> Ready to paste the product description? [y/n]: ")
    else:
        result = raw_input(
            "--> Ready to create a product description? [y/n]: ")
    print

    if result.lower() != 'y':
        print 'User cancelled paste. Abort'
        return 1

    if stdin:
        lines = iter_read_line()
    else:
        _buffer = 'Format specifications according to template below, delete all extra text. :wq when done:\n\n'
        _buffer += repr_dict(spec_template)
        editor_buffer = read_from_editor(start_buffer=_buffer)

    lines = editor_buffer.split('\n') if not stdin else lines
    lines = [line.strip() for line in lines
             if ':' in line]  # only keep lines with a ":" in them
    editor_lines = '\n'.join(copy.deepcopy(lines))

    data = parse_colon_lines(
        lines)  # parse the lines and reduce into a dictionary
    print data

    i = 1
    numbers = str(i) + ', '
    lformats = {}
    for template in templates:
        _is_valid, _missing_key = is_valid_data_for_template(template, data)
        if not _is_valid:
            print 'Inputted product description is missing key {0}'.format(
                red(_missing_key))
            print 'Aborting'
            return 1

        lformats[i] = lformat(template, **data)

        print '---- {0} #{1} ----'.format(cyan('Product Description'), i)
        print lformats[i]
        print
        numbers += str(i) + ', '
        i += 1

    result = raw_input(
        '{0} the {1} product description to use, or {2} to go custom: [0-9/a-z] '
        .format(cyan('Enter'), green('Number'), green('any letter')))
    if result.isdigit():
        description = lformats[int(result)]
    else:
        _buffer = 'Write a product description, generated ones are below. Delete this text when done. :wq to continue\n\n\n'
        _buffer += '\n\n'.join(
            ["#{0} {1}".format(k, v) for k, v in lformats.iteritems()])
        description_lines = read_from_editor(start_buffer=_buffer)
        description = '\n'.join(to_lines(description_lines))

    final_doc = to_rtf(
        description,
        editor_lines) if rtf else description + "\n" + "\n" + editor_lines

    print
    print '------------------ Product Description: {0} -------------------'.format(
        data['name'])
    print
    print final_doc

    result = raw_input('{0} product description+specs to {1}? [y/n] '.format(
        cyan('Send'), green('clipboard')))
    if result.lower() == 'y':
        # subprocess.call(['echo', '-e', description + '\n' + editor_lines, '|', 'pbcopy'], shell=True)
        if rtf:
            # -Prefer isn't required passing rtf formatted chars through shells and python barely works
            cmd = "bash -c 'echo \"{0}\"' | pbcopy -Prefer rtf".format(
                final_doc)
        else:
            cmd = "bash -c 'echo -e \"{0}\"' | pbcopy".format(final_doc)

        os.system(cmd)
        print 'Successfully saved to clipboard'
    return 0