You are not logged in.

#1 2010-01-14 16:25:04

willxtreme
Member
Registered: 2010-01-07
Posts: 150
Website

Arch Linux Distrowatch's ranking via conky

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

#2 2011-05-04 18:29:29

AirOnSkin
Member
From: Switzerland
Registered: 2008-12-09
Posts: 11

Re: Arch Linux Distrowatch's ranking via conky

Thanks a lot for that script smile

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

#3 2014-11-22 12:04:56

entodoays
Member
From: Malta
Registered: 2014-10-25
Posts: 118

Re: Arch Linux Distrowatch's ranking via conky

I need beautifulsoup for python3. I cannot find it in the repos.

Offline

#4 2014-11-22 12:28:32

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,523

Re: Arch Linux Distrowatch's ranking via conky

$  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 wink

Offline

Board footer

Powered by FluxBB