-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateLocalReport.py
More file actions
72 lines (62 loc) · 2.24 KB
/
createLocalReport.py
File metadata and controls
72 lines (62 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from createSubReport import createSubReport
from bs4 import BeautifulSoup
import requests
import sys
# Testing if a file path was given
if len(sys.argv) > 2:
path = sys.argv[2]
path = path.replace('\\', '/') + '/'
else:
path = ""
html = requests.get(sys.argv[1])
soup = BeautifulSoup(html.content, features="lxml")
subReportUrls = soup.find('table').find_all('a')
# Extracting the number of lines matched in each comparison
numLinesMatched = soup.find('table').find_all('td', {'align': 'right'})
# Extracting report date and options
headerInfo = soup.find_all('p')
date = headerInfo[0].contents[0]
options = headerInfo[1].contents[0]
reportHTMLTop = f"""
<!DOCTYPE html>
<html>
<head>
<title> Moss Results </title>
</head>
<body>
Moss Results
<p> {date} </p>
<p> {options} </p>
<hr>
<a href="http://moss.stanford.edu/general/format.html" target="_top"> How to Read the Results</a>
<a href="http://moss.stanford.edu/general/tips.html" target="_top"> Tips</a>
<a href="http://moss.stanford.edu/general/faq.html"> FAQ</a>
<a href="mailto:moss-request@cs.stanford.edu">Contact</a>
<a href="http://moss.stanford.edu/general/scripts.html">Submission Scripts</a>
<a href="http://moss.stanford.edu/general/credits.html" target="_top"> Credits</a>
<hr>
<table>
<tbody>
<tr>
<th>File 1</th>
<th>File 2</th>
<th>Lines Matched</th>
</tr>
"""
reportHTMLBottom = """
</tbody>
</table>
</body>
</html>
"""
# Iterating through all of the urls ?to the sub reports, and passing to createSubReport function to create the Sub Reports
for i in range(0, len(subReportUrls), 2):
nameLeft = subReportUrls[i].contents[0]
nameRight = subReportUrls[i + 1].contents[0]
linesMatched = numLinesMatched[int(i / 2)].contents[0]
reportLocation = createSubReport(subReportUrls[i].attrs['href'], nameLeft[:-6], nameRight[:-6], path)
reportHTMLTop = reportHTMLTop + f"""<tr><td> <a href={reportLocation}> {nameLeft} </a> </td>""" + f"""<td> <a href={reportLocation}> {nameRight} </a> </td>""" + f"""<td align=\"right\">{linesMatched}</td> </tr>"""
reportHTMLTop = reportHTMLTop + reportHTMLBottom
mossReport = open(path + 'mossReport.html', 'wb')
mossReport.write(reportHTMLTop.encode())
mossReport.close()