Skip to content

Instantly share code, notes, and snippets.

@thotypous
Created November 8, 2019 18:04
Show Gist options
  • Save thotypous/6c88a77d6903b2b20df420c6cac13cb8 to your computer and use it in GitHub Desktop.
Save thotypous/6c88a77d6903b2b20df420c6cac13cb8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from nizkctf.team import Team, SUBMISSIONS_FILE
from nizkctf.acceptedsubmissions import AcceptedSubmissions
from nizkctf.subrepo import SubRepo
from nizkctf.settings import Settings
import os
import subprocess
import requests
import datetime
import pytz
def get_timestamp(commit_id):
r = requests.get('https://api.github.com/repos/{}/commits/{}/pulls'.format(Settings.submissions_project, commit_id),
headers={'Accept': 'application/vnd.github.groot-preview+json'})
commit, = r.json()
created_at = commit['created_at']
return int(pytz.timezone('UTC').localize(
datetime.datetime.strptime(created_at, '%Y-%m-%dT%H:%M:%SZ')
).astimezone(pytz.timezone('America/Sao_Paulo')).timestamp())
for d, _, files in os.walk('submissions'):
if SUBMISSIONS_FILE in files:
team_id = d.replace('submissions/','')
blame = SubRepo().git(['blame', os.path.join(team_id, SUBMISSIONS_FILE)],
stdout=subprocess.PIPE)
blame = [x.split(b' ')[0].decode('ascii') for x in blame.split(b'\n')]
team = Team(id=team_id)
team_standing = AcceptedSubmissions().get_team_standing(team['name'])
for chall, commit_id in zip(team.submissions().challs(), blame):
chall_id = chall.id
if not chall_id in team_standing['taskStats']:
timestamp = get_timestamp(commit_id)
print(team['name'], chall_id, commit_id, timestamp)
AcceptedSubmissions().add(chall, team, accepted_time=timestamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment