Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions client_socket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import socket
import tkinter as tk
from tkinter import font
import pickle
import webbrowser

Response = []
# Class to create vertical scrollable frame to show urls to the user.
class VerticalScrolledFrame(tk.Frame):
"""A pure Tkinter scrollable frame that actually works!

* Use the 'interior' attribute to place widgets inside the scrollable frame
* Construct and pack/place/grid normally
* This frame only allows vertical scrolling
"""

def __init__(self, parent, *args, **kw):
tk.Frame.__init__(self, parent, *args, **kw)

# create a canvas object and a vertical scrollbar for scrolling it
vscrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
vscrollbar.pack(fill=tk.Y, side=tk.RIGHT, expand=tk.FALSE)
canvas = tk.Canvas(self, bd=0, highlightthickness=0,
yscrollcommand=vscrollbar.set)
# canvas.place(x=2,y=200)
canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.TRUE)
vscrollbar.config(command=canvas.yview)

# reset the view
canvas.xview_moveto(0)
canvas.yview_moveto(0)

# create a frame inside the canvas which will be scrolled with it
self.interior = interior = tk.Frame(canvas)
interior_id = canvas.create_window(0, 0, window=interior,
anchor=tk.NW)

# track changes to the canvas and frame width and sync them,
# also updating the scrollbar
def _configure_interior(event):
# update the scrollbars to match the size of the inner frame
size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
canvas.config(scrollregion="0 0 %s %s" % size)
if interior.winfo_reqwidth() != canvas.winfo_width():
# update the canvas's width to fit the inner frame
canvas.config(width=interior.winfo_reqwidth())

interior.bind('<Configure>', _configure_interior)

def _configure_canvas(event):
if interior.winfo_reqwidth() != canvas.winfo_width():
# update the inner frame's width to fill the canvas
canvas.itemconfigure(interior_id, width=canvas.winfo_width())

canvas.bind('<Configure>', _configure_canvas)


# Destroy the current result frame and create a new frame.
def frame_clear():
scframe.destroy()
create()

# Create a scrollable frame to show to the user.
def create():
global scframe
scframe = VerticalScrolledFrame(root)
scframe.pack(side='bottom', pady=30)

def openlink(x):
webbrowser.open_new(x)

def getquery():
frame_clear()
e = user_query.get()
ClientSocket.send(str.encode(e))
Response = ClientSocket.recv(2048)
Response = pickle.loads(Response)
for i, x in enumerate(Response):

btn = tk.Button(scframe.interior, height=1, width=100, relief=tk.FLAT, bg="gray99", fg="blue", font="Dosis",
text=f"{Response[i]}", command=lambda i=i, x=x: openlink(x))
btn.pack(padx=10, pady=5, side=tk.TOP)
Response.clear()
if e == 'end':
ClientSocket.close()


print('** Ready to connect **')
while True:
host = input('Enter server IP:\t')
port = 95

ClientSocket = socket.socket()

try:
ClientSocket.connect((host, port))
print('\t** Connected to server **')
break
except socket.error as e:
print("Incorrect IP or server is not running")

root = tk.Tk()
root.title("Search Engine")
root.geometry('800x500')
root['bg'] = '#FFFFFF'
root.minsize(800, 500)
root.maxsize(800, 500)
# lis = []
user_query = tk.StringVar()
# logo_path = tk.PhotoImage(file="BG.ppm")
# logo = Label(root, image=logo_path).pack()
button_font = font.Font(family='Calibri', size=8)
text_entry = tk.Entry(root, textvariable=user_query, width=55, bg='#C0C0C0').place(x=230, y=120)
search_button = tk.Button(root, text="Search", font=button_font, padx=1, pady=1, command=getquery).place(x=375, y=150)
scframe = VerticalScrolledFrame(root)
scframe.pack(side='bottom', pady=30)

root.mainloop()
82 changes: 39 additions & 43 deletions front.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
'''
DSA PROJECT MADE BY:
1. SAIF ALI (336561)
2. HASEEB MAHMOOD (334718)
3. TALHA MAJEED KHAN (336254)
4. ALI USMAN BUTT (335520)

PRESENTED TO: SIR FAISAL SHAFAIT
'''

# Importing external dependencies.
import collections
Expand All @@ -31,7 +22,6 @@
key = int(fp_temp.readline())
docid = int(fp_temp.readline())
fp_temp.close()

fp_a = open("author.json", "r")
author_dictionary = json.load(fp_a)
fp_a.close()
Expand Down Expand Up @@ -114,6 +104,11 @@ def clear():
scframe.destroy()
create()

# Create a scrollable frame to show to the user.
def create():
global scframe
scframe = VerticalScrolledFrame(root)
scframe.pack(side='bottom', pady=30)

# Get query from the user. (The text written in search bar)
def getquery():
Expand All @@ -127,11 +122,6 @@ def getquery():
btn.pack(padx=10, pady=5, side=tk.TOP)


# Create a scrollable frame to show to the user.
def create():
global scframe
scframe = VerticalScrolledFrame(root)
scframe.pack(side='bottom', pady=30)


