def __init__(self, message_type, payload, **kwargs): """Initialize a message.""" self.message_type = message_type self.title = util.traverse_dict(payload, kwargs['title']) self.url = util.traverse_dict(payload, kwargs['url']) self.action = util.traverse_dict(payload, kwargs['action']) self.repo_name = util.get_repo_name(payload, kwargs['repo']) self.usernames = util.get_usernames(payload, kwargs['users']) if message_type == 'pull_request': self.action = self.get_pr_status(self.action, payload)
def get_reddit_user_bios(): mongo_client = MongoClient('localhost', 27017) reddit_data = mongo_client.reddit_data user_data = reddit_data.user_data user_data.create_index( [("name",pymongo.ASCENDING)], background=True ) usernames = util.get_usernames() for user in usernames: r = reddit.api_get('user/' + user.strip() + '/about', {}) if r != None: user_data.insert_one(r)
def get_reddit_user_bios(): mongo_client = MongoClient('localhost', 27017) reddit_data = mongo_client.reddit_data user_data = reddit_data.user_data user_data.create_index( [("data.name",pymongo.ASCENDING)], unique=True, dropDups=True ) usernames = util.get_usernames() for user in usernames: print user r = reddit.api_get('user/' + user.strip() + '/about', {}) if r != None: try: u = user_data.insert_one(r) except pymongo.errors.DuplicateKeyError: continue
def get_reddit_user_content(): mongo_client = MongoClient('localhost', 27017) reddit_data = mongo_client.reddit_data user_commentss = reddit_data.user_comments user_comments.create_index( [("data.id",pymongo.ASCENDING)], background=True, unique=True, dropDups=True ) params = { 'sort': 'new', 't': 'all', 'limit': 100, 'sr_detail': True } usernames = util.get_usernames() for user in usernames: print user continueWithUser = True while continueWithUser: r = reddit.api_get('user/' + user.strip() + '/submitted', params) if r != None: for thing in r['data']['children']: try: user_comments.insert_one(thing) except pymongo.errors.DuplicateKeyError: continue if r['data']['after'] is None: continueWithUser = False break else: params['after'] = r['data']['after'] else: continueWithUser = False