def repo(): while not repo_queue.empty(): info = repo_queue.get() user = info['user'] tmp = github(user_name=user) try: if info['repo'] == []: continue for url in info['repo']: repos = tmp.repo(url=url) for repo_name in repos: database().repo(project_user=user, project_name=repo_name, project_url=' ') except Exception as e: repo_queue.put(info)
def followers(): while not followers_queue.empty(): info = followers_queue.get() user = info['user'] tmp = github(user_name=user) try: if info['followers'] == []: continue for url in info['followers']: followers = tmp.user(url=url) for follower in followers: database().relationship(user_name=follower, referer=user, level=level, action='followers') except Exception as e: followers_queue.put(info)
def star(): while not star_queue.empty(): info = star_queue.get() user = info['user'] tmp = github(user_name=user) try: if info['star'] == []: continue for url in info['star']: repos = tmp.star(url=url) for repo_name in repos: project_owner = repo_name.split('/')[0] project_name = repo_name.split('/')[1] database().star(referer_user=user, project_name=project_name, project_url=' ', project_owner=project_owner) except Exception as e: star_queue.put(info)
def main(): try: # Open a connection to the database conn = config.database() get_educations(conn) #lines = read_file(conn, 'address.txt') finally: print('Closing connection to database') # Close communication with the database conn.close()
def main(): try: # Open a connection to the database conn = config.database() update_schools(conn) # parse_file(conn, 'us_institutions.json') finally: print('Closing connection to database') # Close communication with the database conn.close()
def main(): print("USAGE: python2 " + sys.argv[0] + " username host password database") try: user = sys.argv[1] except: user = '******' try: host = sys.argv[2] except: host = 'localhost' try: password = sys.argv[3] except: password = '******' try: db = sys.argv[4] except: db = 'price_watcher' db = database(user, password, host, db) # MAIN MENU selection = 0 numOptions = 2 while selection < 1 or selection > numOptions: prompt = " MENU\n" prompt += "======\n" prompt += "1 - Run Price Check (you must implement in config.py first)\n" prompt += "2 - Graph Prices (example data provided in \'sql\' folder)\n" prompt += ">> " selection = raw_input(prompt) try: selection = int(selection) except: selection = -1 if selection == 1: db.runPriceChecks() # Must write your own code in config.py elif selection == 2: db.graphJobs() # Uses database schema in folder "sql" else: print("ERROR") sys.exit()
def main(level): for user in database().find_level(level=level - 1): print(user) user_queue.put(user) # 生产者线程 producer_tasks = [] for i in range(300): run_producer = producer() producer_tasks.append(run_producer) for task in producer_tasks: task.start() for task in producer_tasks: task.join() # 调度线程 run_scheduler = scheduler() run_scheduler.start() run_scheduler.join() # 消费者线程 consumer_tasks = [] for i in range(500): run_consumer_star = consumer(action='star') run_consumer_repo = consumer(action='repo') run_consumer_following = consumer(action='following') run_consumer_followers = consumer(action='followers') consumer_tasks.append(run_consumer_star) consumer_tasks.append(run_consumer_repo) consumer_tasks.append(run_consumer_following) consumer_tasks.append(run_consumer_followers) for task in consumer_tasks: task.start() for task in consumer_tasks: task.join()
run_scheduler.start() run_scheduler.join() # 消费者线程 consumer_tasks = [] for i in range(500): run_consumer_star = consumer(action='star') run_consumer_repo = consumer(action='repo') run_consumer_following = consumer(action='following') run_consumer_followers = consumer(action='followers') consumer_tasks.append(run_consumer_star) consumer_tasks.append(run_consumer_repo) consumer_tasks.append(run_consumer_following) consumer_tasks.append(run_consumer_followers) for task in consumer_tasks: task.start() for task in consumer_tasks: task.join() if __name__ == '__main__': level = 0 # 初始化用户 database().init_user() while level != 7: level += 1 print(level) main(level=level)