Exemplo n.º 1
0
 def add(cls, title):
     Logger.error("add: title={title}".format(title=title))
     connection = cls.__get_db()
     try:
         with connection.cursor() as cursor:
             sql = "INSERT INTO notes(title, created) VALUES(%s, now())"
             cursor.execute(sql, (title,))
             insert_id = connection.insert_id()
         connection.commit()
         return insert_id
     finally:
         connection.close()
Exemplo n.º 2
0
 def add(cls, schedule):
     Logger.error("add: schedule={schedule}".format(schedule=schedule))
     connection = cls.__get_db()
     try:
         with connection.cursor() as cursor:
             keys = list(
                 set(cls.__schema).intersection(set(schedule.keys())) -
                 {'id'})
             sql = "INSERT INTO schedules({keys}, created) " \
                   "VALUES({columns}, now())".format(keys=','.join(keys), columns=','.join(map(lambda x: "%s", keys)))
             values = []
             for key in keys:
                 values.append(schedule[key])
             Logger.debug("sql={sql}, values={values}".format(
                 sql=sql, values=values))
             cursor.execute(sql, values)
             insert_id = connection.insert_id()
         connection.commit()
         return insert_id
     finally:
         connection.close()
Exemplo n.º 3
0
 def add(cls, chart):
     Logger.error("add: chart={chart}".format(chart=chart))
     connection = cls.__get_db()
     try:
         with connection.cursor() as cursor:
             sql = "INSERT INTO charts(note, title, resource, graph, query_type, query, query_params) VALUES(%s, " \
                   "%s, %s, %s, %s, %s, %s) "
             cursor.execute(sql, (
                 chart['note'],
                 chart['title'],
                 chart['resource'],
                 json.dumps(chart['graph']),
                 chart['query_type'],
                 chart['query'],
                 json.dumps(chart['query_params']),
             ))
             insert_id = connection.insert_id()
         connection.commit()
         return insert_id
     finally:
         connection.close()
Exemplo n.º 4
0
 def update(cls, schedule):
     Logger.error("update: schedule={schedule}".format(schedule=schedule))
     connection = cls.__get_db()
     try:
         with connection.cursor() as cursor:
             keys = list(
                 set(cls.__schema).intersection(set(schedule.keys())))
             sql = "UPDATE schedules SET {key_val} WHERE id={id}".format(
                 key_val=','.join(
                     map(lambda x: "{key}=%s".format(key=x), keys)),
                 id=schedule['id'])
             values = []
             for key in keys:
                 values.append(schedule[key])
             Logger.debug("sql={sql}, values={values}".format(
                 sql=sql, values=values))
             cursor.execute(sql, values)
             insert_id = connection.insert_id()
         connection.commit()
         return insert_id
     finally:
         connection.close()
Exemplo n.º 5
0
    def query(self, job_id, query_type, query, query_params=None):
        Logger().debug(
            "query_async: job_id={job_id}, query_type={query_type}, query_params={query_params}"
            .format(job_id=job_id,
                    query_type=query_type,
                    query_params=query_params))
        job = self.__get_job(job_id=job_id)
        if not job:
            job = self.__get_client().run_async_query(
                job_name=job_id,
                query=self.QueryBuilder.get_query(config=self.__config,
                                                  query_type=query_type,
                                                  query=query,
                                                  query_params=query_params))
            job.use_legacy_sql = False
            try:
                query_params = json.loads(
                    BigQueryAdapter.QueryBuilder.replace_patterns(
                        query=query_params))
                Logger().debug("query_params={query_params}".format(
                    query_params=query_params))
                if 'destinationTable' in query_params:
                    client = self.__get_client()
                    dataset = client.dataset(
                        dataset_name=query_params['destinationTable']
                        ['dataset'])
                    job.destination = dataset.table(
                        name=query_params['destinationTable']['name'])
                    if 'write_disposition' in query_params['destinationTable']:
                        job.write_disposition = query_params[
                            'destinationTable']['write_disposition']
            except:
                Logger.error("invalid query params:{query_params}".format(
                    query_params=query_params))

            job.begin()
        return job
Exemplo n.º 6
0
def oauth2check():
    if 'user' not in session:
        Logger.error("Credentials not exists")
        return redirect(__getFlow().step1_get_authorize_url())
    else:
        return None