Skip to content

Instantly share code, notes, and snippets.

@Mayfly277
Created April 10, 2018 21:15
Show Gist options
  • Save Mayfly277/fa1aca7c6245d43873364a112517cc78 to your computer and use it in GitHub Desktop.
Save Mayfly277/fa1aca7c6245d43873364a112517cc78 to your computer and use it in GitHub Desktop.
#! /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