imcrazytwkr

VK group statistics

Jul 16th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # Configuration
  2. group_id = 1337
  3. access_token = ''
  4. file_name = 'test.csv'
  5.  
  6. # Imports
  7. import urllib.request as request
  8. import json
  9. import csv
  10.  
  11. # Preparations
  12. count = 50
  13. offset = 0
  14. wallposts = []
  15.  
  16. # DAT CODE
  17. while (count == 50):
  18.     data = json.loads(request.urlopen('https://api.vk.com/method/wall.get?owner_id=-' + str(group_id) + '&offset=' + str(offset) + '&count=50&access_token=' + access_token).read().decode('UTF-8'))['response'][1:]
  19.     if (len(data) > 0):
  20.         wallposts.extend(data)
  21.         offset += 50
  22.     count = len(data)
  23.  
  24. # Output
  25. fileWriter = open(file_name, 'w', encoding='UTF-8')
  26. rowWriter = csv.writer(fileWriter)
  27. rowWriter.writerow(('id', 'timestamp', 'html', 'comment_count', 'like_count', 'repost_count' ))
  28.  
  29. for post in wallposts:
  30.     rowWriter.writerow((
  31.         post['id'],
  32.         post['date'],
  33.         post['text'],
  34.         post['comments']['count'],
  35.         post['likes']['count'],
  36.         post['reposts']['count']
  37.     ))
  38.  
  39. fileWriter.close()
Advertisement
Add Comment
Please, Sign In to add comment