Simple class for parsing data from WordStat via yandex direct api
Project description
YandexWordstatAPI
Simple small class for parsing data from WordStat via yandex direct api
Installing YandexWordstatAPI
$ python -m pip install YandexWordstatAPI
Docs
from YandexWordstatAPI.WordstatAPI import *
import time
'''
Yandex sandbox url = https://api-sandbox.direct.yandex.ru/v4/json/
Yandex full access url = https://api.direct.yandex.ru/v4/json/
'''
url = 'https://api-sandbox.direct.yandex.ru/v4/json/' # api url
token = 'AgAAAAAX1GmLIIX9s4uEoSNiSEyjjxTsAHZ0p8w' # Token to access Yandex.Direct API
username = 'yandex.username' # Username to get points value
API = WordstatAPI(url, token, username)
phrases = [
'фотошоп',
'photoshop'
]
exclude = [
'-купить',
'-дешево',
'-скачать',
'-бесплатно'
]
geo = [] # Can be let empty
data = API.compose_data(phrases, exclude) # Compose data with exclude phrases
# Methods
units = API.get_client_units() # Get client units. ref: https://yandex.ru/dev/direct/doc/dg-v4/reference/GetClientsUnits.html
print(f"You have {units['data'][0]['UnitsRest']}")
report_id = API.create_report(data, geo)[
'data'] # Create new report, it will be redy in ~2 minutes. ref: https://yandex.ru/dev/direct/doc/dg-v4/reference/CreateNewWordstatReport.html
print(f"The report wit id {report_id} is creating")
report_list = API.get_report_list() # Get report list, you can wait til the report will be ready, or just check it later. ref: https://yandex.ru/dev/direct/doc/dg-v4/reference/GetWordstatReportList.html
last_report = report_list['data'][-1]
while lastReport['StatusReport'] != 'Done':
if lastReport['StatusReport'] == 'Failed':
raise Exception('Failed to create report')
else:
print('Report is creating...')
lastReport = API.get_report_list()['data'][-1]
time.sleep(2)
report = API.readReport(
report_id) # Read report data by its id. ref: https://yandex.ru/dev/direct/doc/dg-v4/reference/GetWordstatReport.html
API.save_report_to_txt(report, searched_also_flag=True) # Save all data to txt, can be undone if not necessary
response = API.delete_report(
report_id) # Delete Wordstat report, it can be done when you reach report number limit(5 reports)
if response['data'] == 1:
print(f'Report with id {report_id} was successfully deleted')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
YandexWordstatAPI-1.1.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file YandexWordstatAPI-1.1.tar.gz
.
File metadata
- Download URL: YandexWordstatAPI-1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaa08f3cf94f8ef295fb3c41ff28037d8134d8d6893b5a39e8893f0e3f6c3b68 |
|
MD5 | acb965ce39001d63fecd79e2e0e9c7fe |
|
BLAKE2b-256 | f8234dd2ac06b40169e2b0d3526e5d6a9097c2c0d606106b9e66a778ee2f0c2e |
File details
Details for the file YandexWordstatAPI-1.1-py3-none-any.whl
.
File metadata
- Download URL: YandexWordstatAPI-1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa898d48e086fd00a6a177b3b895f41af3860b57caf71990333c6265e39b095 |
|
MD5 | 5ec306c95b47e41c27493bbacee56667 |
|
BLAKE2b-256 | adc91c25fb3145338eb76282a6ed4cecf7895ec17f004cb68da12d5af8e8759b |