Пример #1
0
def index():
    filenames = os.listdir("src/pages")
    topics = []

    for file in filenames:
        if os.path.isdir("src/pages/" + file): # check whether the current object is a folder or not
            topics.append(file)

    t = """<ul>"""
    for topic in topics:
        topicname = topic.replace("_", " ").capitalize()
        t += f"""<li><a href="./pages/{topic}/posts.html">{topicname}</a></li>"""
    t+="</ul>"

    l = latest.latest("src/pages")
    l = f"""<a href="{l[0]}">{l[1][0]}</a>"""

    with open("src/templates/index.html", "r") as index:
        html = index.read()
        html = re.sub("\<\!\-\-Add Latest\-\-\>", l, html)
        html = re.sub("\<\!\-\-Add Topics\-\-\>", t, html)

    os.makedirs(f"build/", exist_ok=True)
    with open(f"build/index.html", "w") as f:
        f.write(html)
Пример #2
0
 def test_latest_no_number(self):
     """
     Ensure that calling the function with no arguments returns
     the single most recently-created file.
     """
     expected = [self.path + "file.new"]
     latest_file = latest.latest(path=self.path)
     self.assertEqual(latest_file, expected,)
Пример #3
0
 def testLatestWithArgs(self):
     """
     Ensure that calling the function with the arguments of 2 and some 
     directory  returns the two  most recently created files in the directory.
     """
     expected = set([self.path + "file.new", self.path + "file.bak"])
     latestFiles = set(latest.latest(2, self.path))
     self.assertEqual(latestFiles, expected)
Пример #4
0
 def test_latest_with_args(self):
     """
     Ensure that calling the function with arguments of 2 and some
     directory returns the two most recently-created files in the directory.
     """
     expected = set([self.path + "file.new", self.path + "file.bak"])
     latest_files = set(latest.latest(2, self.path))
     self.assertEqual(latest_files, expected)
Пример #5
0
 def test_latest_no_number(self):
     """
     Ensure that calling the function with no arguments 
     returns the single most recently-created file.
     """
     expected = [self.path + "file.new"]
     latest_file = latest.latest(path=self.path)
     self.assertEqual(
         latest_file,
         expected,
     )
Пример #6
0
#!/usr/bin/env python
import os
import sys

if __name__ == '__main__':
    if len(sys.argv) < 2:
        from latest import latest
        exercise = str(int(latest()) + 1)
    else:
        exercise = sys.argv[1]
    exercise = exercise.rjust(3, '0')
    dpath = os.path.join(*exercise[:-1])
    if not os.path.isdir(dpath):
        os.makedirs(dpath)

    with open(os.path.join(*exercise) + '.py', 'w') as f:
        f.write("""#!/usr/bin/env python
# https://projecteuler.net/problem={0}
# Discussion: https://projecteuler.net/thread={0}
import unittest


def answer():
    pass


def run():
    print(answer())


class Test{0}(unittest.TestCase):
Пример #7
0
def global_():
    return latest.latest()