import os from metasdk import MetaApp META = MetaApp() log = META.log os.chdir(os.path.dirname(__file__)) __DIR__ = os.getcwd() + "/" configuration = { "download": { # "skipHeaders": True, Если не нужны заголовки "dbQuery": { "command": "SELECT * FROM products WHERE productname ilike '%Gula%' LIMIT 1000" } } } db = META.db("nw") db.download_data(configuration, output_file=__DIR__ + 'assets/out_products.tsv')
from metasdk import MetaApp, StarterService META = MetaApp() starter = StarterService(META, META.db("garpun_main"), "http://code.harpoon.lan:28341") res = starter.submit("Notice.DeactivateOldNotices", {"foo": "bar"}) print(u"res = %s" % str(res))
META = MetaApp() log = META.log os.chdir(os.path.dirname(os.path.abspath(__file__))) __DIR__ = os.getcwd() + "/" upload_file = open(__DIR__ + 'assets/load_data_sample.tsv', 'rb') configuration = { "load": { "destinationTable": { "schema": "public", "table": "xxx_ya_stat" }, "schema": { "fields": [ {"name": "Date", "type": "DATE"}, {"name": "Clicks", "type": "LONG"}, {"name": "Cost", "type": "DECIMAL"}, {"name": "AdNetworkType", "type": "TEXT"}, ] } } } db = META.db("meta_samples") result = db.upload_data(upload_file, configuration) print(u"result = %s" % str(result))
from metasdk import MetaApp from metasdk.utils import pretty_json META = MetaApp(meta_url="https://meta.realweb.ru") log = META.log log.info('start') try: db_general = META.db("garpun_main") camps = db_general.all(""" SELECT "adHandsCampaignId" as id, name, "accountId" as account_id, "campaignRemoteId", "engine" FROM global.campaigns WHERE "virtualCampaignId" > 0 LIMIT 2 """) for camp in camps: storage_db = META.db("garpun_storage", camp['account_id']) search_params = {"engine": camp['engine'], "camp_remote_id": camp['campaignRemoteId'],} res = storage_db.one(""" SELECT count(1) as ads_cnt FROM #shard.ads INNER JOIN #shard."campaigns" c USING("campaignLocalId") INNER JOIN #shard."virtualCampaigns" vc USING("virtualCampaignId") WHERE vc.engine=:engine::"enum_engineType" AND c."campaignRemoteId"=:camp_remote_id """, search_params) camp.setdefault('counter', {})
import os from metasdk import MetaApp from datetime import datetime from metasdk.utils import pretty_json t1 = datetime.now() META = MetaApp() log = META.log os.chdir(os.path.dirname(__file__)) __DIR__ = os.getcwd() + "/" source_db = META.db("adplatform") destination_db = META.db("iata") source_tbl_schema = "iata" source_tbl_name = "prices" destination_tbl_schema = "public" destination_tbl_name = "prices_copy" OUTFILE = __DIR__ + 'assets/out_' + source_tbl_name + '.tsv' configuration = { "download": { "dbQuery": { "command": "SELECT * FROM " + source_tbl_schema + "." + source_tbl_name }
from metasdk import MetaApp from metasdk.utils import pretty_json META = MetaApp() log = META.log # # Db.one # db_adplatform = META.db("adplatform") u = db_adplatform.one(""" SELECT id, name, info FROM users WHERE id = -1 LIMIT 1 """) # Выдаст None print(u"u = %s" % u) # # Db.query # db_adplatform = META.db("adplatform") dr = db_adplatform.query(""" SELECT id, name, info FROM users WHERE name ILIKE 'Андре%' ORDER BY name LIMIT 1 """) print(u"dr = %s" % pretty_json(dr))