示例#1
0
    def generate_pdf(self):
        """ генерация pdf. Ваш К.О. """
        try:
            path = self.app.app.sets.save_pdf
        except:
            path = ''
        filename = 'Продажи за %s.pdf' % (norm_date(self.c_date))
        f = tkFileDialog.asksaveasfilename(initialdir=path,
                                           initialfile=filename)
        if not f: return
        f = f.replace('\\', '/')
        self.app.app.sets.save_pdf = '/'.join(f.split('/')[:-1])
        doc = pdf.Pdf(title='Продажи за %s' % (norm_date(self.c_date)),
                      fname=f)
        doc.string('Доходы:')

        doc.table([('Время', 45), ('Отд', 35), ('Товар', 220), ('Сум.', 40),
                   ('К-во', 30), ('Итого', 40), ('Продавец', 90)])

        self.app.app.db.execute(
            'select time,dep,article,sum,rate,name,art_id,edit from income where date=?',
            (self.c_date, ))
        income_all = 0
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[7] <> 0:
                out[1] = str(out[1]) + u' (≈)'
            if out[6] <> -1:
                out[1] = str(out[1]) + u' →'
            out.insert(5, x[3] * x[4])
            income_all += x[3] * x[4]

            doc.table([(out[0], 45), (out[1], 35), (out[2], 220), (out[3], 40),
                       (out[4], 30), (out[5], 40), (out[6], 90)],
                      font=10)
        doc.enter()
        doc.string('Расходы:')
        outcome_all = 0

        doc.table([('Время', 45), ('Причина', 220), ('Сум.', 40),
                   ('Продавец', 90)])
        self.app.app.db.execute(
            'select time,article,sum,name,art_id,edit from outcome where date=?',
            (self.c_date, ))
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[5] <> 0:
                out[1] = u'(≈) ' + out[1]
            doc.table([(out[0], 45), (out[1], 220), (out[2], 40),
                       (out[3], 90)],
                      font=10)
            outcome_all += out[2]

        doc.enter()
        doc.string('Всего доходов: %s' % (income_all))
        doc.string('Всего расходов: %s' % (outcome_all))
        doc.string('Остаток: %s' % (income_all - outcome_all))
        doc.end()
        self.win.deiconify()
示例#2
0
    def generate_pdf(self):
        """ генерация pdf c выбранным приходом """
        if not self.lst.curselection(): return
        sel = int(self.lst.curselection()[0])
        id = self.c_id[sel]

        self.app.app.app.db.execute('select date,time from in_art where id=?',
                                    (id, ))
        rez = self.app.app.app.db.fetchall()[0]

        try:
            path = self.app.app.app.sets.save_pdf
        except:
            path = ''
        print rez
        filename = ('Приход товара за %s %s.pdf' %
                    (norm_date(rez[0]), str(rez[1]))).replace(':', '-')
        f = tkFileDialog.asksaveasfilename(initialdir=path,
                                           initialfile=filename)
        if not f: return
        f = f.replace('\\', '/')
        self.app.app.app.sets.save_pdf = '/'.join(f.split('/')[:-1])
        doc = pdf.Pdf(title='Приход товара', fname=f)
        doc.string('Приход товара за %s %s' % (norm_date(rez[0]), str(rez[1])))

        self.app.app.app.db.execute(
            'select dep,name,rate from in_art where id=?', (id, ))
        doc.table([('Отдел', 45), ('Товар', 350), ('Кол.во', 50)])
        n = 0
        s = 0
        for x in self.app.app.app.db.fetchall():
            n += 1
            doc.table([(x[0], 45), (x[1], 350), (x[2], 50)], font=10)
            s += x[2]
        doc.enter()
        doc.string('Наименований: %s' % (n))
        doc.string('Количество: %s' % (s))

        doc.end()
        self.app.win.deiconify()
示例#3
0
 def generate_contact_sheet(self, font, columns, rows, export_path, panels,
                            header, font_size):
     pdf = pdf_api.Pdf(font, columns, rows, export_path, panels, header,
                       font_size)
     return pdf.build_canvas()
currentDirectory = os.path.dirname(__file__)

ssl._create_default_https_context = ssl._create_unverified_context

# getting pdf urls from file
fileContent = file.File("urls.txt").getFileContent()

#saving pdfs from internet
i = 1
for url in fileContent:
    urllib.request.urlretrieve(url, "source/" + str(i) + ".pdf")
    i += 1

corpus = list()
for source in glob.glob("source/*.pdf"):
    corpus.append(pdf.Pdf(source).getWordList())

