Advertisement
Kalashnikov

growl vk class

Nov 10th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. class VK:
  2.     def __init__(self):
  3.         import vkontakte
  4.         global config
  5.         self.config = config.vk
  6.         self.api = vkontakte.API(self.config.appId, self.config.appSecret)
  7.  
  8.     def getNewMessages(self):
  9.         #print 'requesting vk'
  10.         resp = self.api.get('wall.get', owner_id='-' + str(self.config.group), count=str(5))
  11.         total = resp[0]
  12.         posts = resp[1:]
  13.  
  14.         messages = []
  15.         for i in xrange(total - self.config.handled):
  16.             self.config.handled += 1
  17.             global config
  18.             config.save( open('growl.conf', 'w') ) # костыльно
  19.            
  20.             post = posts[i]
  21.             author = self.api.get('users.get', uids=str(post['from_id']), fields='first_name,last_name,sex')[0] # nickname,screen_name,
  22.             name = author['first_name'] + ' ' + author['last_name']
  23.             posted = u'насрал' + ([u'о', u'а', u''][author['sex']])
  24.  
  25.             message = name + ' ' + posted + u' на стенке:\n' + post['text']
  26.             if 'attachments' in post:
  27.                 for att in post['attachments']:
  28.                     if att['type'] in ('photo', 'posted_photo'):
  29.                         message += u'\n\tИзображение: ' + att[att['type']]['src_big']
  30.                     elif att['type'] == 'link':
  31.                         pass
  32.                         #message += u'\n\tСсылка: ' + att[att['type']]['url']
  33.                     elif att['type'] == 'video':
  34.                         message += u'\n\tВидео: ' + att[att['type']]['title']
  35.                     elif att['type'] == 'audio':
  36.                         message += u'\n\tАудио: ' + att[att['type']]['performer'] + ' - ' + att[att['type']]['title']
  37.                     else:
  38.                         message += u'\n\tПрикреплено ' + att['type']
  39.  
  40.             messages.append(message)
  41.         return messages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement