Esempio n. 1
0
def get_emails():
    client_id = os.environ['client_id']
    client_secret = os.environ['client_secret']
    app_id = int(os.environ['projects_app_id'])
    app_token = os.environ['projects_token']
    oncall_project = int(os.environ['oncall_project_id'])

    c = api.OAuthAppClient(
        client_id,
        client_secret,
        app_id,
        app_token,
    )
    a = {"filters": {"item_id": oncall_project}}
    t = c.Item.filter(app_id, a)
    if t['filtered'] != 1:
        print "ERROR: Cannot find the project for Managed Services"
        return []

    sdm_field_id = 140858054
    emails = []
    for f in t['items'][0]['fields']:
        if f['field_id'] == sdm_field_id:
            for i in f['values']:
                emails += i['value']['mail']
            break
    return emails
Esempio n. 2
0
def get_phones():
    client_id = os.environ['podio_client_id']
    client_secret = os.environ['podio_client_secret']
    s_app_id = os.environ['podio_s_app_id']
    # Staffing app
    s_app_token = os.environ['podio_s_app_token']
    # Staffing token
    view_id = os.environ['podio_view_id']
    # This week on Call view
    field_id = os.environ['podio_field_id']
    # Assignment

    c = api.OAuthAppClient(
        client_id,
        client_secret,
        s_app_id,
        s_app_token,
    )
    item_id = c.Item.filter_by_view(s_app_id, view_id)['items'][0]['item_id']
    user_data = c.Item.values(item_id)

    phones = []
    for u in user_data:
        if 'external_id' in u and u['external_id'] == 'meeting-participants':
            for v in u['values']:
                if 'value' in v and 'phone' in v['value']:
                    phones += v['value']['phone']
    return phones
Esempio n. 3
0
 def _getClient(self, app_token=None):
     """
     Gets a client item from pypodio, from the app_id given to the podioApi object when it was created. Optionally it receives an app_token; in that case it doesn't need to fetch it from the database
     """
     if app_token is None:
         from . import models
         app_token = models.Aplicacion.objects.get(app_id=self.app_id).app_token
     return api.OAuthAppClient(settings.CLIENT_ID, settings.CLIENT_SECRET, self.app_id, app_token)
Esempio n. 4
0
def handler(event, context):
    client_id = os.environ['client_id']
    client_secret = os.environ['client_secret']
    s_app_id = int(os.environ['s_app_id'])  # Staffing app
    s_app_token = os.environ['s_app_token']  # Staffing token

    emails = get_emails()
    if len(emails) < 1:
        print "ERROR: Cannot get SDMs emails for alert"
        return {}

    c = api.OAuthAppClient(
        client_id,
        client_secret,
        s_app_id,
        s_app_token,
    )

    field_week_number = 140525289
    field_project = 140523653
    field_project_date = 140522955
    field_project_type = 140524037

    oncall_project = 772605447
    oncall_type = 4

    a = {
        "filters": {
            field_project: [oncall_project],
            field_project_type: [oncall_type],
            field_project_date: {
                "from": '+4dr',
                "to": '+4dr'
            }
        },
    }

    t = c.Item.filter(s_app_id, a)

    if int(t['filtered']) < 1:
        res = send_email(emails)
    else:
        res = {}

    return res
Esempio n. 5
0
                #if d[k][0].member:
                #session.merge(d[k][0].member) # add member from podio
                #d[k][0].member=d[k][0].member.item_id
                session.merge(d[k][0])
            session.commit()
            podio_client.Comment.create(
                'item',
                d[k][0].item_id, {
                    'value':
                    'Das Access Level wurde in der Schließsystemdatenbank aktualisiert.'
                },
                silent=False,
                hook=False)


if __name__ == '__main__':
    from database import create_session
    import sys
    podio_client = api.OAuthAppClient(config.podio_client_id,
                                      config.podio_client_secret,
                                      config.podio_app_id_nfc,
                                      config.podio_app_key_nfc)
    s = create_session(config.db)
    d, e = create_diff(s, podio_client, config.podio_app_id_nfc)
    if e:
        for x in e:
            print(x)
    if not e or '-f' in sys.argv:
        print('------------------')
        interactive_merge(s, d, podio_client)
Esempio n. 6
0
import os
from pypodio2 import api
from dotenv import load_dotenv
load_dotenv()
# Authenticate as App in podio, variables below contains a client object that
# allow us to do all the diferent requests to Podio API

#Client to do requests to "" app
podio_client_expedientes = api.OAuthAppClient(
    client_id=os.getenv("PODIO_CLIENT_ID"),
    client_secret=os.getenv("PODIO_CLIENT_SECRET"),
    app_id=os.getenv("PODIO_EXPEDIENTES_APP_ID"),
    app_token=os.getenv("PODIO_EXPEDIENTES_APP_TOKEN"),
)

#Client to do requests to "inasistencias" app
podio_client_inasistencias = api.OAuthAppClient(
    client_id=os.getenv("PODIO_CLIENT_ID"),
    client_secret=os.getenv("PODIO_CLIENT_SECRET"),
    app_id=os.getenv("PODIO_INASISTENCIAS_APP_ID"),
    app_token=os.getenv("PODIO_INASISTENCIAS_APP_TOKEN"),
)

