def login_oauth_user(name, info): data = parse_data(name, info) if not check(name, data): raise Exception("login arguments error") users = db.select("user", where=name + "_id=" + data[name + "_id"]) if not users: raise Exception("user not found") return login.login(users[0]["id"])
from util.login import login import json import requests from datetime import timedelta, datetime if __name__ == '__main__': session = login() r = session.get('http://127.0.0.1:8000/training/contest/') problems = session.get('http://127.0.0.1:8000/training/problem/').json() teams = set() teams_id = [ [2, '试炼者'], [3, '我不知道.png'], [5, '未闻WA'], [7, '将来我一定比你聪明比你强'], [9, '奔跑的小菜鸡'], [12, '火锅队'], [14, '路人队伍的养成方法'], [15, '我们不会起名'], [17, '周末早上请不要训练'], [19, '从前往后做'], [20, '神奈川冲浪里'], [4, '仰望星空'], [10, '铲车人'], [1, '苍响'], [18, '普通攻击是WA而且触发TLE还能RE的弟弟你喜欢吗'], [8, '大吉大利,今晚吃 mian();'], [16, '地址过低'], [11, '辉夜大小姐想让我AC'], [13, '合法字符串'],
def snow(ctx, debug, format): ctx.obj["BASE_URL"] = login.BASE_URL ctx.obj["s"] = login.login() ctx.obj["debug"] = debug ctx.obj["format"] = format pass
import os import logging import subprocess import sys from util import filepaths from util import images from util import login # Getting all file paths in target directory. gopath = os.getenv('GOPATH') directory = '/src/k8s.io/kubernetes/test/e2e' filepaths = filepaths.get_filepaths(gopath + directory) logging.basicConfig(level=logging.WARNING) logging.info('Walking through directory {}'.format(directory)) success, registry, username, password = login.login() if success != True: sys.exit(1) # Getting Kubernetes version. os.chdir(gopath + directory) version = subprocess.check_output(['git', 'describe']).decode('utf-8').rstrip() logging.info('The current version of Kubernetes is {}'.format(version)) # Getting all gcr images in the files. gcr_images = images.get_gcr_images(filepaths) # Pulling images from gcr, tagging the image and pushing to daocloud registry. success = images.upload_daocloud_images(gcr_images, registry, username) if success != True: sys.exit(1)
def handle_session(api): if api.get('login_required'): return login() else: return requests.Session()
def crawl(): session = login() r = requests.get('http://codeforces.com/api/contest.list') r = json.loads(r.text) r = r['result'] print(r[0]) for contest in r: id = contest['id'] if id <= 140: continue params = { 'contest_id': contest['id'], 'name': contest['name'], 'type': contest['type'], 'start_time': contest['startTimeSeconds'], 'duration_time_second': contest['durationSeconds'], 'division': 'Unknown', 'division_comment': 'Too old.', } # r = requests.get('http://127.0.0.1:8000/codeforces/update_contest', params=params) # print(r.text) elif id <= 581: continue print(id, contest['name'], end=' ') path = os.path.join('rating_change', f'{id}.json') # if not os.path.isfile(path): # result = requests.get(f'http://codeforces.com/api/contest.ratingChanges?contestId={id}') # with open(path, 'w') as fpout: # fpout.write(result.text) params = { 'contest_id': contest['id'], 'name': contest['name'], 'type': contest['type'], 'start_time': contest['startTimeSeconds'], 'duration_time_second': contest['durationSeconds'], } with open(path, 'r') as fpin: result = json.load(fpin) unrated_message = 'Rating changes are unavailable for this contest' if result['status'] == 'FAILED' and unrated_message in result[ 'comment']: params['division'] = 'Unknown' params['division_comment'] = unrated_message + '.' else: bound = 1700 rating_change = result['result'] old_ratings = [ change['oldRating'] for change in rating_change ] if len(old_ratings) == 0: params['division'] = 'Unknown' params['division_comment'] = 'Technically unrated?' else: params['division_comment'] = 'No comment.' min_rating = min(old_ratings) max_rating = max(old_ratings) if bound - 10 <= max_rating < bound: params['division'] = 'Div. 2' elif max_rating < bound - 10: params['division'] = 'Unknown' params['division_comment'] = 'Unknown error.' elif min_rating < bound: params['division'] = 'Div. 1 + 2' else: params['division'] = 'Div. 1' # r = requests.get('http://127.0.0.1:8000/codeforces/update_contest', params=params) # print(r.text) elif id <= 976: continue print(id, contest['name'], end=' ') path = os.path.join('rating_change', f'{id}.json') # if not os.path.isfile(path): # result = requests.get(f'http://codeforces.com/api/contest.ratingChanges?contestId={id}') # with open(path, 'w') as fpout: # fpout.write(result.text) params = { 'contest_id': contest['id'], 'name': contest['name'], 'type': contest['type'], 'start_time': contest['startTimeSeconds'], 'duration_time_second': contest['durationSeconds'], } with open(path, 'r') as fpin: result = json.load(fpin) unrated_message = 'Rating changes are unavailable for this contest' if result['status'] == 'FAILED': if unrated_message in result['comment']: params['division'] = 'Unknown' params['division_comment'] = unrated_message + '.' else: params['division'] = 'Unknown' params['division_comment'] = result['comment'] else: bound = 1900 rating_change = result['result'] old_ratings = [ change['oldRating'] for change in rating_change ] if len(old_ratings) == 0: params['division'] = 'Unknown' params['division_comment'] = 'Technically unrated?' else: params['division_comment'] = 'No comment.' min_rating = min(old_ratings) max_rating = max(old_ratings) if bound - 10 <= max_rating < bound: params['division'] = 'Div. 2' elif max_rating < bound - 10: params['division'] = 'Unknown' params['division_comment'] = 'Unknown error.' elif min_rating < bound: params['division'] = 'Div. 1 + 2' else: params['division'] = 'Div. 1' r = requests.get('http://127.0.0.1:8000/codeforces/update_contest', params=params) print(r.text) elif id <= 1351: continue print(id, contest['name'], end=' ') path = os.path.join('rating_change', f'{id}.json') # if not os.path.isfile(path): # result = requests.get(f'http://codeforces.com/api/contest.ratingChanges?contestId={id}') # with open(path, 'w') as fpout: # fpout.write(result.text) params = { 'contest_id': contest['id'], 'name': contest['name'], 'type': contest['type'], 'start_time': contest['startTimeSeconds'], 'duration_time_second': contest['durationSeconds'], } with open(path, 'r') as fpin: result = json.load(fpin) unrated_message = 'Rating changes are unavailable for this contest' if result['status'] == 'FAILED': if unrated_message in result['comment']: params['division'] = 'Unknown' params['division_comment'] = unrated_message + '.' else: params['division'] = 'Unknown' params['division_comment'] = result['comment'] else: bound1 = 1900 bound2 = 2100 bound3 = 1600 rating_change = result['result'] old_ratings = [ change['oldRating'] for change in rating_change ] if len(old_ratings) == 0: params['division'] = 'Unknown' params['division_comment'] = 'Technically unrated?' else: params['division_comment'] = 'No comment.' min_rating = min(old_ratings) max_rating = max(old_ratings) if bound1 - 10 <= max_rating < bound1 or bound2 - 10 <= max_rating < bound2: params['division'] = 'Div. 2' elif bound3 - 10 <= max_rating < bound3: params['division'] = 'Div. 3' elif max_rating < bound3 - 10: params['division'] = 'Unknown' params['division_comment'] = 'Unknown error.' elif min_rating < bound3: params['division'] = 'Div. 1 + 2' else: params['division'] = 'Div. 1' r = requests.get('http://127.0.0.1:8000/codeforces/update_contest', params=params) print(r.text) else: print(id, contest['name'], end=' ') path = os.path.join('../data/codeforces/rating_change', f'{id}.json') if not os.path.isfile(path): result = requests.get( f'http://codeforces.com/api/contest.ratingChanges?contestId={id}' ) with open(path, 'w') as fpout: fpout.write(result.text) params = { 'id': contest['id'], 'name': contest['name'], 'type': contest['type'], 'start_time': datetime.fromtimestamp(contest['startTimeSeconds']).strftime( '%Y-%m-%dT%H:%M:%S+08:00'), 'duration_time_second': contest['durationSeconds'], } with open(path, 'r') as fpin: result = json.load(fpin) unrated_message = 'Rating changes are unavailable for this contest' if result['status'] == 'FAILED': if unrated_message in result['comment']: params['division'] = 'Unknown' params['division_comment'] = unrated_message + '.' else: params['division'] = 'Unknown' params['division_comment'] = result['comment'] else: bound1 = 1900 bound2 = 2100 bound3 = 1600 bound4 = 1400 rating_change = result['result'] old_ratings = [ change['oldRating'] for change in rating_change ] if len(old_ratings) == 0: params['division'] = 'Unknown' params['division_comment'] = 'Technically unrated?' else: params['division_comment'] = 'No comment.' min_rating = min(old_ratings) max_rating = max(old_ratings) if bound1 - 10 <= max_rating < bound1 or bound2 - 10 <= max_rating < bound2: params['division'] = 'Div. 2' elif bound3 - 10 <= max_rating < bound3: params['division'] = 'Div. 3' elif bound4 - 10 <= max_rating < bound4: params['division'] = 'Div. 4' elif max_rating < bound4 - 10: params['division'] = 'Unknown' params['division_comment'] = 'Unknown error.' elif min_rating < bound4: params['division'] = 'Div. 1 + 2' else: params['division'] = 'Div. 1' print(params) r = session.post('http://127.0.0.1:8000/codeforces/contest/', data=params) print(r.text)
def snow(ctx, debug): ctx.obj["BASE_URL"] = login.BASE_URL ctx.obj["s"] = login.login() ctx.obj["debug"] = debug pass