Ejemplo n.º 1
0
def update_engineering_events():
    r = requests.get('http://engineering.columbia.edu/feeds/events')
    soup = BeautifulSoup(r.text)

    events = soup.find_all('item')
    user = User.query.filter(User.name == "Columbia Engineering").first()
    for event in events:
        current_soup = BeautifulSoup(event.renderContents())

        event_name = current_soup.find('title').text
        url = current_soup.find('link').get_text()
        u = urlparse.urlparse(url)
        event_id = urlparse.parse_qs(u.query)["id"][0]

        base = "http://calendar.columbia.edu/sundial/webapi/"
        ical_url = base + "iCalendar.php?EventID={}".format(event_id)
        url = base + "get.php?vt=detail&id={}&con=standalone".format(event_id)

        r_event = requests.get(ical_url)
        cal = Calendar.from_ical(r_event.text)

        cevent = Event.query.filter(Event.sundial_id == event_id).first()
        if cevent is None:
            cevent = Event(name=event_name, url=url, sundial_id=event_id,
                           user_id=user.id)

        # only one event in cal
        for event in cal.walk('vevent'):
            cevent.start = event.get('dtstart').dt.replace(tzinfo=None)
            cevent.end = event.get('dtend').dt.replace(tzinfo=None)
            cevent.description = event.get('description')
            cevent.location = event.get('location')

        db.session.add(cevent)
    db.session.commit()
Ejemplo n.º 2
0
async def get_individual_event(event, user):
    sundial_id = str(event['uid'])

    cevent = Event.query.filter(Event.sundial_id == sundial_id).first()
    if cevent is None:
        cevent = Event(sundial_id=sundial_id, user_id=user.id)

    cevent.name = event["summary"]
    cevent.description = event["description"]
    cevent.location = event.get('location')
    cevent.url = event.get("url")

    try:
        cevent.start = event["dtstart"].dt.replace(tzinfo=None)
    except TypeError:  # dtstart is a date, not a datetime
        cevent.start = event["dtstart"].dt

    try:
        cevent.end = event["dtend"].dt.replace(tzinfo=None)
    except TypeError:  # dtend is a date, not a datetime
        cevent.end = event["dtend"].dt
    except KeyError:  # no dtend
        pass

    return cevent
Ejemplo n.º 3
0
def update_fb_events():
    url = "https://graph.facebook.com/v2.3/"
    payload = {"access_token": FACEBOOK_ACCESS_TOKEN}

    for user_id, events in get_users().items():
        user = User.query.filter(User.fb_id == user_id).first()

        for chunk in utils.grouper(events):
            ids = ",".join(event_data["id"] for event_data in chunk)
            payload["ids"] = ids

            # new request to get complete information
            r = requests.get(url, params=payload)
            data = json.loads(r.text)

            for event_id, event_data in data.items():
                event = Event.query.filter(Event.fb_id == event_id).first()
                if event is None:
                    event = Event(fb_id=event_id)

                start = iso8601.parse_date(event_data["start_time"])
                event.start = start.replace(tzinfo=None)

                if "end_time" in event_data:
                    end = iso8601.parse_date(event_data["end_time"])
                    event.end = end.replace(tzinfo=None)

                event.user_id = user.id
                event.description = event_data.get("description", "")
                event.location = event_data.get('location', None)
                event.name = event_data['name']
                event.url = "https://www.facebook.com/" + event_data['id']

                db.session.add(event)
    db.session.commit()
Ejemplo n.º 4
0
async def get_individual_event(event, user):
    event_name = event.find('title').text
    url = event.find('link').get_text()
    u = urlparse.urlparse(url)
    event_id = urlparse.parse_qs(u.query)["id"][0]

    base = "http://calendar.columbia.edu/sundial/webapi/"
    ical_url = base + "iCalendar.php?EventID={}".format(event_id)
    url = base + "get.php?vt=detail&id={}&con=standalone".format(event_id)

    async with aiohttp.get(ical_url) as r_event:
        cal = Calendar.from_ical(await r_event.text())

    cevent = Event.query.filter(Event.sundial_id == event_id).first()
    if cevent is None:
        cevent = Event(name=event_name, url=url, sundial_id=event_id,
                       user_id=user.id)

    for event in cal.walk('vevent'):
        cevent.start = event.get('dtstart').dt.replace(tzinfo=None)
        cevent.end = event.get('dtend').dt.replace(tzinfo=None)
        cevent.description = event.get('description')
        cevent.location = event.get('location')
    return cevent