Subversion Repositories basico

Rev

Rev 45 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45 Rev 73
Line 77... Line 77...
77
77
78
78
79
    def fetch(self, sid):
79
    def fetch(self, sid):
80
        db = self.get_service('DB')
80
        db = self.get_service('DB')
81
        valid = False
81
        valid = False
82
        self.log.debug("Fetching SAP Note %s" % sid)
-
 
-
 
82
        #~ self.log.debug("%3d/%3d - Fetching SAP Note %s" % (self.notes_fetched+1, self.notes_total, sid))
83
83
84
        if not db.is_stored(sid):
84
        if not db.is_stored(sid):
85
            self.log.debug("\tSAP Note %s must be downloaded" % sid)
-
 
-
 
85
            self.log.debug("%3d/%3d - SAP Note %s must be downloaded" % (self.notes_fetched+1, self.notes_total, sid))
86
            content = self.download(sid)
86
            content = self.download(sid)
87
            db.store(sid, content)
-
 
-
 
87
            if len(content) > 0:
-
 
88
                self.log.debug("%3d/%3d - SAP Note %s fetched" % (self.notes_fetched+1, self.notes_total, sid))
-
 
89
            else:
-
 
90
                self.log.debug("%3d/%3d - SAP Note %s not feched" % (self.notes_fetched+1, self.notes_total, sid))
88
        else:
91
        else:
89
            self.log.debug("\tSAP Note %s will be analyzed again" % sid)
-
 
-
 
92
            self.log.debug("%3d/%3d - SAP Note %s will be analyzed again" % (self.notes_fetched+1, self.notes_total, sid))
90
            content = db.get_sapnote_content(sid)
93
            content = db.get_sapnote_content(sid)
-
 
94
-
 
95
        self.fetched()
91
96
92
        sapnote = self.analyze_sapnote_metadata(sid, content)
97
        sapnote = self.analyze_sapnote_metadata(sid, content)
93
        if len(sapnote) > 0:
98
        if len(sapnote) > 0:
94
            db = self.get_service('DB')
99
            db = self.get_service('DB')
95
            db.add(sapnote)
100
            db.add(sapnote)
96
            db.store(sid, content)
101
            db.store(sid, content)
97
            valid = True
102
            valid = True
98
103
99
        return valid, sid
104
        return valid, sid
-
 
105
-
 
106
-
 
107
    def start_fetching(self, total):
-
 
108
        self.notes_fetched = 0
-
 
109
        self.notes_total = total
-
 
110
-
 
111
-
 
112
    def fetched(self):
-
 
113
        self.notes_fetched += 1
-
 
114
-
 
115
-
 
116
    def stop_fetching(self):
-
 
117
        self.notes_fetched = 0
-
 
118
        self.notes_total = 0
100
119
101
120
102
    def download(self, sapnote=None):
121
    def download(self, sapnote=None):
103
        try:
122
        try:
104
            driver = self.get_service('Driver')
123
            driver = self.get_service('Driver')
105
            browser = driver.open()
-
 
106
            self.log.debug("\tDownloading SAP Note %s:" % sapnote)
-
 
107
            self.log.debug(ODATA_NOTE_URL % sapnote)
-
 
108
            if browser is not None:
-
 
109
                browser = driver.load(ODATA_NOTE_URL % sapnote)
-
 
110
                time.sleep(10)
-
 
111
                content = browser.page_source
-
 
112
                self.log.debug("\tSAP Note %s downloaded" % sapnote)
-
 
113
            else:
-
 
114
                content = ''
-
 
-
 
124
            #~ browser = driver.open()
-
 
125
            #~ self.log.debug("\tDownloading SAP Note %s:" % sapnote)
-
 
126
            #~ self.log.debug(ODATA_NOTE_URL % sapnote)
-
 
127
            browser = driver.load(ODATA_NOTE_URL % sapnote)
-
 
128
            time.sleep(5)
-
 
129
            content = browser.page_source
-
 
130
            #~ self.log.debug("\t%3d - SAP Note %s downloaded" % (sapnote, driver.)
-
 
131
            #~ else:
-
 
132
            #~ content = ''
115
        except Exception as error:
133
        except Exception as error:
116
            self.log.error("\tSAP Note %s coud not be downloaded" % sapnote)
-
 
-
 
134
            #~ self.log.error("\tSAP Note %s coud not be downloaded" % sapnote)
117
            self.log.error(error)
135
            self.log.error(error)
118
            raise
-
 
119
            content = ''
136
            content = ''
120
137
121
        return content
138
        return content
122
139
123
140