Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- from threading import Thread
- import time
- from datetime import datetime
- API_URL = "https://www.reddit.com/r/wallpaper.json"
- POSTS = []
- 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'}
- def Engine():
- url = requests.get(API_URL, headers=headers).content
- api_call = json.loads(url)
- for single_post in api_call['data']['children']:
- post_id = single_post['data']['id']
- title = single_post['data']['title']
- photo_url = single_post['data']['url']
- if post_id not in POSTS:
- POSTS.append(post_id)
- if "3840" in title:
- file_name = photo_url.split("/")[-1]
- tempo = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
- print(f"Nuovo wallpaper scaricato: {title} - {tempo}")
- with open("wallpaper/"+file_name, 'wb') as file:
- file.write(requests.get(photo_url).content)
- while 1:
- t = Thread(target=Engine)
- t.start()
- time.sleep(300)
Add Comment
Please, Sign In to add comment