In front of me and my acquaintances, there was more than once a task to update the dates daily in Yandex.Direct ads. In the ad is written "Have time to May 21", if today is May 20. And so every day is exposed the next day. For some reason, they all did it manually, although the task is perfectly and conveniently automated using the
API provided by this service.
I have automated this task and want to share it with an already
prepared script . In addition, it will serve as an example for work in such situations, it is easy to adapt it for other similar tasks.
The script was written under the campaign of my partner, for others it may need some changes. It was important for me to simplify the work with the script, so the option “I will upload the templates of all ads to the server and I will update every day” didn’t work - so when changing or adding ads, they had to be configured on the server.
As a result, I came to the conclusion that it is better to automatically search for the deadline in the ad and correct it to the correct one.
')
The principle of the script is as follows:
- All ads from the specified campaigns are downloaded.
- In phrases like "before 11.22", the numbers are replaced with the desired date.
For example, “before 01.05” will be replaced by “until 21.05”, if today is May 20.
The current dates in the announcement can be any, if only there were two digits for both the day and the month (correctly:
09.05, wrong: 9.05, 9.5, 09.5)
- In the phrases of the form "before May 2," the date and month are replaced with the necessary ones.
Phrases like "up to 20 percent" are ignored, as the last word can only be the name of the month.
To get started with the API, you need to:
- In the Yandex.Direct interface, enable the use of the API by reading and agreeing to the rules.
- Create a certificate and download it.
Next, download all the files from the archive with the certificate to the directory with the script on the server.
The following parameters should be entered into the script (in the first two lines):
- List of identifiers of advertising campaigns (similar to what is written in the line).
- The number of days to add to the current (default is 1 day).
Next, add a call to this script in cron at night, from 0 to 9 o'clock (9:00 - moderation start time) It remains only to receive notifications of the past moderations in the morning.
Yandex.Direct API documentation:
http://api.yandex.ru/direct/The script itself:
https://github.com/gepo/ecommerce-tools