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))
# coding=utf-8 from metaappscriptsdk import MetaApp, 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")
import os from metaappscriptsdk import MetaApp META = MetaApp(meta_url="http://localhost:8080") log = META.log os.chdir(os.path.dirname(os.path.abspath(__file__))) __DIR__ = os.getcwd() + "/" configuration = { "download": { "dbQuery": { "command": "SELECT * FROM products WHERE productname ilike '%Gula%' LIMIT 1000" } } } db = META.db("nw") schema_data = db.schema_data(configuration) print(u"schema_data = %s" % str(schema_data))
from metaappscriptsdk import MetaApp from metaappscriptsdk.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))
import time from metaappscriptsdk import MetaApp META = MetaApp() log = META.log META.worker.debug_tasks = [{"data": {}}] meta_samples_db = META.db("meta_samples") def process_org(org): log.info("process_org", {"org": org}) time.sleep(5) @META.worker.single_task def main(task): log.info("task", {"task": task}) orgs = meta_samples_db.all("SELECT * FROM organization ORDER BY name") for org in orgs: process_org(org)
# coding=utf-8 from metaappscriptsdk import MetaApp, 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))
import os from metaappscriptsdk import MetaApp, pretty_json from datetime import datetime 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 metaappscriptsdk import MetaApp from metaappscriptsdk.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 metaappscriptsdk import MetaApp from datetime import datetime from metaappscriptsdk.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 }