コード例 #1
0
def create_md(weeks, filename):
    with open(filename, 'w') as f:
        writer = mdg.Writer(f)
        writer.write_heading('100 Pushups')
        writer.write('from ')
        writer.writeline(
            mdg.link('https://hundredpushups.com', 'hundredpushups.com'))
        writer.writeline()

        writer.write_heading('Weeks', 2)
        writer.writeline()
        for i in range(1, 7):
            writer.write('- ')
            writer.writeline(mdg.link(f'#week-{i}', f'Week {i}'))
            for j in range(1, 4):
                writer.write('  - ')
                writer.writeline(mdg.link(f'#week-{i}-day-{j}', f'Day {j}'))
        writer.writeline()
        for week in weeks:
            writer.write(week.md())
コード例 #2
0
ファイル: make_scaffold.py プロジェクト: famavott/write-me
def main():
    """Create README."""
    if os.path.isfile('README.md'):
        readme = overwrite()
    else:
        readme = 'README.md'

    with open(readme, 'w') as f:
        w = mg.Writer(f)
        w.write_heading(user_data['project_name'], 1)
        w.write_hrule()

        # Description and Key Features
        if badge:
            w.writeline(badge)
            w.writeline()
        w.writeline('Version: ' + mg.emphasis(setup_dict['version']))
        w.writeline()
        w.writeline(setup_dict['description'])
        key_features = mg.List()
        key_features.append('Feature #1')
        key_features.append('Feature #2')
        key_features.append('Feature #3')
        w.write(key_features)

        # AUTHORS
        w.write_heading('Authors', 3)
        w.write_hrule()
        authors = mg.List()
        for i in range(len(setup_dict['author'])):
            authors.append(
                mg.link(user_data['project_user_profile_url'],
                        setup_dict['author'][i]))
        w.write(authors)

        # DEPENDENCIES
        w.write_heading('Dependencies', 3)
        w.write_hrule()
        deps = mg.List()
        for dep in dependencies:
            deps.append(dep)
        w.write(deps)

        if args.verbose:
            # DOCS
            w.write_heading('Documentation', 3)
            w.write_hrule()
            w.writeline('Additional documentation can be found at: {}'.format(
                'http://write-me.readthedocs.io/en/stable/'))

            w.write_heading('Getting Started', 3)
            w.write_hrule()

        w.write_heading('Getting Started', 3)

        # GETTING STARTED: Installation requirements
        w.write_heading(mg.emphasis('Prerequisites'), 5)
        prereqs = mg.List()
        prereqs.append(
            mg.link('https://www.python.org/downloads/', 'python (3.6+)'))
        prereqs.append(mg.link('https://pip.pypa.io/en/stable/', 'pip'))
        prereqs.append(mg.link('https://git-scm.com/', 'git'))
        w.write(prereqs)

        # GETTING STARTED: Cloning/VE Instructions
        w.write_heading(mg.emphasis('Installation'), 5)
        w.writeline(
            'First, clone the project repo from Github. Then, change directories into the cloned repository. To accomplish this, execute these commands:'
        )
        w.writeline()
        w.writeline('`$ git clone {}.git`'.format(user_data['url']))
        w.writeline()
        w.writeline('`$ cd {}`'.format(user_data['project_name']))
        w.writeline()
        w.writeline(
            'Now now that you have cloned your repo and changed directories into the project, create a virtual environment named "ENV", and install the project requirements into your VE.'
        )
        w.writeline()
        w.writeline('`$ python3 -m venv ENV`')
        w.writeline()
        w.writeline('`$ source ENV/bin/activate`')
        w.writeline()
        w.writeline('`$ pip install -r requirements.txt`')

        if args.django:
            # GETTING STARTED: Serving the App (Django)
            w.write_heading(mg.emphasis('Serving Locally'), 5)
            w.writeline(serving_options['django']['instructions'])
            w.writeline(serving_options['django']['serve_command'])
            w.writeline(serving_options['django']['hosting'])

        elif args.pyramid:
            # GETTING STARTED: Serving the App (Pyramid)
            w.write_heading(mg.emphasis('Serving Locally'), 5)
            w.writeline(serving_options['pyramid']['instructions'])
            w.writeline(serving_options['pyramid']['serve_command'])
            w.writeline(serving_options['pyramid']['hosting'])

        elif args.flask:
            # GETTING STARTED: Serving the App (Flask)
            w.write_heading(mg.emphasis('Serving Locally'), 5)
            w.writeline(serving_options['flask']['instructions'])
            w.writeline(serving_options['flask']['serve_command'])
            w.writeline(serving_options['flask']['hosting'])

        # TESTS: Running & Files
        w.write_heading('Test Suite', 3)
        w.write_hrule()
        if len(test_dict.keys()) > 0:
            w.write_heading(mg.emphasis('Running Tests'), 5)
            w.writeline(
                'This application uses {} as a testing suite. To run tests, run:'
                .format(mg.link(test_options[testing_mod][0], testing_mod)))
            w.writeline()
            w.writeline('`{}`'.format(test_options[testing_mod][1]))
            w.writeline()
            w.writeline('To view test coverage, run:')
            w.writeline()
            w.writeline('`{}`'.format(test_options[testing_mod][2]))

            w.write_heading(mg.emphasis('Test Files'), 5)
            w.writeline('The testing files for this project are:')
            w.writeline()
            test_table = mg.Table()
            test_table.add_column('File Name', mg.Alignment.CENTER)
            test_table.add_column('Description', mg.Alignment.CENTER)
            for key, val in test_dict.items():
                test_table.append('`{}`'.format(key), val)
            w.write(test_table)

            # URLS - table
            if args.django or args.pyramid or args.flask:
                w.write_heading('URLs', 3)
                w.write_hrule()
                w.writeline(
                    'The URLS for this project can be found in the following modules:'
                )
                w.writeline()
                urls_table = mg.Table()
                urls_table.add_column('URL module', mg.Alignment.CENTER)
                urls_table.add_column('Description', mg.Alignment.CENTER)
                for key, val in url_dict.items():
                    urls_table.append(key, val)
                w.write(urls_table)
        else:
            w.writeline('This repository contains no tests.')

        # APPLICATIONS (Django) -v
        if args.django and args.verbose:
            w.write_heading('Django Apps', 3)
            w.write_hrule()
            models_list = mg.List()
            for model in settings_dict['INSTALLED_APPS']:
                if "django.contrib" not in model:
                    models_list.append(model)
            w.write(models_list)

        # TOOLS
        w.write_heading('Development Tools', 3)
        w.write_hrule()
        tools_list = mg.List()
        tools_list.append('{} - programming language'.format(
            mg.emphasis('python')))
        if os.path.isfile('requirements.txt'):
            with open('requirements.txt', 'r') as f:
                reqs = []
                for line in f:
                    line = line.strip()
                    reqs.append(line)
            reqs = [i.split('==')[0] for i in reqs]
            for package in reqs:
                if package.lower() in frameworks:
                    tools_list.append('{} - web framework'.format(
                        mg.emphasis(package.lower())))
                elif package.lower() in dbms:
                    tools_list.append('{} - DB management system'.format(
                        mg.emphasis(package.lower())))
                elif package.lower() in languages:
                    tools_list.append('{} - programming language'.format(
                        mg.emphasis(package.lower())))
        w.write(tools_list)

        if args.verbose:
            # CONTRIBUTIONS
            w.write_heading('Contributions', 3)
            w.write_hrule()
            w.writeline(
                'If you wish to contribute to this project, please contact {}.'
                .format(setup_dict['author_email']))

        # LICENSE
        w.write_heading('License', 3)
        w.write_hrule()
        w.writeline(license)

        # ACKNOWLEDGEMENTS
        w.write_heading('Acknowledgements', 3)
        w.write_hrule()
        shoutouts = mg.List()
        shoutouts.append('Coffee')
        w.write(shoutouts)

        w.writeline(
            mg.emphasis('This README was generated using ' + mg.link(
                'https://github.com/chelseadole/write-me', 'writeme.')))
    return """
コード例 #3
0
 def test_none_link(self):
     self.assertEqual(link(None), '')
コード例 #4
0
def main():
    """Create README."""
    if os.path.isfile('README.md'):
        readme = overwrite()
    else:
        readme = 'README.md'

    with open(readme, 'w') as f:
        w = mg.Writer(f)
        w.write_heading(user_data['project_name'], 1)
        w.write_hrule()

        # Description and Key Features
        w.write_heading('Description', 3)
        if badge:
            w.writeline(badge)
            w.writeline()
        w.writeline('Version: ' + mg.emphasis(setup_dict['version']))
        w.writeline()
        w.writeline(setup_dict['description'])
        key_features = mg.List()
        key_features.append('Feature #1')
        key_features.append('Feature #2')
        key_features.append('Feature #3')
        w.write(key_features)

        # AUTHORS
        w.write_heading('Authors', 3)
        w.write_hrule()
        authors = mg.List()
        for i in range(len(setup_dict['author'])):
            authors.append(mg.link(user_data['url'], setup_dict['author'][i]))
        w.write(authors)

        if len(dependencies) > 0:
            # DEPENDENCIES
            w.write_heading('Dependencies', 3)
            w.write_hrule()
            deps = mg.List()
            for dep in dependencies:
                deps.append(dep)
            if args.django and "django" not in dependencies:
                deps.append("Django")
            elif args.pyramid and "pyramid" not in dependencies:
                deps.append("Pyramid")
            elif args.flask and "flask" not in dependencies:
                deps.append("Flask")
            w.write(deps)

        if args.verbose:
            # DOCS
            w.write_heading('Documentation', 3)
            w.write_hrule()
            w.writeline(
                'Additional documentation can be found at: YOUR DOC SITE HERE')

        w.write_heading('Getting Started', 3)
        w.write_hrule()

        # GETTING STARTED: Installation requirements
        w.write_heading(mg.emphasis('Prerequisites'), 5)
        prereqs = mg.List()
        prereqs.append(
            mg.link('https://www.python.org/downloads/', 'python (3.6+)'))
        prereqs.append(mg.link('https://pip.pypa.io/en/stable/', 'pip'))
        prereqs.append(mg.link('https://git-scm.com/', 'git'))
        w.write(prereqs)

        # GETTING STARTED: Cloning/VE Instructions
        w.write_heading(mg.emphasis('Installation'), 5)
        w.writeline(
            'First, clone the project repo from Github. Then, change directories into the cloned repository. To accomplish this, execute these commands:'
        )
        w.writeline()
        w.writeline('`$ git clone {}.git`'.format(user_data['url']))
        w.writeline()
        w.writeline('`$ cd {}`'.format(user_data['project_name']))
        w.writeline()
        w.writeline(
            'Now now that you have cloned your repo and changed directories into the project, create a virtual environment named "ENV", and install the project requirements into your VE.'
        )
        w.writeline()
        w.writeline('`$ python3 -m venv ENV`')
        w.writeline()
        w.writeline('`$ source ENV/bin/activate`')
        w.writeline()
        w.writeline('`$ pip install -r requirements.txt`')

        if os.path.isfile('requirements.txt'):
            with open('requirements.txt', 'r') as f:
                reqs = []
                for line in f:
                    line = line.strip()
                    reqs.append(line)
            reqs = [i.split('==')[0] for i in reqs]

            if args.django and "psycopg2" in reqs:
                # Additional Django setup requirements using PostgreSQL
                w.writeline()
                w.writeline(
                    'Open PostgreSQL using the `psql` command from your Terminal.'
                )
                w.writeline(
                    'Create a PostgreSQL Database, called YOUR DBNAME HERE, using following command:'
                )
                w.writeline()
                w.writeline('`USER=# CREATE DATABASE ~YOUR DB NAME HERE~;`')
                w.writeline()
                w.writeline(
                    'Now that your database exists, you can migrate this project\'s data into it. Outside of the PostgreSQL commandline, on the same level as your `manage.py` file, run:'
                )
                w.writeline('`$ ./manage.py migrate`')
                w.writeline()

            elif args.django and "mymssql" in reqs:
                # Additional Django setup requirements using MySQL
                w.writeline()
                w.writeline(
                    'Open MySQL using the `psql` command from your Terminal, with your personal user data.'
                )
                w.writeline(
                    'Create a PostgreSQL Database, called YOUR DBNAME HERE, using following command:'
                )
                w.writeline()
                w.writeline('`USER=# CREATE DATABASE ~YOUR DB NAME HERE~;`')
                w.writeline()
                w.writeline(
                    'Now that your database exists, you can migrate this project\'s data into it. Outside of the MySQL commandline, on the same level as your `manage.py` file, run:'
                )
                w.writeline('`$ ./manage.py migrate`')
                w.writeline()

            elif args.django and "cx_Oracle" in reqs:
                # Additional Django setup requirements using Oracle
                w.writeline()
                w.writeline(
                    'Open Oracle using the `sqlplus` command from your Terminal.'
                )
                w.writeline(
                    'Create an Oracle Database, called YOUR DBNAME HERE, using following command:'
                )
                w.writeline()
                w.writeline('`USER=# CREATE DATABASE ~YOUR DB NAME HERE~;`')
                w.writeline()
                w.writeline(
                    'Now that your database exists, you can migrate this project\'s data into it. Outside of the Oracle commandline, on the same level as your `manage.py` file, run:'
                )
                w.writeline('`$ ./manage.py migrate`')
                w.writeline()

        if args.django:
            # GETTING STARTED: Serving the App (Django)
            w.write_heading(mg.emphasis('Serving Locally'), 5)
            w.writeline(serving_options['django']['instructions'])
            w.writeline(serving_options['django']['serve_command'])
            w.writeline(serving_options['django']['hosting'])

        elif args.pyramid:
            # GETTING STARTED: Serving the App (Pyramid)
            w.write_heading(mg.emphasis('Serving Locally'), 5)
            w.writeline(serving_options['pyramid']['instructions'])
            w.writeline(serving_options['pyramid']['serve_command'])
            w.writeline(serving_options['pyramid']['hosting'])

        elif args.flask:
            # GETTING STARTED: Serving the App (Flask)
            w.write_heading(mg.emphasis('Serving Locally'), 5)
            w.writeline(serving_options['flask']['instructions'])
            w.writeline(serving_options['flask']['serve_command'])
            w.writeline(serving_options['flask']['hosting'])

        # TESTS: Running & Files
        w.write_heading('Test Suite', 3)
        w.write_hrule()
        if len(test_dict.keys()) > 0:
            w.write_heading(mg.emphasis('Running Tests'), 5)
            if args.django:
                w.writeline(
                    'This is a Django application, and therefore to run tests, run the following command at the same level as `./manage.py`.'
                )
                w.writeline()
                w.writeline('`./manage.py test`')
            else:
                w.writeline(
                    'This application uses {} as a testing suite. To run tests, run:'
                    .format(mg.link(test_options[testing_mod][0],
                                    testing_mod)))
                w.writeline()
                w.writeline('`{}`'.format(test_options[testing_mod][1]))
                w.writeline()
                w.writeline('To view test coverage, run:')
                w.writeline()
                w.writeline('`{}`'.format(test_options[testing_mod][2]))

            w.write_heading(mg.emphasis('Test Files'), 5)
            w.writeline('The testing files for this project are:')
            w.writeline()
            test_table = mg.Table()
            test_table.add_column('File Name', mg.Alignment.CENTER)
            test_table.add_column('Description', mg.Alignment.CENTER)
            for key, val in test_dict.items():
                test_table.append('`{}`'.format(key), val)
            w.write(test_table)
        else:
            w.writeline('This repository contains no tests.')

        # URLS - table
        if args.django or args.pyramid or args.flask:
            w.write_heading('URLs', 3)
            w.write_hrule()
            w.writeline(
                'The URLS for this project can be found in the following modules:'
            )
            w.writeline()
            urls_table = mg.Table()
            urls_table.add_column('URL module', mg.Alignment.CENTER)
            urls_table.add_column('Description', mg.Alignment.CENTER)
            for key, val in url_dict.items():
                urls_table.append(key, val)
            w.write(urls_table)

        # APPLICATIONS (Django) -v
        if args.django and args.verbose:
            w.write_heading('Django Apps', 3)
            w.write_hrule()
            models_list = mg.List()
            for model in settings_dict['INSTALLED_APPS']:
                if "django.contrib" not in model and "storages" not in model:
                    models_list.append(model)
            w.write(models_list)

        # APPLICATIONS (Pyramid)
        if args.pyramid:
            w.write_heading('Pyramid Development Files', 3)
            w.write_hrule()
            w.writeline(
                'Development files specific to the Pyramid web framework can be found in the following files:'
            )
            pyr_table = mg.List()
            for key, val in pyramid_info.items():
                pyr_table.append(key)
            w.write(pyr_table)

        # TOOLS
        w.write_heading('Development Tools', 3)
        w.write_hrule()
        tools_list = mg.List()
        tools_list.append('{} - programming language'.format(
            mg.emphasis('python')))
        if os.path.isfile('requirements.txt'):
            with open('requirements.txt', 'r') as f:
                reqs = []
                for line in f:
                    line = line.strip()
                    reqs.append(line)
            reqs = [i.split('==')[0] for i in reqs]
            for package in reqs:
                if package.lower() in frameworks:
                    tools_list.append('{} - web framework'.format(
                        mg.emphasis(package.lower())))
                elif package.lower() in dbms:
                    tools_list.append('{} - DB management system'.format(
                        mg.emphasis(package.lower())))
        w.write(tools_list)

        if args.verbose:
            # CONTRIBUTIONS
            w.write_heading('Contributions', 3)
            w.write_hrule()
            w.writeline(
                'If you wish to contribute to this project, please contact {}.'
                .format(setup_dict['author_email']))

        # LICENSE
        w.write_heading('License', 3)
        w.write_hrule()
        w.writeline(license)

        # ACKNOWLEDGEMENTS
        w.write_heading('Acknowledgements', 3)
        w.write_hrule()
        shoutouts = mg.List()
        shoutouts.append('Coffee')
        w.write(shoutouts)

        w.writeline(
            mg.emphasis('This README was generated using ' + mg.link(
                'https://github.com/chelseadole/write-me', 'writeme.')))
    print("""

        README generated.

        User TODOs:
            * Add application highlights to bullet-point "Features" section
            * Add correct contributor Github URL links to "Authors" section
            * Populate "Acknowledgements" section

        Please review your new README, and complete any sections that require additional user input.

        """)
コード例 #5
0
 def test_valid_link_with_text(self):
     url = 'example.com'
     text = 'see example'
     self.assertEqual(link(url, text), '[{}]({})'.format(text, url))
コード例 #6
0
 def test_empty_link(self):
     self.assertEqual(link(''), '')
コード例 #7
0
 def test_valid_link_empty_text(self):
     url = 'example.com'
     self.assertEqual(link(url, ''), url)
コード例 #8
0
 def test_valid_link_none_text(self):
     url = 'example.com'
     self.assertEqual(link(url, None), url)
コード例 #9
0
 def test_valid_link(self):
     url = 'example.com'
     self.assertEqual(link(url), url)
コード例 #10
0
        unordered.append(mg.emphasis('unordered2'))
        unordered.append('unordered3')
        writer.write(unordered)

        ordered = mg.List(ordered=True)
        unordered.append('ordered1')
        unordered.append(mg.emphasis('ordered2'))
        unordered.append('ordered3')
        writer.write(ordered)

        checklist = mg.CheckList()
        checklist.append('checklist1')
        checklist.append('checklist2', True)
        writer.write(checklist)

        link = mg.link('link text', 'https://reddit.com')
        writer.writeline(link)

        image = mg.Image('https://example.com/link/to/image.png',
                         'my alt text')
        writer.writeline(image)

        code = mg.Code('Python')
        code.append("s = 'Python syntax highlighting'")
        code.append("print(s)")
        writer.write(code)

        table = mg.Table()
        table.add_column('col1')
        table.add_column('col2', mg.Alignment.CENTER)
        table.add_column('col3', 2)
コード例 #11
0
ファイル: mark_sum.py プロジェクト: filipwodnicki/mark_sum
    summarizer.stop_words = get_stop_words(LANGUAGE)

    #build a summary (list with sentences as items)
    summary = summarizer(parser.document, SENTENCES_COUNT)

    for sentence in summary:
        print(sentence)

    #Generate markdown
    with open(output_file, 'w') as f:  #Markdown-generator setup
        writer = mg.Writer(f)

        #Title and Source
        writer.write_heading(article_title)
        writer.write('Source: {}'.format(article_source))
        writer.writeline()

        #Image
        image = mg.Image(featured_image_url, article_title)
        writer.writeline(image)
        writer.writeline()

        #Summary
        for sentence in summary:
            writer.writeline(sentence)
            writer.writeline()

        #Link
        link = mg.link(str(url), 'Full text')
        writer.writeline(link)