fedora-infra / supybot-fedora

Fedora plugin for Supybot
20 stars 23 forks source link

a nextmeeting command #9

Closed ralphbean closed 10 years ago

ralphbean commented 10 years ago

add a .nextmeeting command that queries fedocal and tries to figure out how long until the next scheduled meeting (and what its about and what channel its in).

This would be super useful for bot maintenance to know when we can take the bot down for maintenance and stuff.

pypingou commented 10 years ago

Let's wait for fedocal 0.2.0 has the API is rewritten in it

ralphbean commented 10 years ago

So that API is in now. We can access the data we need with a query like this one:

$ http --json get https://apps.fedoraproject.org/calendar/api/meetings location==\#fedora-meeting
pypingou commented 10 years ago

For the record, I have tried to harmonize the locations to use fedora-meeting@irc.freenode.net looks like I need to do a new pass, otherwise the # gives problems with urls :)

ralphbean commented 10 years ago

Messing around with the api:

#!/usr/bin/env python

import arrow
import datetime
import requests

def future_meetings(channel):
    response = requests.get(
        'https://apps.fedoraproject.org/calendar/api/meetings',
        params=dict(
            location='%s@irc.freenode.net' % channel,
        )
    )

    data = response.json()
    now = datetime.datetime.utcnow()

    for meeting in data['meetings']:
        string = meeting['meeting_date'] + " " + meeting['meeting_time_start']
        dt = datetime.datetime.strptime(string, "%Y-%m-%d %H:%M:%S")

        if now < dt:
            yield dt, meeting

def print_next_meetings(channel, n=3):
    meetings = list(future_meetings(channel))[:n]
    for date, meeting in meetings:
        print "The next meeting in #%s is %s starting %s" % (
            channel,
            meeting['meeting_name'],
            arrow.get(date).humanize(),
        )

if __name__ == '__main__':
    print_next_meetings('fedora-meeting')