ddrs/src/main.py

54 lines
2.3 KiB
Python
Raw Normal View History

from pathlib import Path
import re
import pandas
def cnrsformat1_to_sheet(in_tsv_file_path: Path, out_tsv_file_path: Path):
with open(in_tsv_file_path) as inf, open(out_tsv_file_path, 'wt') as outf:
table_header_has_been_written = False
for line in inf.readlines():
ignore_line = False
# Entité dépensière : AESJULLIEN AES RENNES METROPOLE MC JULLIEN Crédits reçus : 40,000.00
# Disponible : 24,743.14
#
#
# N° commande Souche Libellé commande Date commande Raison sociale fournisseur Montant consommé sur exercice antérieur Montant consommé sur l'exercice Montant réservé Montant facturé Code origine Nature dépense Statut Cde groupée
if re.match(r'^Entité dépensière', line):
ignore_line = True
is_table_header = re.match(r'^N° commande', line) is not None
# 19,572.00 19AESMCJ CAMERA ZYLA 5.5 sCMOS 04/11/19 ANDOR TECHNOLOGY LIMITED 0.00 13,681.56 0.00 0.00 635991 IM
if is_table_header and not table_header_has_been_written:
outf.write('# %s' % line)
table_header_has_been_written = True
if re.match(r'^[0-9,./]+\t', line):
outf.write(line)
def main():
cnrsformat1_file_path = Path('./from-cloud.ipr/2019/commandes-2019-cnrs-t001.tsv')
sheet_file_path = Path('./tmp/commandes-2019-cnrs.tsv')
cnrsformat1_to_sheet(cnrsformat1_file_path, sheet_file_path)
df = pandas.read_csv(sheet_file_path, sep='\t')
# delete the colums for which the labve is of the form 'Unnamed: <n>'. They come from the csv export of libre office
unnamed_columns = [column_label for column_label in df.keys() if re.match(r'^Unnamed', column_label) is not None]
print(unnamed_columns)
df = df.drop(columns=unnamed_columns)
print(df.columns)
print(df.keys())
print(df)
it_df = df[(df['Raison sociale fournisseur'] == 'DELL SAS') | (df['Raison sociale fournisseur'] == 'ECONOCOM PRODUCTS & SOLUTIONS')]
# 'AMAZON EU SARL SUCCURSALE FRANCAISE'
# 'INMAC'
# 'RETIS'
# 'APIXIT'
print(it_df)
print(it_df[['Montant facturé', 'Raison sociale fournisseur', 'Libellé commande']])
main()