Last active
September 23, 2019 16:54
-
-
Save teki/7796b346c2b4a6a913b9e07a24e9e659 to your computer and use it in GitHub Desktop.
Use latest pic as background from https://twitter.com/PrimitivePic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# use it with https://github.com/matryer/bitbar | |
import os | |
import re | |
import subprocess | |
import tempfile | |
import time | |
import urllib2 | |
TW_URL = 'https://twitter.com/PrimitivePic' | |
page = urllib2.urlopen(TW_URL).read() | |
first_pic = re.search('pbs.twimg.com/media.*?jpg', page) | |
if first_pic: | |
url = first_pic.group(0) | |
image = urllib2.urlopen('http://' + url).read() | |
tmp_file, tmp_path = tempfile.mkstemp() | |
os.write(tmp_file, image) | |
os.close(tmp_file) | |
subprocess.call("osascript -e 'tell application \"Finder\" to set desktop picture to POSIX file \"" + tmp_path + "\"'", shell=True) | |
time.sleep(1) | |
os.remove(tmp_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was just about to write this when I figured "why not search gist?". Thanks for posting!