-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
107 lines (77 loc) · 2.77 KB
/
script.py
File metadata and controls
107 lines (77 loc) · 2.77 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
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
import requests
from datetime import datetime
import os
from groq import Groq
# ---- CONFIG ----
CITY = "Lucknow"
WEATHER_API_KEY = "b4194471d5254484872163149251206"
NEWS_API_KEY = os.getenv("NEWS_API_KEY") or "b3627940bba147568e4d150c345774e0"
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
# ---- WEATHER ----
weather_url = f"http://api.weatherapi.com/v1/current.json?key={WEATHER_API_KEY}&q={CITY}"
weather_data = requests.get(weather_url).json()
temp = weather_data["current"]["temp_c"]
condition = weather_data["current"]["condition"]["text"]
# ---- NEWS ----
news_url = f"https://newsapi.org/v2/everything?q=technology&language=en&sortBy=publishedAt&apiKey={NEWS_API_KEY}"
news_data = requests.get(news_url).json()
articles = [] # ✅ ALWAYS defined
news_list = ""
if news_data.get("status") == "ok" and news_data.get("articles"):
articles = news_data["articles"][:5]
for article in articles:
title = article.get("title", "No title")
news_list += f"- {title}\n"
else:
news_list = "No news available right now."
# ---- AI (GROQ) ----
ai_output = "AI insight not available."
if GROQ_API_KEY:
try:
client = Groq(api_key=GROQ_API_KEY)
news_text = "\n".join([article.get("title", "") for article in articles])
if news_text.strip(): # only if news exists
response = client.chat.completions.create(
model="mixtral-8x7b-32768",
messages=[
{"role": "system", "content": "Summarize the news and give one short insight."},
{"role": "user", "content": news_text}
]
)
ai_output = response.choices[0].message.content
else:
ai_output = "No news available for AI analysis."
except Exception as e:
ai_output = f"Error generating AI insight: {e}"
else:
ai_output = "GROQ API key missing."
# ---- TIME ----
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# ---- README ----
content = f"""
<p align="center">
<img src="https://img.shields.io/badge/Python-3.10-blue" />
<img src="https://img.shields.io/badge/Automation-GitHub%20Actions-green" />
<img src="https://img.shields.io/badge/Status-Active-success" />
</p>
# 🚀 Sujai's Dev Dashboard
🕒 Last Updated: {now}
---
## 🌦️ Weather in {CITY}
Temperature: {temp}°C
Condition: {condition}
---
## 📰 Top Tech News
{news_list}
---
## 🔥 Daily Update
Keeping the repo active automatically!
## 📊 GitHub Stats


---
## ⚡ About
Auto-updated using Python + GitHub Actions
"""
with open("README.md", "w") as f:
f.write(content)