-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
136 lines (129 loc) · 5.86 KB
/
index.py
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
from flask import Flask, render_template, request, redirect, session, flash
import Searcher, AjaxUpdater
import math
app = Flask('Tarantula Server')
app.secret_key = "INSY_WINSY"
@app.route("/")
def main():
return render_template('index.html')
@app.route('/search', methods=['GET'])
def search():
searcher = Searcher.Searcher('google.db')
if request.method == 'GET':
term = request.args.get('term')
if term == '':
return('Please enter a search query')
type1 = request.args.get('type')
if request.args.get('page') != None: page = request.args.get('page')
else: page = 1
if type1 == 'web':
searchType = request.args.get('searchType')
if searchType == 'lucky':
luckyUrl = searcher.getLuckySiteResult(term.lower())
return redirect(str(luckyUrl))
else:
numResults, searchTime, resultsHtml, pageSize = searcher.getSiteResultsHtml(page, term.lower())
pagesToShow = 10
paginationContainer =''
page = int(page)
numPages = math.ceil(int(numResults)/int(pageSize))
pagesLeft = min(int(pagesToShow), int(numPages))
currentPage = page - math.floor(int(pagesToShow)/2)
if currentPage < 1 : currentPage = 1
if (currentPage + pagesLeft > numPages + 1): currentPage = numPages -pagesLeft +1
while pagesLeft != 0 and currentPage <= numPages:
if currentPage == page:
paginationContainer += f'''<div class='pageNumberContainer'>
<img src='static/images/logoPageNumber.png' width='16px' height='16px' style='filter:saturate(8);'>
<span class='pageNumber' style='color:#c00909;font-weight:bold;'>{currentPage}</span>
</div>'''
else:
paginationContainer += f'''<div class='pageNumberContainer'>
<a href='/search?term={term}&type={type1}&page={currentPage}'>
<img src='static/images/logoPageNumber.gif' width='16px' height='16px'>
<span class='pageNumber'>{currentPage}</span>
</a>
</div>'''
currentPage += 1
pagesLeft -= 1
return render_template('search.html', term=term,type1=type1,searchTime=searchTime,numResults=numResults,resultsHtml=resultsHtml,numPages=numPages,pagesLeft=pagesLeft,currentPage=currentPage,paginationContainer=paginationContainer)
elif type1 == 'images':
numResults = searcher.getImageNumResults(term.lower())
searchTime, resultsHtml, pageSize= searcher.getImageResultsHtml(page, term.lower())
pagesToShow = 10
paginationContainer =''
page = int(page)
numPages = math.ceil(int(numResults)/int(pageSize))
pagesLeft = min(int(pagesToShow), int(numPages))
currentPage = page - math.floor(int(pagesToShow)/2)
if currentPage < 1 : currentPage = 1
if (currentPage + pagesLeft > numPages + 1): currentPage = numPages -pagesLeft +1
while pagesLeft != 0 and currentPage <= numPages:
if currentPage == page:
paginationContainer += f'''<div class='pageNumberContainer'>
<img src='static/images/logoPageNumber.png' width='16px' height='16px' style='filter:saturate(8);'>
<span class='pageNumber' style='color:#c00909;font-weight:bold;'>{currentPage}</span>
</div>'''
else:
paginationContainer += f'''<div class='pageNumberContainer'>
<a href='/search?term={term}&type={type1}&page={currentPage}'>
<img src='static/images/logoPageNumber.gif' width='16px' height='16px'>
<span class='pageNumber'>{currentPage}</span>
</a>
</div>'''
currentPage += 1
pagesLeft -= 1
return render_template('search.html', term=term,type1=type1,searchTime=searchTime,numResults=numResults,resultsHtml=resultsHtml,numPages=numPages,pagesLeft=pagesLeft,currentPage=currentPage,paginationContainer=paginationContainer)
# return 'COMING SOON!!'
elif type1 == 'torrents':
numResults = searcher.getTorrentNumResults(term.lower())
searchTime, resultsHtml, pageSize= searcher.getTorrentResultsHtml(page, term.lower())
pagesToShow = 10
paginationContainer =''
page = int(page)
numPages = math.ceil(int(numResults)/int(pageSize))
pagesLeft = min(int(pagesToShow), int(numPages))
currentPage = page - math.floor(int(pagesToShow)/2)
if currentPage < 1 : currentPage = 1
if (currentPage + pagesLeft > numPages + 1): currentPage = numPages -pagesLeft +1
while pagesLeft != 0 and currentPage <= numPages:
if currentPage == page:
paginationContainer += f'''<div class='pageNumberContainer'>
<img src='static/images/logoPageNumber.png' width='16px' height='16px' style='filter:saturate(8);'>
<span class='pageNumber' style='color:#c00909;font-weight:bold;'>{currentPage}</span>
</div>'''
else:
paginationContainer += f'''<div class='pageNumberContainer'>
<a href='/search?term={term}&type={type1}&page={currentPage}'>
<img src='static/images/logoPageNumber.gif' width='16px' height='16px'>
<span class='pageNumber'>{currentPage}</span>
</a>
</div>'''
currentPage += 1
pagesLeft -= 1
return render_template('search.html', term=term,type1=type1,searchTime=searchTime,numResults=numResults,resultsHtml=resultsHtml,numPages=numPages,pagesLeft=pagesLeft,currentPage=currentPage,paginationContainer=paginationContainer)
else:
return '404'
@app.route('/ajax/updateImageCount', methods=['POST'])
def updateImageCount():
if request.method == 'POST':
if request.form['imageUrl'] == '':
print('BLANK URL')
return ''
print(f'URL of Image Clicked :: {request.form["imageUrl"]}')
ajaxUpdater = AjaxUpdater.AjaxUpdater('google.db')
updateImageStatus = ajaxUpdater.updateImageCount(request.form['imageUrl'])
return ''
@app.route('/ajax/setBroken', methods=['POST'])
def setBroken():
if request.method == 'POST':
if request.form['src'] == '':
print('BLANK URL')
return '' #Error
print(f'Broken URL :: {request.form["src"]}')
ajaxUpdater = AjaxUpdater.AjaxUpdater('google.db')
setBrokenStatus = ajaxUpdater.setBroken(request.form['src'])
return request.form['src']
return ''
if __name__ == "__main__":
app.run(debug=True)