Mercurial > repos > artbio > facturation_ibps
comparison facturation.py @ 2:3bbcf49ad677 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/facturation_ibps commit 9a51dcfe718e63148d19717c473f9e234652fade
| author | artbio |
|---|---|
| date | Thu, 08 Nov 2018 05:45:50 -0500 |
| parents | 927553056183 |
| children | 1c5097aea031 |
comparison
equal
deleted
inserted
replaced
| 1:927553056183 | 2:3bbcf49ad677 |
|---|---|
| 1 #!/usr/bin/env python2 | |
| 2 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 3 | 2 |
| 4 | 3 |
| 5 import argparse | 4 import argparse |
| 6 import re | 5 import re |
| 28 facture_html = file_object.read() | 27 facture_html = file_object.read() |
| 29 # convert to unicode utf-8, remove   and € | 28 # convert to unicode utf-8, remove   and € |
| 30 facture_html = facture_html.decode('utf-8') | 29 facture_html = facture_html.decode('utf-8') |
| 31 facture_html = facture_html.replace(r' ', r' ') | 30 facture_html = facture_html.replace(r' ', r' ') |
| 32 facture_html = facture_html.replace(u' \u20ac', '') | 31 facture_html = facture_html.replace(u' \u20ac', '') |
| 33 # parsing de la date et de la période de facturation | 32 # parsing de la référence, de la date et de la période de facturation |
| 34 date = re.search(r'Paris le (.*?)</p>'.decode('utf-8'), | 33 date = re.search(r'Paris le (.*?)</p>'.decode('utf-8'), |
| 35 facture_html).group(1) | 34 facture_html).group(1) |
| 36 periode = re.search(r'de la prestation (.*?)</p>'.decode('utf-8'), | 35 periode = re.search(r'de la prestation (.*?)</p>'.decode('utf-8'), |
| 37 facture_html).group(1) | 36 facture_html).group(1) |
| 37 ref = re.search(r'sur le bon de commande :\s*(.*?)<'.decode('utf-8'), | |
| 38 facture_html).group(1) | |
| 38 | 39 |
| 39 # parsing des tableaux html avec pandas | 40 # parsing des tableaux html avec pandas |
| 40 facture_parsed = pd.read_html( | 41 facture_parsed = pd.read_html( |
| 41 facture_html, | 42 facture_html, |
| 42 thousands='', | 43 thousands='', |
| 51 elements_col = elements.iloc[0] | 52 elements_col = elements.iloc[0] |
| 52 cout_col = elements_col.str.extract(r'(cout.*)', | 53 cout_col = elements_col.str.extract(r'(cout.*)', |
| 53 expand=False).dropna().iloc[0] | 54 expand=False).dropna().iloc[0] |
| 54 elements = elements.rename(columns=elements_col).drop( | 55 elements = elements.rename(columns=elements_col).drop( |
| 55 elements.index[0]) | 56 elements.index[0]) |
| 56 | |
| 57 misc = facture_parsed[3] | |
| 58 | |
| 59 ref = misc.iloc[:, # récupération de la référence | |
| 60 0].str.extract(r'sur le bon de commande :\s*(.*)$', | |
| 61 expand=False).dropna().iloc[0] | |
| 62 | 57 |
| 63 # ouverture fichier output | 58 # ouverture fichier output |
| 64 facture_output = openpyxl.load_workbook( | 59 facture_output = openpyxl.load_workbook( |
| 65 'template_facture.xlsx', data_only=False, keep_vba=False) | 60 'template_facture.xlsx', data_only=False, keep_vba=False) |
| 66 ws = facture_output.worksheets[0] | 61 ws = facture_output.worksheets[0] |
