fork download
  1. import json
  2. import os
  3. import re
  4. import subprocess
  5. from urllib import request
  6.  
  7.  
  8. def get_resolution():
  9. cmd = ['xrandr']
  10. cmd2 = ['grep', '*']
  11. p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
  12. p2 = subprocess.Popen(cmd2, stdin=p.stdout, stdout=subprocess.PIPE)
  13. p.stdout.close()
  14.  
  15. resolution_string, junk = p2.communicate()
  16. resolution = resolution_string.split()[0]
  17. return resolution.decode('utf-8')
  18.  
  19.  
  20. url = 'http://w...content-available-to-author-only...g.com/HPImageArchive.aspx?format=js&idx=0&n=1'
  21. resolution = get_resolution()
  22.  
  23. with request.urlopen(url) as res:
  24. data = res.read()
  25.  
  26. bing_json = json.loads(data.decode('utf-8'))
  27. wallpaper_urlbase = bing_json['images'][0]['urlbase']
  28.  
  29. wallpaper_name = re.search('\w+$', wallpaper_urlbase).group()
  30.  
  31. wallpaper_url = 'http://w...content-available-to-author-only...g.com{}_{}.jpg'.format(
  32. wallpaper_urlbase, resolution)
  33.  
  34.  
  35. request.urlretrieve(wallpaper_url, '{}_{}.jpg'.format(
  36. wallpaper_name, resolution))
Runtime error #stdin #stdout #stderr 0.05s 54320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 21, in <module>
  File "./prog.py", line 11, in get_resolution
  File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'xrandr'