File size: 4,042 Bytes
fa8201e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import streamlit as st

def ReadPDFFile(doc, PageNum, searchtext, BreakText):
	Read = False
	found = False
	Extracttext = []
	#
	page = doc.loadPage(PageNum)
	pagetext = page.getText("text")
	#
	text_instances = page.searchFor(searchtext)
	#
	if (text_instances):
		page_display = page.getDisplayList()
		dictionary_elements = page_display.getTextPage().extractDICT()
		for block in dictionary_elements['blocks']:
			for line in block['lines']:
				for span in line['spans']:
					Line = span['text']
					if (Line.strip() == searchtext):
						Read = True
					if (BreakText != "" and BreakText in Line.strip() and Read == True):
						Extracttext.append(Line)
						found = True
						break
					if (Read):
						if (len(Line) > 1):
							Extracttext.append(Line)
				if (found): break
			if (found): break
	#
	return Extracttext


def PopulateDict(Extracttext, DictText):
	Extractedtext = []
	# DictText = {}
	ShareAmts = []
	Key = ""
	Extractedtext = Extracttext[4:len(Extracttext) - 1]
	for readtext in Extractedtext:
		if (not any(map(str.isdigit, readtext)) and "(" in readtext):
			Key = Key + readtext
		else:
			if (not any(map(str.isdigit, readtext))):
				if (ShareAmts):
					DictText[Key] = ShareAmts
					Key = readtext  # String data
				else:
					Key = readtext
				ShareAmts = []
			else:
				ShareAmts.append(readtext.strip())
	#
	if (ShareAmts):
		DictText[Key] = ShareAmts
	#
	return DictText


def get_brief(DictText):
	for Key in DictText:
		Values = DictText[Key]
		if (len(Values) == 3):
			Val0 = Values[0].replace(",", ".")
			Val1 = Values[1].replace(",", ".")
			Val0 = Val0.replace("%", "")
			Val1 = Val1.replace("%", "")
			Val2 = Values[2]
			Val2 = Val2.replace("(", "")
			Val2 = Val2.replace(")", "")
			Val2 = Val2.replace("]", "")
			Val2 = Val2.replace("[", "")
			Val2 = Val2.replace("pt", "%")
			Val2 = Val2.replace(" %", "%")
			#
			if (float(Val0) > float(Val1)):
				st.markdown('* {} ${}B, <font color="green">**up**</font> {} YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), Val2,
				                                                      round(float(Val1), 2)),unsafe_allow_html=True)
			else:
				st.markdown('* {} ${}B, <font color="red">**down**</font> {} YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), Val2,
				                                                        round(float(Val1), 2)),unsafe_allow_html=True)
		if (len(Values) == 2):
			Val0 = Values[0].replace(",", ".")
			Val1 = Values[1].replace(",", ".")
			Val0 = Val0.replace("%", "")
			Val1 = Val1.replace("%", "")
			Val0 = Val0.replace("(", "")
			Val0 = Val0.replace(")", "")
			Val1 = Val1.replace("(", "")
			Val1 = Val1.replace(")", "")
			#
			if (float(Val0) > float(Val1)):
				diffVal = (float(Val0) - float(Val1))
				Res = (100 * diffVal) / (float(Val1))
				st.markdown('* {} ${}B, <font color="green">**up**</font> {}% YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), round(Res, 2),
				                                                      round(float(Val1), 2)),unsafe_allow_html=True)
			else:
				diffVal = (float(Val1) - float(Val0))
				Res = (100 * diffVal) / (float(Val0))
				st.markdown('* {} ${}B, <font color="red">**down**</font> {}% YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), round(Res, 2),
				                                                        round(float(Val1), 2)),unsafe_allow_html=True)
		if (len(Values) == 1):
			Values = str(Values)
			Values = Values.replace("]", "")
			Values = Values.replace("[", "")
			Values = Values.replace(" %", "%")
			if ("Impact" in Key):
				if ("(" in Values):
					Values = Values.replace("(", "")
					Values = Values.replace(")", "")
					st.markdown('* {} on revenue growth, <font color="red">**negative**</font> {}.'.format(Key, Values),unsafe_allow_html=True)
				else:
					st.markdown('* {} on revenue growth, {}.'.format(Key, Values),unsafe_allow_html=True)
			else:
				if ("Organic" in Key):
					st.write('* {}, {}.'.format(Key, Values))
				else:
					st.write('* {}, {}.'.format(Key, Values))