42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
#!/usr/bin/python3.10
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""************************
|
|
AnkIdentification - Supplementary code 3-1 : Creating the list of all plant species.
|
|
Aurélien VALENTIN - from 06/11/2022 to 29/12/2022
|
|
************************"""
|
|
|
|
# Importation and initialisation
|
|
import json, sys
|
|
dict_common_names = {}
|
|
|
|
# Definition of the progressbar function, from https://gist.github.com/ChesterChowWOV/2b35c551b339adbf459363322aac5b4b
|
|
def progressbar(it, prefix="", size=60, file=sys.stdout):
|
|
count = len(it)
|
|
def show(j):
|
|
x = int(size*j/count)
|
|
file.write("{}[{}{}] {}/{} {}%\r".format(prefix, "█"*x, "."*(size-x), j, count, round(j/count * 100, 2)))
|
|
file.flush()
|
|
show(0)
|
|
for i, item in enumerate(it):
|
|
yield item
|
|
show(i+1)
|
|
file.write("\n")
|
|
file.flush()
|
|
|
|
# Creation of the list
|
|
with open("0229588-220831081235567.csv", encoding="utf-8") as fpi:
|
|
fpi.readline()
|
|
for line in progressbar(fpi.readlines(), "Processing species", 40):
|
|
try:
|
|
specie = line.split("\t")[1].split(" ")[0] + " " + line.split("\t")[1].split(" ")[1]
|
|
dict_common_names[specie] = ""
|
|
# Looking for another scientific name accepted
|
|
specie2 = line.split("\t")[3].split(" ")[0] + " " + line.split("\t")[3].split(" ")[1]
|
|
if specie2 != specie:
|
|
dict_common_names[specie2] = ""
|
|
except: pass
|
|
|
|
# Generation of the json file
|
|
with open("_dict_species_raw.json", "w") as fpo : json.dump(dict_common_names, fpo)
|
|
print(dict_common_names) |