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', {})
        camp['counter']['ads'] = res['ads_cnt']

        res = storage_db.one(
            """
            SELECT count(1) as phrases_cnt
            FROM #shard."conditionsPhrases"
            INNER JOIN #shard.ads USING("adLocalId")
            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['counter']['phrases'] = res['phrases_cnt']
    print(pretty_json(camps))
finally:
    log.info('finish')
Example #2
0
""")
# Выдаст 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))

for r in dr['rows']:
    print("\n")
    print(u"r['id'] = %s" % r['id'])
    print(u"r['name'] = %s" % r['name'])
    print(u"r['info'] = %s" % pretty_json(r['info']))

db_adhands_ui = META.db("adhands_ui")
dr = db_adhands_ui.query(
    """
    SELECT id, name
    FROM user
    WHERE name LIKE :uname
    AND id IN ( :ids )
    ORDER BY name
# coding=utf-8
import base64

from metaappscriptsdk import MetaApp, pretty_json

META = MetaApp(meta_url="http://localhost:8080")
log = META.log

#
# Вы можете установить ID пользователя, от лица которого будут работать запросы
# Это полезно, когда вам надо сгенерировать приватный файл в фоновом режиме.
# Это user_id вы можете передать и прочитать из поля data в task
#
META.auth_user_id = 3503

YOUR_FILE_CONTENT_BASE64 = base64.b64encode(b'Custom user file').decode(
    "utf-8")
# Получаете инстанс сервиса и делаете запрос к нему
result = META.MediaService.persist_one(
    file_base64_content=YOUR_FILE_CONTENT_BASE64,
    filename="req.txt",
    extension="txt",
    mime="plain/text")
print(u"result = %s" % result)
# Формат ответа стандартный для меты
first = result['rows'][0]
print(u"result['rows'][0]['url'] = %s" % first['url'])
print(u"first = %s" % first)
print(u"result = %s" % pretty_json(result))
Example #4
0
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
        }
    }
}

schema_data = source_db.schema_data(configuration)
print(pretty_json(schema_data))
source_db.download_data(configuration, output_file=OUTFILE)

configuration = {
    "load": {
        "destinationTable": {
            "schema": destination_tbl_schema,
            "table": destination_tbl_name
        },
        "schema": schema_data['schema']
    }
}
upload_file = open(OUTFILE, 'rb')
destination_db.upload_data(upload_file, configuration)

t2 = datetime.now()