eong commited on
Commit
7a7702f
·
verified ·
1 Parent(s): ba5e858

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -53,13 +53,34 @@ def crypto_analysis(crypto_name: str) -> str:
53
  """
54
 
55
  url = f"https://rest.coincap.io/v3/assets/{crypto_name}?apiKey={os.getenv(key='coincap_api')}"
 
56
  try:
57
  response = requests.get(url)
58
  response.raise_for_status() # Raise exception for bad status codes
59
  data = response.json()
60
- return data
61
 
62
- except requests.exceptions.RequestException as e:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  raise f"Error: {str(e)}"
64
 
65
 
 
53
  """
54
 
55
  url = f"https://rest.coincap.io/v3/assets/{crypto_name}?apiKey={os.getenv(key='coincap_api')}"
56
+ search_tool = DuckDuckGoSearchTool()
57
  try:
58
  response = requests.get(url)
59
  response.raise_for_status() # Raise exception for bad status codes
60
  data = response.json()
61
+ crypto_info = data["data"]
62
 
63
+ # get search results
64
+ search_query = f"Get the latest analysis trends for the following cryptocurrency: crypto_info['name']}"
65
+ search.results = search_tool.search(search_query)
66
+
67
+ analysis = {
68
+ "crypto_data": {
69
+ "name": crypto_info["name"],
70
+ "symbol": crypto_info["symbol"],
71
+ "price_usd": float(crypto_info["priceUsd"]),
72
+ "market_cap_usd": float(crypto_info["marketCapUsd"]),
73
+ "24h_change": float(crypto_info["changePercent24Hr"]),
74
+ "rank": int(crypto_info["rank"])
75
+ },
76
+ "market_sentiment": "positive" if float(crypto_info["changePercent24Hr"]) > 0 else "negative",
77
+ "related_information": search_results,
78
+ "data_source": crypto_info["explorer"]
79
+ }
80
+
81
+ return json.dumps(analysis)
82
+
83
+ except Exception as e:
84
  raise f"Error: {str(e)}"
85
 
86