def update_project_by_name(project_name, track_progress=False): wp10db = wp10_connect() wikidb = wiki_connect() redis = redis_connect() logging.basicConfig(level=logging.INFO) logging.getLogger('mwclient').setLevel(logging.CRITICAL) logging.getLogger('urllib3').setLevel(logging.CRITICAL) logging.getLogger('requests_oauthlib').setLevel(logging.CRITICAL) logging.getLogger('oauthlib').setLevel(logging.CRITICAL) try: project = get_project_by_name(wp10db, project_name) if not project: project = Project(p_project=project_name, p_timestamp=GLOBAL_TIMESTAMP_WIKI) update_project(wikidb, wp10db, project, redis=redis, track_progress=track_progress) if track_progress: redis.expire(_project_progress_key(project_name), 600) finally: wp10db.close() wikidb.close()
def get_project_by_name(wp10db, project_name): with wp10db.cursor() as cursor: cursor.execute('SELECT * FROM projects WHERE p_project=%(p_project)s', {'p_project': project_name}) db_project = cursor.fetchone() if db_project is None: return None return Project(**db_project)
def setUp(self): super().setUp() self.project_name = b'My test project' self.project = Project(p_project=self.project_name, p_timestamp=b'20180930123000', p_count=100, p_upload_timestamp=b'20180929120000') logic_project.insert_or_update(self.wp10db, self.project)
def setUp(self): super().setUp() self.project = Project(p_project=b'Testing', p_timestamp='201001010000') logic_project.insert_or_update(self.wp10db, self.project) self.old_ns = 0 self.old_article = b'The history of testing' self.new_ns = 0 self.new_article = b'History of testing' self.dt = datetime(2015, 4, 1) self.timestamp_db = self.dt.strftime(TS_FORMAT).encode('utf-8')
def list_all_projects(wp10db): with wp10db.cursor() as cursor: cursor.execute(''' SELECT p_project, p_timestamp, p_count, p_qcount, p_icount FROM projects ''') return [Project(**db_project) for db_project in cursor.fetchall()]