Skip to content

Instantly share code, notes, and snippets.

@trianglesis
Created July 28, 2016 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trianglesis/08af14d629da9139035a085b26d613f0 to your computer and use it in GitHub Desktop.
Save trianglesis/08af14d629da9139035a085b26d613f0 to your computer and use it in GitHub Desktop.
Старый скриптец, который я использовал около года назад для выборки именинников и публикации поста с ними на стену сообществ Вконтакте. Выкладываю в публичный доступ, так как морально он устарел и код в нем выглядит ужасно, но подходит чисто для образовательных целей и "авось кому пригодится" мне бы он помог на первых порах изучения, может быть …
#! /usr/bin/env python3
# coding=utf-8
__author__ = 'danilcha'
# Change history
# 2015-11-16 Add note about new API method after VK_module update, and new list parsing method.
import vk
from time import gmtime, strftime
curr_date = strftime("%Y-%m-%d")
vk_birth_day = strftime("%d", gmtime())
vk_birth_month = strftime("%m", gmtime())
token = ''
vkapi = vk.API(access_token=token)
print("Today's date "
+ curr_date +
" will find b-days for this day."
"Day string is "
+ vk_birth_day +
". Month string is "
+ vk_birth_month +
" continue"
)
users_birthday = vkapi('users.search',
count=1000,
birth_day=vk_birth_day,
birth_month=vk_birth_month,
group_id=0000000)
users_id = users_birthday['items']
all_bdays = len(users_id)
some = []
for user in users_id:
for vk_id in user:
id_int = user['id']
id_str = str(id_int)
for raw_id in id_str:
all_str = str("@id" + id_str)
for line in all_str:
some.append(all_str)
break
break
break
count = len(some)
those_ids = ', '.join(some)
print("How many b-day-ers were found:")
print(count)
print("\n")
print("Composing greeting message")
greet_msg = ("Поздравляем наших подписчиков с днём рождения!"
"\n\n"
"Желаем Вам всего самого лучшего!"
"\n\n"
" С Ув. администрация .... "
"\n\n"
+ those_ids +
"\n\n"
" от: Бот автоматического поздравления"
"\n\n"
"\n\n"
"\n\n"
"Если вы не попали в список, значит, "
"вероятно вы или закрыли свою дату рождения, "
"или заполнили её некорректно, "
"или же не вступили в группу ... , "
"поздравление происходит только в том случае, "
"если все предыдущие условия соблюдены, спасибо за понимание!"
"#b_day_bot"
"\n\n #ВождьБот Powered by #Python made by #trianglesis"
)
owner_id = "-00000000"
wall_post = vkapi('wall.post',
owner_id=owner_id,
from_group='1',
message=greet_msg,
attachments='photo-46631810_395130865,'
'audio13147598_392954307,'
'audio13147598_392954267,'
'audio13147598_392954252,'
'audio13147598_392954225',
signed='0')
print("Message has been posted successfully!")
print(greet_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment