""" Fetch and parse stenograms """

from datetime import date
from urlparse import urlparse, parse_qs
from path import path
from pyquery import PyQuery as pq


def fetch_day(day):
    contents = pq('http://www.cdep.ro/pls/steno/steno.data',
                  {'cam': 2, 'dat': day.strftime('%Y%m%d'), 'idl': 1})
    for link_el in contents('td.headlinetext1 b a'):
        link = link_el.attrib['href']
        plink = urlparse(link)
        assert plink.path == '/pls/steno/steno.stenograma'
        if ',' in parse_qs(plink.query)['idm'][0]:
            # this is a fragment page. we can ignore it since we
            # already have the content from the parent page.
            continue
        print link


if __name__ == '__main__':
    import requests_cache
    here = path(__file__).abspath().parent
    requests_cache.install_cache(here / 'http_cache')
    fetch_day(date(2013, 6, 10))

@@ -157,28 +157,79 @@
 q%0A%0A%0A
-def fetch_day(
+class StenogramScraper(object):%0A%0A    def links_for_day(self, 
 day):%0A
+    
     
@@ -285,16 +285,20 @@
 .data',%0A
+    
         
@@ -360,16 +360,20 @@
 l': 1%7D)%0A
+    
     for 
@@ -425,16 +425,20 @@
         
+    
 link = l
@@ -459,16 +459,20 @@
 'href'%5D%0A
+    
         
@@ -502,16 +502,20 @@
         
+    
 assert p
@@ -565,16 +565,20 @@
         
+    
 if ',' i
@@ -612,16 +612,20 @@
 m'%5D%5B0%5D:%0A
+    
         
@@ -693,16 +693,20 @@
         
+    
 # alread
@@ -754,24 +754,28 @@
             
+    
 continue%0A   
@@ -771,16 +771,119 @@
 ontinue%0A
+            yield link%0A%0A    def fetch_day(self, day):%0A        for link in self.links_for_day(day):%0A    
         
@@ -1045,20 +1045,39 @@
 cache')%0A
-
     
+StenogramScraper().
 fetch_da

structure the scraper as a class