Advertisement
Es7evam

Untitled

May 12th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. def list_events(self):
  2. fmtstr = '%Y-%m-%dT%H:%M:%S'
  3.  
  4. now = int(time.time())
  5. nextweek = now + 604800 * 10 #*10 for testing
  6.  
  7. f = urllib.request.urlopen('https://ctftime.org/api/v1/events/?limit=20&start={}&finish={}'.format(now, nextweek))
  8. l = json.load(f)
  9. newL = []
  10.  
  11. for o in l:
  12. if not o['onsite']:
  13. o['start'] = datetime.datetime.strptime(o['start'][:-6], fmtstr)
  14. o['finish'] = datetime.datetime.strptime(o['finish'][:-6], fmtstr)
  15. newL.append(o)
  16.  
  17. return newL
  18.  
  19.  
  20. def upcoming(self, bot, update):
  21. l = self.list_events()
  22. msg = "*Upcoming Online Events:* \n"
  23. for o in l:
  24. msg += '\n' + '[' + o['title'] + ']' + '(' + o['url'] + ') ' + '\n'
  25. msg += datetime.datetime.strptime(o['start'][:-6], fmtstr) + '\n'
  26.  
  27. 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