from Simhash import Simhash
from teamque1.referrences.definitions import define
from teamque1.referrences.definitions import teamscore
from teamque1.referrences.definitions import teamplayers
from teamque1.referrences.definitions import teamtable
from teamque1.referrences.definitions import teamposition
from teamque1.referrences.definitions import teamsgame
import re
import sys
import difflib
name = input
def search_soccerteams():
"""Searches through the system finding the team stuff e.g. if you enter Arsenal, you get the score results of the last game"""
while True:
name = input ('Please Type your Question: ').lower().split()
name2 = name[:]
for item in name2:break
name3 = ' '.join(name2)
import sqlite3
id = 0
location = ""
conn = sqlite3.connect("team.db")
c = conn.cursor()
c.execute('select * from scores')
records = c.fetchall()
for record in records:
id = record[0]
location = record[15]
if id == name3:
print (name3.capitalize(),':' '\n',location)
break
else:
for item in name2:
def FindName1(name,list1):
""" searches for a pattern in the list, returns the complete list entry. Is case sensitive. May return incomplete value if ' is in the list value"""
if name in list1:
return name
else:
string1 = str(list1).replace('"',"'")
pattern = re.compile("[']"+name+"[^']*")
match = re.search(pattern,string1)
if match:
if match.group().lstrip("'") in list1:
return match.group().lstrip("'")
else:
print( 'Fail %s' %match.group().lstrip("'"))
return None
else:
return ' '.join(name2) + '\n' 'Result.'
this = ' '.join(name2)
text1 = this
text2 = FindName1(this,define)
simhash1 = Simhash(text1)
simhash2 = Simhash(text2)
similarity = simhash1.similarity(simhash2)
if similarity < 100:
this = ' '.join(name2)[:-1]
text2 = this.split()[:-1]
text3 = ' '.join(text2)
text4 = FindName1(text3,teamscore)
simhash1 = Simhash(text3)
simhash2 = Simhash(text4)
similarity = simhash1.similarity(simhash2)
if similarity == 100:
name3 = ' '.join(name2[-1:])
for item in name3:
if similarity == 100:
import sqlite3
id = 0
location = ""
conn = sqlite3.connect("teams.db")
c = conn.cursor()
c.execute('select * from scores')
records = c.fetchall()
for record in records:
id = record[0]
location = record[10]
if id == name3:
print ('\n''Your team details:' , FindName1(this,define))
print ('Score of:', name3.capitalize(),":",'\n', location )
exit = input("Press 1 to exit: ")# or press close to exit
while True:
if int(exit) == 1:
sys.exit();
print('Please Enter Your Next Question: ')
this = ' '.join(name2)
text1 = this
text2 = FindName1(this,define)
simhash1 = Simhash(text1)
simhash2 = Simhash(text2)
similarity = simhash1.similarity(simhash2)
if similarity < 100:
this = ' '.join(name2)[:-1]
text2 = this.split()[:-1]
text3 = ' '.join(text2)
text4 = FindName1(text3,teamstable)
simhash1 = Simhash(text3)
simhash2 = Simhash(text4)
similarity = simhash1.similarity(simhash2)
if similarity == 100:
name3 = ' '.join(name2[-1:])
for item in name3:
if similarity == 100:
import sqlite3
id = 0
location = ""
conn = sqlite3.connect("teams.db")
c = conn.cursor()
c.execute('select * from position')
records = c.fetchall()
for record in records:
id = record[0]
location = record[10]
if id == name3:
print ('\n''Your team details:' , FindName1(this,define))
print ('Table position of:', name3.capitalize(),":",'\n', location )
exit = input("Press 1 to exit: ")# or press close to exit
while True:
if int(exit) == 1:
sys.exit();
print('Please Enter Your Next Question: ')
this = ' '.join(name2)
text1 = this
text2 = FindName1(this,define)
simhash1 = Simhash(text1)
simhash2 = Simhash(text2)
similarity = simhash1.similarity(simhash2)
if similarity < 100:
this = ' '.join(name2)[:-1]
text2 = this.split()[:-1]
text3 = ' '.join(text2)
text4 = FindName1(text3,teamsgame)
simhash1 = Simhash(text3)
simhash2 = Simhash(text4)
similarity = simhash1.similarity(simhash2)
if similarity == 100:
name3 = ' '.join(name2[-1:])
for item in name3:
if similarity == 100:
import sqlite3
id = 0
location = ""
conn = sqlite3.connect("teams.db")
c = conn.cursor()
c.execute('select * from games')
records = c.fetchall()
for record in records:
id = record[0]
location = record[10]
if id == name3:
print ('\n''Your team details:' , FindName1(this,define))
print ('The next game for:', name3.capitalize(),":",'\n', location )
exit = input("Press 1 to exit: ")# or press close to exit
while True:
if int(exit) == 1:
sys.exit();
print('Please Enter Your Next Question: ')
this = ' '.join(name2)
text1 = this
text2 = FindName1(this,define)
simhash1 = Simhash(text1)
simhash2 = Simhash(text2)
similarity = simhash1.similarity(simhash2)
if similarity < 100:
this = ' '.join(name2)[:-1]
text2 = this.split()[:-1]
text3 = ' '.join(text2)
text4 = FindName1(text3,teamplayers)
simhash1 = Simhash(text3)
simhash2 = Simhash(text4)
similarity = simhash1.similarity(simhash2)
if similarity == 100:
name3 = ' '.join(name2[-1:])
for item in name3:
if similarity == 100:
import sqlite3
id = 0
location = ""
conn = sqlite3.connect("teams.db")
c = conn.cursor()
c.execute('select * from players')
records = c.fetchall()
for record in records:
id = record[0]
location = record[10]
if id == name3:
print ('\n''Your team details:' , FindName1(this,define))
print ('Team players for:', name3.capitalize(),":",'\n', location )
exit = input("Press 1 to exit: ")# or press close to exit
while True:
if int(exit) == 1:
sys.exit();
print('Please Enter Your Next Question: ')
I also have other modules for other teams such as NBA, Hockey,Rugby etc. Every time I run the module separately, it works, but I need a way to import into a main to allow a user to enter any key word such as 'Chicago Bulls players' and the module runs or 'Arsenal score' and the module runs from the main. The modules contain quite a long detail and that is why I have separated the long code into these modules. I have also put them into packages.Please help