-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetstock.py
More file actions
54 lines (43 loc) · 1.68 KB
/
getstock.py
File metadata and controls
54 lines (43 loc) · 1.68 KB
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
import sys
print(sys.executable)
import moviepy
print(moviepy.__file__)
from crewai import Agent as a
import litellm
import yfinance as y
from moviepy import *
from moviepy.video.VideoClip import ColorClip, TextClip
from moviepy import CompositeVideoClip
litellm.enable_logging()
# Initialize CrewAgent
agent = a(name="Stock Video Creator")
@agent.task(name="getstocks")
def getstocks():
movers = []
tickers = y.Tickers("AAPL MSFT AMZN TSLA NVDA GOOGL META NFLX ORCL IBM")
print(tickers)
for name, values in tickers.tickers.items():
data = values.history(period='1d')
close = data['Close'].iloc[0]
Open = data['Open'].iloc[0]
change = float(round((close - Open) / Open * 100))
vol = int(data['Volume'].iloc[0])
movers.append([name, change, vol])
sorts = sorted(movers, key=lambda x: x[1])
return sorts
@agent.task(name="videomade")
def videomade(stockdata):
clips = []
clip1 = ColorClip(size=(640, 480), color=(0, 0, 0), duration=2)
clips.append(clip1)
for i in stockdata:
txt = TextClip(txt=f'Symbol: {i[0]}\n Change% : {i[1]}\n Volume: {i[2]}',
font=r"C:\Users\gcmad\venv\Lib\site-packages\moviepy\fonts\arialbd.ttf", color='white', fontsize=24)
vid_clip = txt.set_pos('center').set_duration(1)
clips.append(vid_clip)
video = CompositeVideoClip(clips)
video.write_videofile("output_list.mp4", fps=24)
if __name__ == "__main__":
stock_movers = getstocks() # Get the stock movers first
videomade(stock_movers) # Pass the result to videomade function
agent.run_flow(["getstocks", "videomade"])