This repository was archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py.save
More file actions
executable file
·205 lines (147 loc) · 6.3 KB
/
Copy pathapp.py.save
File metadata and controls
executable file
·205 lines (147 loc) · 6.3 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/python
# coding=utf-8
from flask import Flask,Response,jsonify, render_template ,flash, redirect, url_for, session,logging,request, make_response, request
app = Flask(__name__)
import urllib
from bs4 import BeautifulSoup
# @app.errorhandler(Exception)
# def all_exception_handler(error):
# return render_template('form.html')
@app.route('/')
def home():
return render_template('home.html')
@app.route('/ScanTos', methods = ['GET','POST'])
def TestTos():
if request.method == 'POST':
safetyurl = request.form['websiteurl']
html = urllib.request.urlopen(safetyurl).read()
soup = BeautifulSoup(html)
# kill all script and style elements
for script in soup(["script", "style"]):
script.extract() # rip it out
# get text
text = soup.get_text()
# break into lines and remove leading and trailing space on each
lines = (line.strip() for line in text.splitlines())
# break multi-headlines into a line each
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
# drop blank lines
text = '\n'.join(chunk for chunk in chunks if chunk)
ToStr = text.lower() #Replace 'open("tos.txt", "r").read()' with str
print(text)
catagories = ['business-transfers', 'changes', 'tracking', 'waiving-rights']
negatives = ['not', 'no', 'none', 'never']
catScore = [0,0,0,0]
catTotal = [0,0,0,0]
totalScore = 0
for i in range(len(catagories)):
index = i
terms = [i for i in open("text/"+catagories[i]+".txt", "r").read().replace('_', ' ').split('\n') if i]
score = 0
for term in terms:
current = ToStr.count(term)
for negative in negatives: #Implement negatives
current -= ToStr.count(negative + ' ' + term)
current -= ToStr.count(negative + ' be ' + term)
score+=current
catTotal[index] = score
if score<0: score=0
elif score>25: score=25
catScore[index] = score
totalScore += score
worst = [0,0]
for i in range(len(catScore)):
if catScore[i] > worst[0]:
worst = [catScore[i], i]
if (100 - (totalScore*3) < 0): totalScore = 0
else: totalScore = 100 - (totalScore*3)
# for i in range(4):
# print catagories[i].replace("-"," "), "got infracted", catTotal[i], "times."
zero = str(catTotal[0])
one = str(catTotal[1])
two = str(catTotal[2])
three = str(catTotal[3])
recommendations = 'The current ToS has a score of ' + str(totalScore) + ' with the worst being in ' + str(catagories[worst[1]].replace("-"," "))
print(recommendations)
# print(ToS)
score = totalScore
return render_template('results.html',score = score,recommendations = recommendations,zero=zero,one=one,two=two,three=three,safetyurl=safetyurl)
else:
return render_template('form.html')
@app.route('/ScanTosExtention/<string:safetyurl>', methods = ['GET','POST'])
def TestTosExtention(safetyurl):
safetyurl = "http://" + safetyurl.replace("-slash-","/")
print(safetyurl)
html = urllib.request.urlopen(safetyurl).read()
soup = BeautifulSoup(html)
# kill all script and style elements
for script in soup(["script", "style"]):
script.extract() # rip it out
# get text
text = soup.get_text()
# break into lines and remove leading and trailing space on each
lines = (line.strip() for line in text.splitlines())
# break multi-headlines into a line each
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
# drop blank lines
text = '\n'.join(chunk for chunk in chunks if chunk)
print(text)
html = urllib.request.urlopen(safetyurl).read()
soup = BeautifulSoup(html)
# kill all script and style elements
for script in soup(["script", "style"]):
script.extract() # rip it out
# get text
text = soup.get_text()
# break into lines and remove leading and trailing space on each
lines = (line.strip() for line in text.splitlines())
# break multi-headlines into a line each
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
# drop blank lines
text = '\n'.join(chunk for chunk in chunks if chunk)
ToStr = text.lower() #Replace 'open("tos.txt", "r").read()' with str
catagories = ['business-transfers', 'changes', 'tracking', 'waiving-rights']
negatives = ['not', 'no', 'none', 'never',"don't"]
catScore = [0,0,0,0]
catTotal = [0,0,0,0]
totalScore = 0
for i in range(len(catagories)):
index = i
terms = [i for i in open("text/"+catagories[i]+".txt", "r").read().replace('_', ' ').split('\n') if i]
score = 0
for term in terms:
current = ToStr.count(term)
for negative in negatives: #Implement negatives
current -= ToStr.count(negative + ' ' + term)
current -= ToStr.count(negative + ' be ' + term)
score+=current
catTotal[index] = score
if score<0: score=0
elif score>25: score=25
catScore[index] = score
totalScore += score
worst = [0,0]
for i in range(len(catScore)):
if catScore[i] > worst[0]:
worst = [catScore[i], i]
if (100 - (totalScore*3) < 0): totalScore = 0
else: totalScore = 100 - (totalScore*3)
# for i in range(4):
# print catagories[i].replace("-"," "), "got infracted", catTotal[i], "times."
zero = str(catTotal[0])
one = str(catTotal[1])
two = str(catTotal[2])
three = str(catTotal[3])
print(zero)
print(one)
print(two)
print(three)
recommendations = 'The current ToS has a score of ' + str(totalScore) + ' with the worst being in ' + str(catagories[worst[1]].replace("-"," "))
print(recommendations)
# print(ToS)
score = totalScore
return render_template('results.html',score = score,recommendations = recommendations,zero=zero,one=one,two=two,three=three, safetyurl=safetyurl)
#run server
if __name__ == '__main__':
app.secret_key='secret123'
app.run(host='0.0.0.0', port=80, threaded=True,debug='True')