Skip to content

Instantly share code, notes, and snippets.

@trapier
Forked from teki/PrimitivePic_bg.30m.py
Last active September 23, 2019 17:15
Show Gist options
  • Save trapier/82adce6c19b1a6ebc3e6ce0928790077 to your computer and use it in GitHub Desktop.
Save trapier/82adce6c19b1a6ebc3e6ce0928790077 to your computer and use it in GitHub Desktop.
Use latest pic as background from https://twitter.com/PrimitivePic
#!/usr/bin/python
import os
import re
import subprocess
import tempfile
import time
import urllib.request
from pathlib import Path
TW_URL = 'https://twitter.com/PrimitivePic'
SUB_DIR="/Pictures/primitivepic/"
home = str(Path.home())
page = urllib.request.urlopen(TW_URL).read().decode('utf-8')
pics = re.findall('pbs.twimg.com/media.*?jpg', page)
if pics:
url = pics[4]
image = urllib.request.urlopen('http://' + url).read()
tmp_file, tmp_path = tempfile.mkstemp(suffix='jpg', dir=home + SUB_DIR)
os.write(tmp_file, image)
os.close(tmp_file)
subprocess.call('feh --bg-max ' + tmp_path, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment