Beispiel #1
0
    def get(self):
        if self.logged_in:
            sites = SitesModel.query().order().fetch()
            changed_sites = OrderedDict([[x, ' '] for x in URLS])
            for site in sites:
                results = site.results
                lasts = results.split('/')
                if len(lasts) < 2:
                    # Only one result
                    continue

                last = lasts[-1].split('|')[0]  # [1] - timestamp
                last_result = self.get_data(last)

                i = -2
                while True:
                    prev = lasts[i].split('|')[0]
                    prev_result = self.get_data(prev)
                    if prev_result:
                        break
                    i -= 1
                # Now we have IDs

                changes = self.compare_data(last_result, prev_result)
                if len(changes) > 0:
                    changed_sites[site.site_name] = changes

            # Mail results
            from mailer.mail_send import SendStatistics
            stat = False
            for val in changed_sites.itervalues():
                if val is not ' ':
                    stat = True
                    break

            if stat:
                result = ''
                for k in changed_sites.iterkeys():
                    changes = changed_sites[k]
                    changed_cost = ''
                    for change in changes:
                        change = ' '.join(get_data_from_html(change).split('/$'))
                        if change:
                            changed_cost = '; '.join([change, changed_cost])
                    if changed_cost:
                        line = ' '.join([k, changed_cost])
                        result = '\n'.join([result, line])

                stats = SendStatistics()
                stats.post(data=result)
            values = {'user': self.current_user,
                      'site_names': URLS,
                      'sites': changed_sites,
                      'site': ''
                      }
            # self.session.add_flash('Some message', level='error')
            self.render('index.html', values)
        else:
            self.redirect('/login')
Beispiel #2
0
def send_mail(changed_sites):
    result = ''
    for k in changed_sites.iterkeys():
        changes = changed_sites[k]
        changed_cost = ''
        for change in changes:
            change = ' '.join(get_data_from_html(change).split('/$'))
            if change:
                changed_cost = '; '.join([change, changed_cost])
        if changed_cost:
            line = ' '.join([k, changed_cost])
            result = '\n'.join([result, line])

    stats = SendStatistics()
    stats.post(data=result)