def webhook_init(username, reponame, client, token, db, add_username): event_user_url = 'https://api.github.com/repos/%s/%s/events?page=%s&per_page=100&access_token=%s' i = 1 while True: print event_user_url % (username, reponame, i, token) event_info = yield client.fetch(event_user_url % (username, reponame, i, token), raise_error=False) if event_info.code != 200: print event_info.code print 'it is done!' break print 'ooop' event_info_json = json.loads(event_info.body) for one in event_info_json: if one['type'] == 'WatchEvent': one_user_url = 'https://api.github.com/users/%s?access_token=%s' % (one['actor']['login'] ,token) print one_user_url sender_info = yield client.fetch(one_user_url, raise_error=False) if sender_info.code != 200: print 'it can not get this user infomation: %s!' % one['actor']['login'] continue sender_info_json = json.loads(sender_info.body) if 'location' in sender_info_json and sender_info_json['location']: location = yield get_geo_name(sender_info_json['location']) if not location: print 'it can not get location by geonames.org!' continue city = location['city'] country = location['country'] location_str = sender_info_json['location'] countrycode = location['countrycode'] company = sender_info_json['company'] else: city = '' country = '' location_str = '' countrycode = '' company = '' print 'location: %s' % city sender = { 'followers': sender_info_json['followers'], 'sender_name': one['actor']['login'], 'avatar_url': sender_info_json['avatar_url'], 'public_repos': sender_info_json['public_repos'], 'city': city, 'country': country, 'location': location_str, 'countrycode': countrycode, 'company': company } yield db.event.insert({ 'username': username, 'reponame':reponame, 'add_username':add_username, 'sender': sender, 'time': parser.parse(one['created_at']) }) i = i + 1 raise gen.Return(True)
def webhook_init(username, reponame, client, token, db): event_user_url = 'https://api.github.com/repos/%s/%s/events?page=%s&per_page=100&access_token=%s' i = 1 while True: event_info = yield client.fetch(event_user_url % (username, reponame, i, token), raise_error=False) if event_info.code != 200: print 'it is done!' break print 'ooop' event_info_json = json.loads(event_info.body) for one in event_info_json: if one['type'] == 'WatchEvent': one_user_url = 'https://api.github.com/users/%s?access_token=%s' % (one['actor']['login'] ,token) print one_user_url sender_info = yield client.fetch(one_user_url, raise_error=False) if sender_info.code != 200: print 'it can not get this user infomation: %s!' % one['actor']['login'] continue sender_info_json = json.loads(sender_info.body) if 'location' in sender_info_json and sender_info_json['location']: location = yield get_geo_name(sender_info_json['location']) if not location: print 'it can not get location by geonames.org!' continue city = location['city'] country = location['country'] location_str = sender_info_json['location'] countrycode = location['countrycode'] company = sender_info_json['company'] else: city = '' country = '' location_str = '' countrycode = '' company = '' print 'location: %s' % city sender = { 'followers': sender_info_json['followers'], 'sender_name': one['actor']['login'], 'avatar_url': sender_info_json['avatar_url'], 'public_repos': sender_info_json['public_repos'], 'city': city, 'country': country, 'location': location_str, 'countrycode': countrycode, 'company': company } yield db.event.insert({ 'username': username, 'reponame':reponame, 'sender': sender, 'time': parser.parse(one['created_at']) }) i = i + 1 raise gen.Return(True)
def add_webhook_event(username, repo_json, reponame, client, token, db): sender_info = yield client.fetch( 'https://api.github.com/users/%s?access_token=%s' % (repo_json['sender']['login'], token), raise_error=False) if sender_info.code != 200: raise gen.Return(False) sender_info_json = json.loads(sender_info.body) if 'location' in sender_info_json and sender_info_json['location']: location = yield get_geo_name(sender_info_json['location']) if not location: raise gen.Return(False) city = location['city'] country = location['country'] countrycode = location['countrycode'] location_str = sender_info_json['location'] company = sender_info_json['company'] else: city = '' country = '' location_str = '' countrycode = '' company = '' print 'city:%s' % city sender = { 'followers': sender_info_json['followers'], 'sender_name': repo_json['sender']['login'], 'avatar_url': sender_info_json['avatar_url'], 'public_repos': sender_info_json['avatar_url'], 'city': city, 'country': country, 'countrycode': countrycode, 'location': location_str, 'company': company } insert_res = yield db.event.insert({ 'username': username, 'reponame': reponame, 'sender': sender, 'star_count': repo_json['repository']['stargazers_count'], 'time': parser.parse(repo_json['repository']['updated_at']) }) raise gen.Return(insert_res)
def add_webhook_event(username, repo_json, reponame, client, token, db): sender_info = yield client.fetch('https://api.github.com/users/%s?access_token=%s' % (repo_json['sender']['login'], token), raise_error=False) if sender_info.code != 200: raise gen.Return(False) sender_info_json = json.loads(sender_info.body) if 'location' in sender_info_json and sender_info_json['location']: location = yield get_geo_name(sender_info_json['location']) if not location: raise gen.Return(False) city = location['city'] country = location['country'] countrycode = location['countrycode'] location_str = sender_info_json['location'] company = sender_info_json['company'] else: city = '' country = '' location_str = '' countrycode = '' company= '' print 'city:%s' % city sender = { 'followers': sender_info_json['followers'], 'sender_name': repo_json['sender']['login'], 'avatar_url': sender_info_json['avatar_url'], 'public_repos': sender_info_json['avatar_url'], 'city': city, 'country': country, 'countrycode': countrycode, 'location': location_str, 'company': company } insert_res = yield db.event.insert({ 'username': username, 'reponame':reponame, 'sender': sender, 'star_count': repo_json['repository']['stargazers_count'], 'time': parser.parse(repo_json['repository']['updated_at']) }) raise gen.Return(insert_res)