You are not logged in.
in 3 steps
1) Download Beautiful Soup for Python & copy BeautifulSoup.py to /usr/lib/python2.6/site-packages
2) Create ranking.py containing:
#!/usr/bin/env python
import urllib2
from BeautifulSoup import BeautifulSoup
address = "http://distrowatch.com/"
try:
website = urllib2.urlopen(address)
soup = BeautifulSoup(''.join(website))
rankings = soup.find(text= "Page Hit Ranking").findParent("table").find(text="Arch").findParent("tr").find("th").string
print rankings
except:
print "N/A"
3) Add in .conkyrc
Distrowatch's Ranking: $alignr ${execi 7200 python ~/.scripts/ranking.py}
http://sites.google.com/site/zazazpsite … 7conky.png -- Please follow image posting rules -- Inxsible
credits to iggykoopa
Last edited by Inxsible (2011-05-04 19:15:20)
Offline
Thanks a lot for that script
A few notes:
a) Beautiful Soup is in the community repo. You can get it with: pacman -S python-beautifulsoup
b) This script didn't work for me right away. After some help from the #python channel on FreeNode I found out, that it's probably because I'm behind a proxy. When executed from bash (where http_proxy was set) it was working, with conky not. I've searched the internet and found, that urllib2 has a proxy handler. I wasn't able to test it yet, but my script looks now as follows:
#!/usr/bin/env python
import urllib2
from BeautifulSoup import BeautifulSoup
address = "http://distrowatch.com/"
try:
proxy = urllib2.ProxyHandler({'http':'http://proxy.yourdomain.com:8080'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
website = urllib2.urlopen(address)
soup = BeautifulSoup(''.join(website))
rankings = soup.find(text= "Page Hit Ranking").findParent("table").find(text="Arch").findParent("tr").find("th").string
print rankings
except:
print "N/A"
# EOF
c) I didn't have a command python on my system, but rather python2. So the line in the conkyrc needs to changed as well (for users with the same problem):
Distrowatch's Ranking: $alignr ${execi 7200 python2 ~/.scripts/ranking.py}
Cheers,
Air
Last edited by AirOnSkin (2011-05-04 18:30:29)
Offline
I need beautifulsoup for python3. I cannot find it in the repos.
Offline
$ pacman -Ss beautifulsoup
community/python-beautifulsoup4 4.3.2-2
A Python HTML/XML parser designed for quick turnaround projects like
screen-scraping
Aren't you sure that you searched enough?
do it good first, it will be faster than do it twice the saint
Offline