Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def list_events(self):
- fmtstr = '%Y-%m-%dT%H:%M:%S'
- now = int(time.time())
- nextweek = now + 604800 * 10 #*10 for testing
- f = urllib.request.urlopen('https://ctftime.org/api/v1/events/?limit=20&start={}&finish={}'.format(now, nextweek))
- l = json.load(f)
- newL = []
- for o in l:
- if not o['onsite']:
- o['start'] = datetime.datetime.strptime(o['start'][:-6], fmtstr)
- o['finish'] = datetime.datetime.strptime(o['finish'][:-6], fmtstr)
- newL.append(o)
- return newL
- def upcoming(self, bot, update):
- l = self.list_events()
- msg = "*Upcoming Online Events:* \n"
- for o in l:
- msg += '\n' + '[' + o['title'] + ']' + '(' + o['url'] + ') ' + '\n'
- msg += datetime.datetime.strptime(o['start'][:-6], fmtstr) + '\n'
- bot.send_message(chat_id=update.message.chat_id, text=msg, parse_mode=ParseMode.MARKDOWN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement