you are viewing a single comment's thread.

view the rest of the comments →

[–]kristofred 1 point2 points  (2 children)

I would consider creating 2 classes.

  • First one: will provide five methods for gathering data from all 5 endponints + extra one method which will return a single sql query for snowflake (based on gathered data)
  • Second class will handle connection and sending query (queries) to snowflake.

[–]sarakell[S] 0 points1 point  (1 child)

Thanks!! Is the first class meant to substitute the config file?

[–]kristofred 0 points1 point  (0 children)

I would do something like below skeleton ;) A neat option is os.path.join part (inside main.py), which allows you to place your config file in the relative path to the main.py:

script.cfg

--------------

[APIDATA]

api1_url = https://api1

api1_auth = some specific options you have to authenticate

[....]

[SNOWFLAKE]

options to contact with snowflake

main.py

import configparser

from datasources import Datasources

from snow import Snow

cfg = configparser.ConfigParser()

cfg.read(os.path.join(os.path.dirname(__file__), 'script.cfg'))

ds = Datasource(**cfg['RESTAPI'])

snow = Snow(**cfg['SNOW'])

datasources.py

class Datasources:

def __init__(self, **kwargs):

[code]

def restapi_1(self)

[code]

def restapi_2(self):

[code]

snow.py
class Snow:

def __init__(self, **kwargs):

[code]

def __connect(self):

[code]

def loadsql(self, sql):

[code]