Ejemplo n.º 1
0
def initInsertCalendars(client, principal, homeset, calendar_list):
    #print(client.hostname, client.auth[0], client.auth[1], homeset.homesetUrl)
    result = db_connector.query(
        "INSERT INTO account VALUES (%s, %s, %s, %s)",
        (client.hostname, client.auth[0], client.auth[1], homeset.homesetUrl))

    for calendar in calendar_list:
        result2 = db_connector.query(
            "INSERT INTO calendar VALUES (%s, %s, %s, %s, %s, %s)",
            (client.hostname, client.auth[0], calendar.calendarId,
             calendar.calendarUrl, calendar.calendarName, calendar.cTag))

        evt_list = calendar.getAllEvent()
        req_headers = {"Depth": "1", "Authorization": client.auth[0]}

        for evt in evt_list:
            if evt.eventId.find(".ics"):
                evt_name, evt_start_dt, evt_end_dt, evt_loc = icsParser(
                    client.hostname, calendar.calendarId, evt.eventId,
                    req_headers)
                result3 = db_connector.query(
                    "INSERT INTO event "
                    "(host_name, user_id, calendar_id, event_id, event_url, event_name, start_dt, end_dt, location, e_tag) "
                    "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                    (client.hostname, client.auth[0], calendar.calendarId,
                     evt.eventId, evt.eventUrl, evt_name, evt_start_dt,
                     evt_end_dt, evt_loc, evt.eTag))
Ejemplo n.º 2
0
def getAllEvent():
    result = db_connector.query("select * from event")
    rows = util.fetch_all_json(result)

    for row in rows:
        print(row)
        print(type(row))
Ejemplo n.º 3
0
def updateCalendar(homeset_cal_id, cal_id, add_ics_list, update_ics_list,
                   delete_ics_list):
    # Get auth
    res = db_connector.query(
        "select user_base64,user_id,host_name from account where host_name=%s",
        (homeset_cal_id, ))
    rows = util.fetch_all_json(res)
    if rows[0]['user_base64'] is None:
        return  #handle error message
    user_id = rows[0]['user_id']
    host_name = rows[0]['host_name']
    auth = "Basic " + rows[0]['user_base64']
    req_headers = {"Depth": "1", "Authorization": auth}

    # Add event
    if add_ics_list is not None:
        addEvent(homeset_cal_id, cal_id, user_id, add_ics_list, req_headers)
    # Update event (Overwrite)
    if update_ics_list is not None:
        updateEvent(homeset_cal_id, cal_id, update_ics_list, req_headers)
    # Delete event
    if delete_ics_list is not None:
        deleteEvent(delete_ics_list)
Ejemplo n.º 4
0
def deleteEvent(host_name, user_id, calendar_id, event_url):
    result = db_connector.query(
        "delete from event where host_name=%s and user_id = %s and calendar_id = %s and event_url = %s",
        (host_name, user_id, calendar_id, event_url))
Ejemplo n.º 5
0
def updateEvent(host_name, user_id, calendar_id, event_url, e_tag):
    result = db_connector.query(
        "update event set e_tag = %s where host_name=%s and user_id = %s and calendar_id = %s and event_url = %s",
        (e_tag, host_name, user_id, calendar_id, event_url))
Ejemplo n.º 6
0
def addEvent(host_name, user_id, calendar_id, event_url, e_tag):
    result = db_connector.query(
        "insert into event (host_name, user_id, calendar_id, event_id, event_url, e_tag) values (%s, %s, %s, %s, %s, %s)",
        (host_name, user_id, calendar_id, util.splitIdfromUrl(event_url),
         event_url, e_tag))
Ejemplo n.º 7
0
def updateCTag(host_name, user_id, calendar_id, c_tag):
    result = db_connector.query(
        "update calendar set c_tag = %s where host_name=%s and user_id = %s and calendar_id = %s",
        (c_tag, host_name, user_id, calendar_id))
Ejemplo n.º 8
0
def selectEvents(host_name, user_id, calendar_id):
    result = db_connector.query(
        "select * from event where host_name = %s and user_id = %s and calendar_id= %s",
        (host_name, user_id, calendar_id))
    rows = util.fetch_all_json(result)
    return rows
Ejemplo n.º 9
0
def selectAllCalendar():
    result = db_connector.query("select * from calendar natural join account")
    rows = util.fetch_all_json(result)
    return rows
Ejemplo n.º 10
0
def selectAllAccount():
    result = db_connector.query("select * from account")
    rows = util.fetch_all_json(result)
    return rows