for source in glob.glob("source/*.docx"):
    corpus.append(docx.Docx(source).getWordList())

for source in glob.glob("source/*.txt"):
    corpus.append(file.File(source).getWordList())

frequency = frequency.Frequency(corpus)

with open('result/tfidf_list.csv', 'w+') as csvFile:

    writer = csv.writer(csvFile)

    for key, value in OrderedDict(
            sorted(frequency.idf().items(), key=itemgetter(1),
示例#5
0
DIR = os.path.dirname(__file__)

parser = argparse.ArgumentParser()
parser.add_argument('--browser', '-b', action='store_true')
parser.add_argument('--server', '-s', action='store_true')
parser.add_argument('--test', '-t', action='store_true')
args = parser.parse_args()

if args.browser:
    webbrowser.open_new_tab(os.path.join(DIR, 'index.html'))

if args.server:
    subprocess.check_call(['python', '-u', 'py-rpc-host', 'pdf'])

if args.test:
    def compare(a, b):
        with open(a, 'rb') as f: a = f.read()
        with open(b, 'rb') as f: b = f.read()
        return a == b
    for i in glob.glob(os.path.join('reference-pdfs', '*i.pdf')):
        print(i)
        truncated = i[:-5]
        test_file_name = truncated+'t.pdf'
        pdf.Pdf().load(i).save(test_file_name)
        if not compare(truncated+'o.pdf', test_file_name):
            print('warning: output changed')
        pdf.Pdf().load(test_file_name).save(test_file_name)
        if not compare(truncated+'o.pdf', test_file_name):
            print('error: not idempotent')
        os.remove(test_file_name)
示例#6
0
    def generate_pdf(self):
        """ генерация pdf """
        try:
            path = self.app.app.sets.save_pdf
        except:
            path = ''
        filename = 'Остатки по отделу %s на %s.pdf' % (self.cur_dep + 1,
                                                       norm_date(date_now()))
        f = tkFileDialog.asksaveasfilename(initialdir=path,
                                           initialfile=filename)
        if not f: return
        f = f.replace('\\', '/')
        self.app.app.sets.save_pdf = '/'.join(f.split('/')[:-1])
        doc = pdf.Pdf(title='Остатки товара', fname=f)

        r = self.rb_var.get()
        rate = self.rate_ent.get()
        self.app.app.db.execute('select name from dep where id=?',
                                (self.cur_dep + 1, ))

        dep_name = self.app.app.db.fetchall()[0][0]

        if r == 0:
            self.app.app.db.execute(
                'select id,rate,sum,type from article where dep=?',
                (self.cur_dep + 1, ))
            doc.string(u'Все остатки по отделу %s %s' %
                       (self.cur_dep + 1, dep_name))
        else:
            try:
                rate = int(rate)
            except:
                return
            self.app.app.db.execute(
                'select id,rate,sum,type from article where dep=? and rate<?',
                (self.cur_dep + 1, rate))
            doc.string(
                u'Остатки по отделу %s %s, количество товара меньше %s' %
                (self.cur_dep + 1, dep_name, rate))
        rez1 = self.app.app.db.fetchall()

        all_rate = 0
        all_sum = 0
        doc.table([('Товар', 300), ('Остаток', 80), ('Стоимость', 80)])
        for x in rez1:

            t = []
            flag = True
            self.app.app.db.execute(
                'select name,edit,sum,parent from article where id=?',
                (x[0], ))
            s = self.app.app.db.fetchall()[0]
            par = s[3]
            t.append(s[0])
            if par == -1: flag = 0
            while flag:
                self.app.app.db.execute(
                    'select name,parent from article where id=?', (par, ))
                rez = self.app.app.db.fetchall()[0]
                if rez[1] == -1:
                    t.append(rez[0])
                    flag = False
                else:
                    t.append(rez[0])
                    par = rez[1]
            cat_lst = ' > '.join(t[::-1])
            if x[3] == 'item':
                doc.table([(cat_lst, 300), (x[1], 80), (x[2], 80)], font=10)
                all_rate += x[1]
                all_sum += x[1] * x[2]

        self.lab_var.set('Наименований: %s, количество: %s, на сумму %s' %
                         (len(rez1), all_rate, all_sum))
        doc.enter()
        doc.string('Всего наименований: %s' % (len(rez1)))
        doc.string('Всего количество: %s, на сумму %s' % (all_rate, all_sum))
        doc.end()
        self.win.deiconify()