Guest User

Untitled

a guest
Jun 23rd, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import requests
  2. import json
  3. from threading import Thread
  4. import time
  5. from datetime import datetime
  6.  
  7. API_URL = "https://www.reddit.com/r/wallpaper.json"
  8. POSTS = []
  9. headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
  10.  
  11.  
  12. def Engine():
  13. url = requests.get(API_URL, headers=headers).content
  14. api_call = json.loads(url)
  15. for single_post in api_call['data']['children']:
  16. post_id = single_post['data']['id']
  17. title = single_post['data']['title']
  18. photo_url = single_post['data']['url']
  19. if post_id not in POSTS:
  20. POSTS.append(post_id)
  21. if "3840" in title:
  22. file_name = photo_url.split("/")[-1]
  23. tempo = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
  24. print(f"Nuovo wallpaper scaricato: {title} - {tempo}")
  25. with open("wallpaper/"+file_name, 'wb') as file:
  26. file.write(requests.get(photo_url).content)
  27. while 1:
  28. t = Thread(target=Engine)
  29. t.start()
  30. time.sleep(300)
Add Comment
Please, Sign In to add comment