Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import vk_api
  2. import time
  3.  
  4. start = time.time()
  5.  
  6. link_pattern = "https://vk.me/join/"
  7.  
  8. token = "123"
  9. vk = vk_api.VkApi(token=token).get_api()
  10.  
  11. repeat = 1
  12.  
  13. all_links = []
  14.  
  15.  
  16. links = vk.newsfeed.search(q=link_pattern, count=200)
  17.  
  18. for link in links["items"]:
  19. if link_pattern in link["text"]:
  20. link = link["text"][link["text"].find(link_pattern):link["text"].find(link_pattern) + 43]
  21. if link not in all_links and '.' not in link[13:] and len(link.split()) == 1:
  22. if len(link) >= 44:
  23. link = link[0:43]
  24. elif len(link) < 43:
  25. continue
  26. all_links.append(link)
  27.  
  28. with open("links.txt", "r") as f:
  29. links_old = list(set(f.read().split()))
  30.  
  31. with open("links.txt", "a", encoding="utf-8") as f:
  32. for link in all_links:
  33. if link not in links_old:
  34. f.write(link + "\n")
  35.  
  36. end = time.time()
  37.  
  38. print(end - start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement