-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChecklistGenerator.py
56 lines (39 loc) · 2.16 KB
/
ChecklistGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pandas as pd
from pylatex import Enumerate, Itemize , Description ,Command
def mergeBirdNames(commonName, otherNames):
# # Convert both names to title case
commonName = commonName.title()
if pd.isna(otherNames):
return commonName
final_name = commonName
for name in otherNames.split(","):
final_name+= "/"+name.title()
return final_name
df = pd.read_excel('./uomBirds.xlsx')
dfgrouped = df.groupby("Family") #grouping by family of the bird.
firstOrderList = Itemize()
for group_name, group_data in dfgrouped:
# Process each group_data as needed
print(f"Group Name: {group_name}")
print(group_data)
# Perform your operations on the group_data
firstOrderList.add_item(group_name)
secondOrderList = Enumerate()
for index,bird in group_data.iterrows():
dummyList = Description()
#This "Dummylist" is a bulletless list and this is used to
#make the scientific name italic while the other names being bold.
#Without using a list like this (See the previous commits.), using only three
#levels you cannot make the first line italic and second line of the same bullet
#point bold.
dummyList.add_item("",Command("textit",bird["Scientific Name"]+" ("+bird["Conservation Status"]+")"))
dummyList.add_item("", Command("textbf",mergeBirdNames(bird["Common Name"],bird["Other names"])))
secondOrderList.add_item(dummyList)
thirdOrderList = Description()
thirdOrderList.add_item("H: ",bird["Habitat and Distribution"][:-1]+"[2].") #[2] is citation for the bird guide.
thirdOrderList.add_item("D: ",bird["Diet"])
thirdOrderList.add_item("R: ",bird["Recorded Area(s)"])
secondOrderList.append(thirdOrderList)
firstOrderList.append(secondOrderList)
with open("./LatexCode.tex", "w") as tex_file:
tex_file.write(firstOrderList.dumps())