#Client to do requests to "vacaciones" app
podio_client_vacaciones = api.OAuthAppClient(
    client_id=os.getenv("PODIO_CLIENT_ID"),
    client_secret=os.getenv("PODIO_CLIENT_SECRET"),
    app_id=os.getenv("PODIO_VACACIONES_APP_ID"),
    app_token=os.getenv("PODIO_VACACIONES_APP_TOKEN"),
)
Esempio n. 7
0
 def __init__(self): 
     print(cfg)
     self.c = api.OAuthAppClient(cfg['CLIENT_ID'], cfg['CLIENT_KEY'], cfg['APP_ID'], cfg['APP_KEY'])        
Esempio n. 8
0
# Restrict data access to the needed Minimum:
# Only columns, "ID", "Ablaufdatum", "Schluesselgewalt Lab",
# Only rows where 3rd column is non-empty.
# view must be shared with team, so that the API can access it.
podio_view_id = '51148009'

try:
    podio_app_token = os.environ['PODIO_NFC_APP_TOKEN']
    podio_client_secret = os.environ['PODIO_CLIENT_SECRET']
except:
    print("%s needs the following environment variables:" % sys.argv[0])
    print("  PODIO_NFC_APP_TOKEN (for nfc app %s)" % podio_app_id)
    print("  PODIO_CLIENT_SECRET (for client %s)" % podio_client_id)
    sys.exit(0)

podio = api.OAuthAppClient(podio_client_id, podio_client_secret, podio_app_id,
                           podio_app_token)


def fmt_value(field):
    val = []
    for v in field['values']:
        if field['type'] == 'text':
            val.append("'" + v['value'] + "'")
        elif field['type'] == 'category':
            val.append("'" + v['value']['text'] +
                       "' (id=%d)" % v['value']['id'])
        elif field['type'] == 'app':
            val.append("'" + v['value']['app']['name'] +
                       "' (app_id=%d, app_item_id=%d, title=%s)" %
                       (v['value']['app']['app_id'], v['value']['app_item_id'],
                        v['value']['title']))
Esempio n. 9
0
def lambda_handler(event, context):
'''
Out:
    {
        'primary': { !!Contact_info!! },
        'backup': { !!Contact_info!! },
        'manager': { !! Contact_info!! }
    }
'''
    global config

    contacts = {
        'primary': [],
        'backup': [],
        'manager': [],
        'itms': []
    }

    try:
        config = db.Table(config_table).get_item(Key={ 
                "Key": "Config" 
            })['Item']['Value']

        client_id       = config['podioClientID']
        client_secret   = config['podioClientSecret']
        s_app_id        = config['podioAppID']
        s_app_token     = config['podioAppToken']
        itms_call_start = datetime.strptime(config['itms_call_start'], "%H:%M").time()
        itms_call_end   = datetime.strptime(config['itms_call_end'], "%H:%M").time()
        now             = datetime.now(Eastern).time()
        always_4_oncall = config['always4oncall']
    
        field_project        = int(config['podioProjectFieldID'])
        field_project_date   = int(config['podioStaffingDateFieldID'])
        field_project_type   = int(config['podioStaffingTypeFieldID'])
        
        oncall_project = int(config['podioITMSProjectID'])
        oncall_type    = int(config['podioTypeOnCall'])
        default_contact = config['defaultContact']
    
    
        c = api.OAuthAppClient(
            client_id, 
            client_secret, 
            s_app_id, 
            s_app_token,
        )
        itms_staffing = c.Item.filter(s_app_id, attributes={
            'filters': {
                field_project     : [oncall_project],
                field_project_date: {"from": '+0dr', "to": '+0dr' }
            }
        })
        call_4_oncall = always_4_oncall or (now < itms_call_start  or now > itms_call_end)

        itms_primary_data = None
        itms_second_data = None
        itms_escalation_data = None
        oncall_primary_data = None
        oncall_second_data = None
        oncall_escalation_data = None
        for s in itms_staffing['items']:
            define_callee = False
            primary_data = []
            second_data = []
            escalation_data = []
            expired_staffing = False
            project_type = 0
            for f in s['fields']:
                if f['field_id'] == field_project_type:
                    project_type = int(f['values'][0]['value']['id'])
                elif f['external_id'] == 'meeting-participants':
                    primary_data = extract_contact(f)
                elif f['external_id'] == 'second-resource':
                    second_data = extract_contact(f)
                elif f['external_id'] == 'escalation-point':
                    escalation_data = extract_contact(f)
                elif f['field_id'] == field_project_date:
                    d = datetime.strptime(f['values'][0]['end_utc'], '%Y-%m-%d %H:%M:%S')
                    expired_staffing = d < datetime.now()

            if expired_staffing:
                continue

            if project_type == oncall_type:
                oncall_primary_data = primary_data
                oncall_second_data = second_data
                oncall_escalation_data = escalation_data
            else:
                itms_primary_data = primary_data
                itms_second_data = second_data
                itms_escalation_data = escalation_data

        #oncall_primary_data = None
        #itms_primary_data = None
        if call_4_oncall:
            contacts['primary'] = notnone(oncall_primary_data,    itms_primary_data,    [default_contact])
            contacts['backup']  = notnone(oncall_second_data,     itms_second_data,     [default_contact])
            contacts['manager'] = notnone(oncall_escalation_data, itms_escalation_data, [default_contact])
        else:
            contacts['primary'] = notnone(itms_primary_data,    oncall_primary_data,    [default_contact])
            contacts['backup']  = notnone(itms_second_data,     oncall_second_data,     [default_contact])
            contacts['manager'] = notnone(itms_escalation_data, oncall_escalation_data, [default_contact])

    except Exception as e:
        print "ERROR(lambda_handler): %s %s" % (type(e).__name__, e.args[0])

    return contacts