|
|
@@ -0,0 +1,46 @@
|
|
|
+import git
|
|
|
+from git.exc import GitCommandError
|
|
|
+import requests
|
|
|
+from datetime import datetime
|
|
|
+
|
|
|
+# Konfiguration
|
|
|
+REPO_PATH = '/home/pi/solar_collector' # Pfad zum lokalen Git-Repository
|
|
|
+GIT_REPO_URL = 'https://g.tbsgl.xyz:443/tsi/solar_collector.git' # SSH URL des Git-Repositories
|
|
|
+bot_token = '949332240:AAHNsQEmCW4it86Esa7F5o07XxwrotSM7s8'
|
|
|
+chat_id = '-914111351'
|
|
|
+
|
|
|
+def send_telegram_message(bot_token, chat_id, message):
|
|
|
+ """Sendet eine Nachricht über Telegram."""
|
|
|
+ bot_url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
|
|
|
+ payload = {'chat_id': chat_id, 'text': message}
|
|
|
+ try:
|
|
|
+ response = requests.post(bot_url, data=payload)
|
|
|
+ response.raise_for_status()
|
|
|
+ except requests.exceptions.RequestException as e:
|
|
|
+ print(f"Fehler beim Senden der Telegram-Nachricht: {e}")
|
|
|
+
|
|
|
+def git_pull(repo_path, repo_url):
|
|
|
+ """Führt ein git pull im angegebenen Repository aus."""
|
|
|
+ try:
|
|
|
+ repo = git.Repo(repo_path)
|
|
|
+ except git.exc.InvalidGitRepositoryError:
|
|
|
+ # Falls das Verzeichnis kein Git-Repo ist, klone es
|
|
|
+ git.Repo.clone_from(repo_url, repo_path)
|
|
|
+ return "Repository geklont"
|
|
|
+
|
|
|
+ current = repo.head.commit
|
|
|
+ repo.remotes.origin.pull()
|
|
|
+ new = repo.head.commit
|
|
|
+
|
|
|
+ if current != new:
|
|
|
+ return "Neue Daten erfolgreich ausgerollt"
|
|
|
+ else:
|
|
|
+ return "Keine neuen Daten zum Ausrollen"
|
|
|
+
|
|
|
+def main():
|
|
|
+ message = git_pull(REPO_PATH, GIT_REPO_URL)
|
|
|
+ send_telegram_message(bot_token, chat_id, message)
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ main()
|
|
|
+
|