source: misc/verkeersinformatie@ 395

Last change on this file since 395 was 370, checked in by Rick van der Zwet, 13 years ago

Forgot an file.

  • Property svn:executable set to *
File size: 1.5 KB
RevLine 
[369]1#!/usr/bin/env python
2#
3# File informatie van NU.nl op de CLI
4#
5# Licence: BSDLike - http://rickvanderzwet.nl/LICENSE
6# Rick van der Zwet <info@rickvanderzwet.nl>
7from bs4 import BeautifulSoup
8import re
9import sys
10import urllib2
11
[370]12rit = { 'werk' : ['N11', 'A44', 'A4', ] }
[369]13
14def usage():
15 print "Gebruik: %s [rit|weg] <naam> [<naam2> ...]" % sys.argv[0]
16 exit(128)
17
18# Zoek uit welke wegen we moeten zoeken
19wegen_filter = []
20if len(sys.argv) > 1:
21 if len(sys.argv) == 2:
22 usage()
23 elif sys.argv[1] == 'rit':
24 for naam in sys.argv[2:]:
25 if not rit.has_key(naam):
26 print "Geen rit '{0}' bekend (opties: {1})".format(naam, rit.keys())
27 exit(128)
28 wegen_filter.extend(rit[naam])
29 elif sys.argv[1] == 'weg':
30 wegen_filter = sys.argv[2:]
31 else:
32 usage()
33wegen_filter = sorted(set(wegen_filter))
34
35# Vind de wegen bij NU.nl
36FILE_URL = 'http://www.nu.nl/verkeer/index.html'
37soup = BeautifulSoup(urllib2.urlopen(FILE_URL))
38middle = soup.find('div', { 'class' : 'page_content' })
39file_len = 0
40for f in middle.find_all('p', { 'style' : 'clear: both' }):
41 text = re.sub('[ ]+',' ', f.get_text().strip().replace('\n', '-'))
42 if len(list(f.children)) != 8:
43 print "# {0}\n".format(text)
44 continue
45 file_len += 1
46 if wegen_filter and not any(['file: {0} '.format(weg.lower()) in text.lower() for weg in wegen_filter]):
47 continue
48 print text
49
50print ""
51if wegen_filter: print "# Gefiltered op wegen: {0}".format(", ".join(wegen_filter))
52print "# Data van: {0}".format(FILE_URL)
53print "# Totaal {0} files".format(file_len)
54
Note: See TracBrowser for help on using the repository browser.