Skip to content

Commit

Permalink
Merge pull request #495 from bsekiewicz/patch-1
Browse files Browse the repository at this point in the history
transparent list of projects #493
  • Loading branch information
jpmckinney authored Sep 25, 2023
2 parents 613c796 + 4ae46f4 commit 77832e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions scrapyd/tests/test_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def test_render_home(self, txrequest, site_no_egg):
content = site_no_egg.children[b''].render_GET(txrequest)
expect_headers = {
b'Content-Type': [b'text/html; charset=utf-8'],
b'Content-Length': [b'704'],
b'Content-Length': [b'714'],
}
if site_no_egg.local_items:
expect_headers[b'Content-Length'] = [b'740']
expect_headers[b'Content-Length'] = [b'751']

headers = dict(txrequest.responseHeaders.getAllRawHeaders())

Expand Down
18 changes: 12 additions & 6 deletions scrapyd/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,31 @@ def __init__(self, root, local_items):

def render_GET(self, txrequest):
vars = {
'projects': ', '.join(self.root.scheduler.list_projects()),
'base_path': self.get_base_path(txrequest),
}
s = """
s = """\
<html>
<head><title>Scrapyd</title></head>
<body>
<h1>Scrapyd</h1>
<p>Available projects: <b>%(projects)s</b></p>
<ul>
<li><a href="%(base_path)s/jobs">Jobs</a></li>
"""
if self.local_items:
s += '<li><a href="%(base_path)s/items/">Items</a></li>'
s += """
s += '<li><a href="%(base_path)s/items/">Items</a></li>\n'
s += """\
<li><a href="%(base_path)s/logs/">Logs</a></li>
<li><a href="https://scrapyd.readthedocs.io/en/latest/">Documentation</a></li>
</ul>
""" % vars
if self.root.scheduler.list_projects():
s += '<p>Available projects:<p>\n<ul>\n'
for project_name in sorted(self.root.scheduler.list_projects()):
s += f'<li>{project_name}</li>\n'
s += '</ul>\n'
else:
s += '<p>No projects available.</p>\n'
s += """
<h2>How to schedule a spider?</h2>
<p>To schedule a spider you need to use the API (this web UI is only for
Expand Down

0 comments on commit 77832e6

Please sign in to comment.