# Make the urls that are received as strings and convert them to hyperlinks.
Expand Down Expand Up @@ -288,7 +278,7 @@ def searching(search, lis):
if len(mwq[docid][0]) != 0:
proximity[docid] = mwq[docid][0]
if len(common_title) > 0:
print("\n------------TITLE OCCURRENCES-----------------\n")
# print("\n------------TITLE OCCURRENCES-----------------\n")
count = 0
for t in common_title:
if t is None:
Expand All @@ -300,7 +290,7 @@ def searching(search, lis):
break

if len(common_set) == 0:
print("No such combination of words exist in the database")
# print("No such combination of words exist in the database")
for wordids in wordslist: # if there is no word from query in title or in close proximity or common in some document
sth = singlewordwithid(wordids)
counter = 0
Expand All @@ -314,14 +304,14 @@ def searching(search, lis):
continue
else: # printing words in close proximity first and the ones in common set later
if len(proximity) != 0:
print("\n------------CLOSE PROXIMITY OCCURRENCES-----------------\n")
# print("\n------------CLOSE PROXIMITY OCCURRENCES-----------------\n")
var = 0
for val in proximity.keys():
lis.append(url_dic[f"{val}"])
var +=1
if var == 30:
break
print("\n------------OTHER OCCURRENCES---------------------------\n")
# print("\n------------OTHER OCCURRENCES---------------------------\n")
var = 0
for value in common_set:
if value not in proximity.keys():
Expand All @@ -330,7 +320,7 @@ def searching(search, lis):
if var == 30:
break
else:
print("\n------------OTHER OCCURRENCES---------------------------\n")
# print("\n------------OTHER OCCURRENCES---------------------------\n")
var = 0
for value in common_set:
if value not in proximity.keys():
Expand Down Expand Up @@ -360,14 +350,14 @@ def searching(search, lis):
counter = 0
if len(ts) > 0 or len(sws) > 0:
if len(ts) > 0:
print("\n------------TITLE OCCURRENCES-----------------\n")
# print("\n------------TITLE OCCURRENCES-----------------\n")
for t in ts:
lis.append(url_dic[f"{t}"])
counter += 1
if counter == 30:
break
if len(sws) > 0:
print("\n------------OTHER OCCURRENCES-----------------\n")
# print("\n------------OTHER OCCURRENCES-----------------\n")
counter = 0
for key in sws.keys():
lis.append(url_dic[f"{key}"])
Expand Down Expand Up @@ -434,7 +424,12 @@ def updateall(filetoadd, key, docid, fp_filenames):
author_tokens = word_tokenize(y[i]["author"]) #updating authors
author_tokens = [w.lower() for w in author_tokens]
author = "".join(author_tokens)
author_dictionary[f'{author}'].append(docid)
if author not in author_dictionary:
author_dictionary[f"{author}"] = [docid]
elif author in author_dictionary:
author_docids = author_dictionary[f"{author}"]
author_docids.append(docid)
author_dictionary[f"{author}"] = author_docids
title_tokens = word_tokenize(y[i]["title"])
word_tokens = [w.lower() for w in word_tokens]
table = str.maketrans('', '', string.punctuation)
Expand Down Expand Up @@ -501,23 +496,24 @@ def updateall(filetoadd, key, docid, fp_filenames):
print("updation successfull")


print("Initializing GUI")

root = tk.Tk()
root.title("Search Engine")
root.geometry('800x500')
root['bg'] = '#FFFFFF'
root.minsize(800, 500)
root.maxsize(800, 500)
lis = []
user_query = tk.StringVar()
logo_path = tk.PhotoImage(file="BG.ppm")
logo = Label(root, image=logo_path).pack()
button_font = font.Font(family='Arial', size=8)
text_entry = tk.Entry(root, textvariable=user_query, width=55, bg='#C0C0C0').place(x=230, y=120)
search_button = tk.Button(root, text="search", font=button_font, padx=1, pady=1, command=getquery).place(x=375, y=150)
add_file_button = tk.Button(root, text="add file", font=button_font, padx=4, pady=2, command=getFile).place(x=740, y=10)
scframe = VerticalScrolledFrame(root)
scframe.pack(side='bottom', pady=30)

root.mainloop()
if __name__ == '__main__':
print("Initializing GUI")

root = tk.Tk()
root.title("Search Engine")
root.geometry('800x500')
root['bg'] = '#FFFFFF'
root.minsize(800, 500)
root.maxsize(800, 500)
lis = []
user_query = tk.StringVar()
# logo_path = tk.PhotoImage(file="BG.ppm")
# logo = Label(root, image=logo_path).pack()
button_font = font.Font(family='Calibri', size=8)
text_entry = tk.Entry(root, textvariable=user_query, width=55, bg='#C0C0C0').place(x=230, y=120)
search_button = tk.Button(root, text="Search", font=button_font, padx=1, pady=1, command=getquery).place(x=375, y=150)
add_file_button = tk.Button(root, text="Add File", font=button_font, padx=4, pady=2, command=getFile).place(x=740, y=10)
scframe = VerticalScrolledFrame(root)
scframe.pack(side='bottom', pady=30)

root.mainloop()
Loading