def save_story_info(session, story_dict): ''' Save a dictionary of story into to the datastore session then return that story instance ''' filter = Story.organization_name == story_dict['organization_name'], \ Story.link == story_dict['link'] existing_story = session.query(Story).filter(*filter).first() # If this is a new story, save and return it. if not existing_story: new_story = Story(**story_dict) session.add(new_story) return new_story # Mark the existing story for safekeeping. existing_story.keep = True # Update existing story details for (field, value) in story_dict.items(): setattr(existing_story, field, value) # Flush existing object, to prevent a sqlalchemy.orm.exc.StaleDataError. session.flush()
def save_story_info(session, story_dict): ''' Save a dictionary of story into to the datastore session then return that story instance ''' # Select the current story, filtering on link and organization name. filter = Story.organization_name == story_dict['organization_name'], \ Story.link == story_dict['link'] existing_story = session.query(Story).filter(*filter).first() # If this is a new story, save and return it. if not existing_story: new_story = Story(**story_dict) session.add(new_story) return new_story # Preserve the existing story. # :::here (story/true) existing_story.keep = True # Update existing story details for (field, value) in story_dict.items(): setattr(existing_story, field, value)
exit(1) # Setup headless browser options chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument("--disable-extensions") chrome_options.add_argument("--disable-gpu") chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) chrome_options.add_experimental_option("prefs",{"profile.default_content_settings.cookies": 2}) driver = webdriver.Chrome(executable_path="{}/chromedriver.exe".format(DRIVER),options=chrome_options) if args.app == 'stock': app = Stock(driver) elif args.app == 'story': app = Story(driver) else: app = Money(driver) data = {} if isinstance(app,Stock): # Check stock arguments if args.overview: data["overview"] = app.getOverview() data["tables"] = app.getTable(args.keystats,args.usindex) if args.hot: data["hot"] = app.getHot() elif isinstance(app,Story): # Check story arguments if args.img: