You are not logged in.

#1 2015-06-12 21:18:13

theGunslinger
Member
Registered: 2011-05-20
Posts: 300

Need help with a watch script

I found this small script which parses livescore.com and shows the latest result from the games.

watch -n10 --no-title "w3m http://www.livescore.com/ |awk '/live [0-9H]+[^ ]/,/red cards/'" ;

The output looks like this:

2'
Tunisia
8 - 1
Djibouti
Africa Cup of Nations - Qualification:: group F
June 12
FT
Morocco
1 - 0
Libya
Africa Cup of Nations - Qualification:: group L
June 12
FT
Guinea
1 - 2
Swaziland
International - Friendly (Under 21)
June 12
FT
Austria U21
3 - 1
Bulgaria U21
World Cup Women - Group C
June 12
23:00
Switzerland
? - ?
Ecuador
June 13
02:00
Japan
? - ?
Cameroon
World Cup Women - Group D
June 12
live 13'
Australia
0 - 0
Nigeria

I would like the 3 lines after the line containg the word "live" "HT" or "FT" to be joined together. Is there an easy way to make it happen?

Thanks in advance

Offline

#2 2015-06-13 17:04:35

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Need help with a watch script

wouldn't a python script be better for this?

#!/usr/bin/env python3

from bs4 import BeautifulSoup
import requests
import time

url="http://www.livescore.com/soccer/";                           
r=requests.get(url);

data=r.text
soup=BeautifulSoup(data);
count=0;
pl1=""
pl2=""
score=""
line=""
for link in soup.find_all('div'):
    if (link.get('class')==['row','row-tall','mt4']):
        count=count+1;
    if(link.get('class')==['ply','tright','name']):
        pl1= ''.join(link.contents)
    if(link.get('class')==['sco']):
        for st in link.stripped_strings:
            score=''.join(repr(st))
    if(link.get('class')==['ply','name']):
        pl2= ''.join(link.contents)
        line=line +pl1+" : "+score+" : "+pl2+"\n";
    if(count>1):
        break;

print(line)

Output:

carnager@caprica ~/Downloads > python test2
 Ireland  : '1 - 0' :  Scotland 
 Poland  : '0 - 0' :  Georgia 
 Gibraltar  : '? - ?' :  Germany 

Last edited by Rasi (2015-06-13 17:07:51)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

Board footer

Powered by FluxBB