Created
April 10, 2018 21:15
-
-
Save Mayfly277/fa1aca7c6245d43873364a112517cc78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/python | |
# -*- coding: utf-8 -*- | |
import requests | |
import datetime | |
def print_ctf(ctfs): | |
key_list = ( | |
('title', 40), | |
('onsite', 10), | |
('start', 12), | |
('finish', 12), | |
('url', 40), | |
('format', 20), | |
('participants', 12), | |
('ctftime_url', 40) | |
) | |
head = '' | |
for (header, format) in key_list: | |
f = '| {:' + str(format)[0:format-2] + 's}' | |
head += f.format(str(header)) + ' ' | |
print head | |
for ctf in ctfs: | |
line = '' | |
for (key, format) in key_list: | |
f = '| {:' + str(format) + 's}' | |
if not isinstance(ctf[key], str): | |
line += f.format(str(ctf[key])[0:format-2]) + ' ' | |
else: | |
line += f.format(ctf[key].encode('utf-8')[0:format-2]) + ' ' | |
print line | |
def call_api(start, finish, limit=100): | |
params = { | |
'limit': limit, | |
'start': start, | |
'finish': finish} | |
url = 'https://ctftime.org/api/v1/events/' | |
r = requests.get(url, params=params) | |
return r.json() | |
def main(): | |
start = datetime.datetime.now() | |
end = start + datetime.timedelta(days=10) | |
r = call_api(start.strftime("%s"), end.strftime("%s")) | |
print_ctf(r) | |
return 'ok' | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment