Пример #1
0
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))
# 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")
Пример #3
0
# coding=utf-8
import time

from metaappscriptsdk import MetaApp

META = MetaApp()

# Станартный вариант
total = 125
bulk_log = META.bulk_log(u'Моя пачка', total, 1)

for idx in range(total):
    bulk_log.try_log_part()
    time.sleep(1)
bulk_log.finish()

# На частых но возможно долгих процессах
bulk_log = META.bulk_log(u'Моя пачка', total, 1)

for idx in range(total):
    bulk_log.try_log_part(with_start_message=False)
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 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
        }
Пример #6
0
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
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))
Пример #8
0
import os
from metaappscriptsdk import MetaApp

META = MetaApp()
log = META.log

MediaService = META.MediaService

resp = MediaService.info('5665d822-2edb-48b8-85a5-817043900a9a')
print(u"resp = %s" % str(resp))
# resp = {'id': '5665d822-2edb-48b8-85a5-817043900a9a', 'name': 'load_data_sample.tsv', 'extension': 'tsv', 'mime': 'text', 'url': None, 'creationTime': '2017-11-08T16:45:00Z', 'userId': 4501, 'fileSize': 256, 'info': {'test': True}, 'private': True, 'downloadUrlPart': '/api/meta/v1/media/d/5665d822-2edb-48b8-85a5-817043900a9a'}
Пример #9
0
from metaappscriptsdk import MetaApp

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

export = META.ExportService
# res = export.export_page(58, 3203, ["res"], export_format="html")
# print(u"res = %s" % str(res))

res_ds = export.export_data_source('e4082545-7388-4e2c-893f-3c0124fc5d26')
print(u"res_ds = %s" % str(len(res_ds['rows'])))
Пример #10
0
from metaappscriptsdk import MetaApp

META = MetaApp(starter_api_url="http://s2.meta.vmc.loc:28341")

ret = META.StarterService.submit("adptools.clear_logs", {})
print(u"ret = %s" % str(ret))
Пример #11
0
# 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))
Пример #12
0
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

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))

Пример #15
0
import logging

from metaappscriptsdk import MetaApp

META = MetaApp(debug=False)
log = META.log

e = Exception("Русский текст")
log.error("Моя ошибка", {"e": e})

log.set_entity('campaign_id', -1)
log.set_entity('test', True)
log.warning('Do warning log', {"count": 1, "mycontextParam": [1, 3, 4]})
log.info('Info log')
log.error('Info log')

logging.info('Default logging')

log.remove_entity('test')
log.info('Info log2')
Пример #16
0
from metaappscriptsdk import MetaApp

META = MetaApp()
log = META.log

META.auth_user_id = 10191
result = META.MediaService.download("93ed70c9-2aa9-4fc6-971e-b41619c46f30")
print(u"result.content = %s" % str(result.content))
import os
from metaappscriptsdk 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')
import os
from metaappscriptsdk import MetaApp

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)
Пример #19
0
import time

from metaappscriptsdk import MetaApp

META = MetaApp()

# Самый простой вариант без знания об общем количестве элементов
bulk_log = META.bulk_log(u'Моя пачка')
for idx in range(100):
    if bulk_log.try_log_part():
        print(u"bulk_log.get_percent_done() = %s" % str(bulk_log.get_percent_done()))
    time.sleep(1)
bulk_log.finish()


# Стандартный вариант
total = 125
bulk_log = META.bulk_log(u'Моя пачка', total, 1)

for idx in range(total):
    if bulk_log.try_log_part():
        print(u"bulk_log.get_percent_done() = %s" % str(bulk_log.get_percent_done()))
    time.sleep(1)

bulk_log.finish()

# На частых но возможно долгих процессах
bulk_log = META.bulk_log(u'Моя пачка', total, 1)

for idx in range(total):
    bulk_log.try_log_part(with_start_message=False)