Last active
December 5, 2020 22:58
-
-
Save ololosha2020/6e38b6ee9feb1c0aa6041da56644b925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests, json\n", | |
"\n", | |
"# (OAuth ) не трогать менять только токен\n", | |
"token='OAuth AgAAAABKF86eAAa_eV3weIJd_EV3k9BwKZMfrAs'\n", | |
"\n", | |
"#Название счетчика\n", | |
"name_counter = input(\"Введите название счётчика: \").strip()\n", | |
"#домен сайта\n", | |
"site_domen = input(\"Введите Домен: \").strip()\n", | |
"site_domen=site_domen.replace(\"https://\", \"\").replace(\"http://\", \"\")\n", | |
"dostup_user= input(\"Введите логин на который передать счетчик: \").strip()\n", | |
"#предоставление доступа для редактирования + коментарий\n", | |
"\n", | |
"\n", | |
"#заголовки запроса\n", | |
"head = {\n", | |
" \"Host\": \"api-metrika.yandex.net\",\n", | |
" \"Authorization\": token,\n", | |
" \"Content-Type\": \"application/x-yametrika+json\",\n", | |
" \"Content-Length\": \"127\"\n", | |
"}\n", | |
"#параметры для отправки\n", | |
"\n", | |
"jsonBody = {\n", | |
" \"counter\": {\n", | |
" \"site\": site_domen,\n", | |
" \"name\": name_counter,\n", | |
" \"grants\" : [ {\"user_login\" : dostup_user , \"perm\" : \"edit\"}],\n", | |
" \"code_options\" : {\n", | |
" \"async\" : \"1\" ,\n", | |
" \"informer\" : {\n", | |
" \"enabled\" : \"0\"\n", | |
" },\n", | |
" \"visor\" : \"0\",\n", | |
" \"track_hash\" : \"0\" ,\n", | |
" \"xml_site\" : \"0\",\n", | |
" \"clickmap\" : \"1\" ,\n", | |
" \"in_one_line\" : \"0\" ,\n", | |
" \"ecommerce\" : \"0\" ,\n", | |
" \"alternative_cdn\" : \"0\"\n", | |
" },\n", | |
" \"goals\": [{\n", | |
" \"name\": \"лид offerrum\",\n", | |
" \"type\": \"url\",\n", | |
" \"is_retargeting\": 0,\n", | |
" \"conditions\": [\n", | |
" {\n", | |
" \"type\": \"contain\",\n", | |
" \"url\": \"confirm\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
"{\n", | |
" \"name\": \"лид lucky\",\n", | |
" \"type\": \"url\",\n", | |
" \"is_retargeting\": 0,\n", | |
" \"conditions\": [\n", | |
" {\n", | |
" \"type\": \"contain\",\n", | |
" \"url\": \"success\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
"{\n", | |
" \"name\": \"лид omni\",\n", | |
" \"type\": \"action\",\n", | |
" \"is_retargeting\": 0,\n", | |
" \"conditions\": [\n", | |
" {\n", | |
" \"type\": \"exact\",\n", | |
" \"url\": \"orderCreated\"\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"]\n", | |
" }}\n", | |
"\n", | |
"url = \"https://api-metrika.yandex.net/management/v1/counters\" \n", | |
"rr = requests.post(url, headers = head , data = json.dumps(jsonBody))\n", | |
"print(\"Ответ сервера \" + str(rr.status_code))\n", | |
"json_response=rr.json()\n", | |
"print(\"_\"*100)\n", | |
"print(\"\")\n", | |
"print('Счётчик № ' + str(json_response[\"counter\"][\"id\"]) + ' Успешно создан')\n", | |
"print(\"Код для вставки: \")\n", | |
"print(\"_\"*100)\n", | |
"print(str(json_response[\"counter\"][\"code\"]))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment