Skip to content

Instantly share code, notes, and snippets.

@teki
Last active September 23, 2019 16:54
Show Gist options
  • Save teki/7796b346c2b4a6a913b9e07a24e9e659 to your computer and use it in GitHub Desktop.
Save teki/7796b346c2b4a6a913b9e07a24e9e659 to your computer and use it in GitHub Desktop.
Use latest pic as background from https://twitter.com/PrimitivePic
#!/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)
@trapier
Copy link

trapier commented Sep 23, 2019

Was just about to write this when I figured "why not search gist?". Thanks for posting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment