bharatcoder commited on
Commit
52796a3
·
verified ·
1 Parent(s): ca7712e

First commit - WIP

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from markitdown import MarkItDown
4
+ import datetime
5
+
6
+
7
+ """
8
+ Retrieve the file at https://pulse.zerodha.com
9
+ Then convert it to markdown format using markitdown library.
10
+
11
+ """
12
+
13
+ # Initialize the client
14
+ def initialize_client(api_key_env_var):
15
+ load_dotenv(find_dotenv())
16
+ api_key = os.getenv(api_key_env_var)
17
+ if not api_key:
18
+ raise ValueError(f"API key not found in environment variable {api_key_env_var}")
19
+ return genai.Client(api_key=api_key)
20
+
21
+ my_model = 'gemini-2.0-flash' #'gemini-2.0-flash-exp'
22
+ client = initialize_client('GOOGLE_API_KEY')
23
+
24
+ # Main function
25
+ if __name__ == '__main__':
26
+
27
+ # Current time is, dd-mm-YYYY HH:MM:SS
28
+ timenow = datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")
29
+
30
+ # get the pulse file
31
+ print(f"Start getting the pulse file at {timenow}...")
32
+ response = requests.get('https://pulse.zerodha.com')
33
+ html_content = response.text
34
+ # Save it to a file
35
+ with open('output.html', 'w') as file:
36
+ file.write(html_content)
37
+
38
+ print(f"Start converting the pulse file to markdown format at {timenow}...")
39
+ md = MarkItDown()
40
+ result = md.convert("output.html")
41
+ #print(result.text_content)
42
+ # Save the markdown content to a file
43
+ with open('output.md', 'w') as file:
44
+ file.write(result.text_content)
45
+
46
+ print(f"Start arranging the pulse file at {timenow}...")
47
+ analyzer = client.chats.create(model=my_model)
48
+ response = analyzer.send_message(f"Arrange and group the news feed provided based on the order of importance for an investor in the markets. Include whatever data related to the news is available in the input, such as short summaries, hyperlinks etc. If available include time of report of the news. The time now is: {timenow}. The input is in markdown. Input: {result.text_content}")
49
+ output = ""
50
+ parts = response.candidates[0].content.parts
51
+ if parts is None:
52
+ print(f'finish_reason={response.candidates[0].finish_reason}')
53
+ for part in parts:
54
+ if part.text:
55
+ #print(part.text)
56
+ # join the text parts
57
+ output += part.text
58
+
59
+ # Save the output to a file
60
+ with open('output_arranged.md', 'w') as file:
61
+ file.write(output)