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(): populate_cats() #split line into tokens meta_data_file = sys.argv[1] data_list = get_trending_queries(meta_data_file) for data_tuple in data_list: cat = game_model_functions.get_category(data_tuple[0],'icon','',append=True) p = Page(category=cat, title=data_tuple[2], is_shown=True, url=data_tuple[1], screenshot=data_tuple[3]) p.save() return 0
def main(): populate_cats() #split line into tokens meta_data_file = sys.argv[1] data_list = get_trending_queries(meta_data_file) for data_tuple in data_list: cat = game_model_functions.get_category(data_tuple[0], 'icon', '', append=True) p = Page(category=cat, title=data_tuple[2], is_shown=True, url=data_tuple[1], screenshot=data_tuple[3]) p.save() return 0
def populate_pages(url_list, category, halved_screen_shot=False): """ :param url_list: a list of the urls for the pages that are going to be populated :param category: the category in which the pages fall into :return: """ #For each url in the url_list for url in url_list: # create PageCapture object - specify the browser to be 800 x 600. try: pc = PageCapture(url, 800, 600) url_file_name = convert_url_to_filename(url) + '.png' # To change to accomodate for the new changes image_file_name = os.path.join(DATA_DIR, url_file_name) pc.load_url(url) # fetch the screen-shot if halved_screen_shot: if random.random() > 0.5: pc.crop_screen_shot(image_file_name, 200, 400, 700, 900) else: pc.crop_screen_shot(image_file_name, 0, 0, 1000, 1000) #pc.halve_screen_shot(image_file_name) else: pc.take_screen_shot(image_file_name) # get the title title = pc.get_page_title() # create page in models/db with category # Abdullah , using DATA_DIR did not work for me because it uses the current working directory in the url. p = Page(category=category, title=title, is_shown=True, url=url, screenshot=os.path.join('/', MEDIA_ROOT, url_file_name)) p.save() print 'Page title= ' + p.title + ' has been saved!' except ValueError: print 'Page has ((NOT)) been saved!' print 'ERROR IS' print ValueError continue
def populate_pages(url_list, category, halved_screen_shot=False): """ :param url_list: a list of the urls for the pages that are going to be populated :param category: the category in which the pages fall into :return: """ #For each url in the url_list for url in url_list: # create PageCapture object - specify the browser to be 800 x 600. try: pc = PageCapture(url,800, 600) url_file_name = convert_url_to_filename(url)+'.png' # To change to accomodate for the new changes image_file_name = os.path.join(DATA_DIR, url_file_name) pc.load_url(url) # fetch the screen-shot if halved_screen_shot: if random.random() > 0.5: pc.crop_screen_shot(image_file_name,200,400,700,900) else: pc.crop_screen_shot(image_file_name,0,0,1000,1000) #pc.halve_screen_shot(image_file_name) else: pc.take_screen_shot(image_file_name) # get the title title = pc.get_page_title() # create page in models/db with category # Abdullah , using DATA_DIR did not work for me because it uses the current working directory in the url. p = Page(category=category, title=title, is_shown=True, url=url, screenshot=os.path.join('/', MEDIA_ROOT, url_file_name)) p.save() print 'Page title= ' + p.title + ' has been saved!' except ValueError: print 'Page has ((NOT)) been saved!' print 'ERROR IS' print ValueError continue
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!")