def get_category(category_name, icon, desc ,append=False): """getter/setter function which creates or gets the category from the model :param category_name: string :param desc: string :param icon: image :param append: boolean, defaults to false, if false, deletes all existing pages from category :return: Category object """ # check to see if the category exists if Category.objects.filter(name=category_name): c = Category.objects.get(name=category_name) if not append: Page.objects.filter(category=c).all().delete() else: # create the category in the models/db c = Category(name=category_name, icon=icon, desc=desc, is_shown=True) c.save() return c
def get_category(category_name, icon, desc, append=False): """getter/setter function which creates or gets the category from the model :param category_name: string :param desc: string :param icon: image :param append: boolean, defaults to false, if false, deletes all existing pages from category :return: Category object """ # check to see if the category exists if Category.objects.filter(name=category_name): c = Category.objects.get(name=category_name) if not append: Page.objects.filter(category=c).all().delete() else: # create the category in the models/db c = Category(name=category_name, icon=icon, desc=desc, is_shown=True) c.save() return c
def main(): print 'Populating the Database from page_meta_data.txt' print '************************************************' from ifind.models.game_models import Category, Page from configuration import MEDIA_ROOT, STATIC_PATH from ifind.common.utils import convert_url_to_filename tuples_list = read_in_file('page_meta_data.txt') c = Category(name="research", icon=os.path.join(STATIC_PATH,'imgs/research.jpg'), desc=None, is_shown=True) c.save() c = Category(name="about glasgow", icon=os.path.join(STATIC_PATH,'imgs/about_glasgow.jpg'), desc=None, is_shown=True) c.save() c = Category(name="undergraduate", icon=os.path.join(STATIC_PATH,'imgs/undergraduate.jpg'), desc=None, is_shown=True) c.save() c = Category(name="postgraduate", icon=os.path.join(STATIC_PATH,'imgs/postgraduate.jpg'), desc=None, is_shown=True) c.save() c = Category(name="alumni", icon=os.path.join(STATIC_PATH,'imgs/alumni.png'), desc=None, is_shown=True) c.save() c = Category(name="student life", icon= os.path.join(STATIC_PATH,'imgs/student_life.jpg'), desc=None, is_shown=True) c.save() for item in tuples_list: cat = Category.objects.get(name=item[0]) url_file_name = convert_url_to_filename(item[1])+'.png' p = Page(category=cat, title=item[2], is_shown=True, url=item[1],screenshot=os.path.join('/', MEDIA_ROOT, url_file_name)) p.save() print("page with"+ item[2] +"has been saved")
def main(): logger = create_ifind_logger('test_game_mech.log') logger.info("Program started") logger.info('Testing game mechanics') print "This script is to test the GameMechanics and interaction with the Models" ds = EngineFactory("Dummy") gm = GameMechanic(ds) print gm u = User.objects.filter(username='******') if u: u = u[0] else: print "Adding testy user" u = User(username='******', password='******') u.save() c = Category.objects.filter(name='Numbers') if c: c = c[0] else: print "Adding a Numbers Category" c = Category(name='Numbers', desc='Looking for sites that around about numbers') c.save() pages = Page.objects.filter(category=c) if not pages: print "Adding pages" for pn in ['one', 'two', 'three', 'four']: p = Page(category=c, title=pn, url='www.' + pn + '.com', snippet=pn, desc=('desc: ' + pn)) p.save() pages = Page.objects.filter(category=c) print u print c print pages gm.create_game(u, c) print gm print "Game is set up to play" raw_input('Press enter to continue') while not gm.is_game_over(): clear_screen() print gm last_query = gm.get_last_query() if last_query: print "\nLast Query: %s and Query Score: %d" % ( last_query, gm.get_last_query_score()) state = handle_game_input() if state == 1: gm.take_points() gm.set_next_page() state = 0 if state == 2: query = handle_query_input() gm.handle_query(query) print '\nGame Over!!\n' print gm logger.info("Done!")
def main(): logger = create_ifind_logger("test_game_mech.log") logger.info("Program started") logger.info("Testing game mechanics") print "This script is to test the GameMechanics and interaction with the Models" ds = EngineFactory("Dummy") gm = GameMechanic(ds) print gm u = User.objects.filter(username="******") if u: u = u[0] else: print "Adding testy user" u = User(username="******", password="******") u.save() c = Category.objects.filter(name="Numbers") if c: c = c[0] else: print "Adding a Numbers Category" c = Category(name="Numbers", desc="Looking for sites that around about numbers") c.save() pages = Page.objects.filter(category=c) if not pages: print "Adding pages" for pn in ["one", "two", "three", "four"]: p = Page(category=c, title=pn, url="www." + pn + ".com", snippet=pn, desc=("desc: " + pn)) p.save() pages = Page.objects.filter(category=c) print u print c print pages gm.create_game(u, c) print gm print "Game is set up to play" raw_input("Press enter to continue") while not gm.is_game_over(): clear_screen() print gm last_query = gm.get_last_query() if last_query: print "\nLast Query: %s and Query Score: %d" % (last_query, gm.get_last_query_score()) state = handle_game_input() if state == 1: gm.take_points() gm.set_next_page() state = 0 if state == 2: query = handle_query_input() gm.handle_query(query) print "\nGame Over!!\n" print gm logger.info("Done!")