Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class VK:
- def __init__(self):
- import vkontakte
- global config
- self.config = config.vk
- self.api = vkontakte.API(self.config.appId, self.config.appSecret)
- def getNewMessages(self):
- #print 'requesting vk'
- resp = self.api.get('wall.get', owner_id='-' + str(self.config.group), count=str(5))
- total = resp[0]
- posts = resp[1:]
- messages = []
- for i in xrange(total - self.config.handled):
- self.config.handled += 1
- global config
- config.save( open('growl.conf', 'w') ) # костыльно
- post = posts[i]
- author = self.api.get('users.get', uids=str(post['from_id']), fields='first_name,last_name,sex')[0] # nickname,screen_name,
- name = author['first_name'] + ' ' + author['last_name']
- posted = u'насрал' + ([u'о', u'а', u''][author['sex']])
- message = name + ' ' + posted + u' на стенке:\n' + post['text']
- if 'attachments' in post:
- for att in post['attachments']:
- if att['type'] in ('photo', 'posted_photo'):
- message += u'\n\tИзображение: ' + att[att['type']]['src_big']
- elif att['type'] == 'link':
- pass
- #message += u'\n\tСсылка: ' + att[att['type']]['url']
- elif att['type'] == 'video':
- message += u'\n\tВидео: ' + att[att['type']]['title']
- elif att['type'] == 'audio':
- message += u'\n\tАудио: ' + att[att['type']]['performer'] + ' - ' + att[att['type']]['title']
- else:
- message += u'\n\tПрикреплено ' + att['type']
- messages.append(message)
- return messages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement