Guest User

Untitled

a guest
Mar 23rd, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. #-*- coding: utf-8 -*-
  4. from bs4 import BeautifulSoup
  5. import urllib.request
  6. import os, random
  7.  
  8.  
  9. def getRandomXkcdComic():
  10.     resp = urllib.request.urlopen("http://c.xkcd.com/random/comic/")
  11.     soup = BeautifulSoup(resp, from_encoding=resp.info().get_param('charset'))
  12.  
  13.     for link in soup.find_all('img'):
  14.         if "imgs.xkcd.com/comics" in link['src']:
  15.            comic_image = 'http:' + link['src']
  16.            return comic_image
  17.    
  18.  
  19. random_image = getRandomXkcdComic()
  20.  
  21. os.system("wget " + random_image + " -O /home/piotr/.xkcd.png")
  22. os.system("killall conky")
  23. os.system("conky -d -c ~/.conky_xkcd")
Add Comment
Please, Sign In to add comment