टेलीग्राम लोकेशन बॉट से अपने पंच कार्ड को स्वचालित करें | मूल, AI द्वारा अनुवादित

Home PDF

name: प्रति घंटा स्थान जांच

on:
  schedule:
    # हर घंटे, घंटे के शुरू में, सुबह 11 बजे से रात 11 बजे तक, सोमवार से शुक्रवार तक चलाएं
    # समय UTC में है। सिंगापुर समय (SGT) UTC+8 है।
    # इसलिए, 11 AM SGT, 03:00 UTC है, और 11 PM SGT, 15:00 UTC है।
    # अतः, हमें 03:00 से 15:00 UTC तक शेड्यूल करना होगा।
    - cron: '0 3-15 * * 1-5'

    # लाइव लोकेशन शेयर करने की याद दिलाने के लिए: बुधवार सुबह 11 बजे SGT (3 AM UTC)
    # वर्तमान समय: रविवार, 8 जून, 2025 शाम 5:10:58 PM +08 (SGT)
    # बुधवार 11 AM SGT (UTC+8): 11 - 8 = 3 AM UTC.
    - cron: '0 3 * * 3' # 3 बुधवार के लिए

    # लाइव लोकेशन शेयरिंग बंद करने की याद दिलाने के लिए: शुक्रवार रात 11 बजे SGT (3 PM UTC)
    # वर्तमान समय: रविवार, 8 जून, 2025 शाम 5:10:58 PM +08 (SGT)
    # शुक्रवार 11 PM SGT (UTC+8): 23 - 8 = 15 PM UTC.
    - cron: '0 15 * * 5' # 5 शुक्रवार के लिए

  workflow_dispatch:  # वर्कफ़्लो को मैन्युअली ट्रिगर करने की अनुमति देता है
  push:
    branches: ["main"]
    paths:
      - 'scripts/release/location_bot.py' # आपके स्क्रिप्ट का सही पथ
      - '.github/workflows/location.yml' # इस वर्कफ़्लो फ़ाइल का पथ

concurrency:
  group: 'location'
  cancel-in-progress: false

jobs:
  check_and_notify:
    runs-on: ubuntu-latest
    env:
      TELEGRAM_LOCATION_BOT_API_KEY: $

    steps:
    - name: रिपॉजिटरी चेकआउट करें
      uses: actions/checkout@v4
      with:
        fetch-depth: 5 # दक्षता के लिए केवल अंतिम 5 कमिट्स फ़ेच करें

    - name: Python 3.13.2 सेट अप करें
      uses: actions/setup-python@v4
      with:
        python-version: "3.13.2" # सटीक Python वर्ज़न निर्दिष्ट करें

    - name: निर्भरताएँ इंस्टॉल करें
      run: |
        python -m pip install --upgrade pip
        # मान लें कि आपके रिपॉजिटरी रूट में requirements.simple.txt है।
        # यदि नहीं, तो उपयोग करें: pip install requests python-dotenv
        pip install -r requirements.simple.txt 

    - name: स्थान जांच स्क्रिप्ट चलाएं (शेड्यूल्ड)
      run: python scripts/release/location_bot.py --job check_location
      # यह चरण प्रति घंटा जांच के लिए शेड्यूल्ड ट्रिगर्स पर चलेगा
      if: github.event.schedule == '0 3-15 * * 1-5' # प्रति घंटा cron शेड्यूल से मेल खाएं

    - name: लाइव लोकेशन शेयर करने की याद दिलाएं
      run: python scripts/release/location_bot.py --job start_sharing_message
      if: github.event.schedule == '0 3 * * 3' # बुधवार 11 AM SGT cron से मेल खाता है

    - name: लाइव लोकेशन शेयरिंग बंद करने की याद दिलाएं
      run: python scripts/release/location_bot.py --job stop_sharing_message
      if: github.event.schedule == '0 15 * * 5' # शुक्रवार 11 PM SGT cron से मेल खाता है

    - name: टेलीग्राम स्क्रिप्ट टेस्ट मैसेज के लिए चलाएं (मैन्युअल ट्रिगर)
      run: python scripts/release/location_bot.py --job send_message --message "यह GitHub Actions से मैन्युअल ट्रिगर टेस्ट मैसेज है।"
      if: github.event_name == 'workflow_dispatch'

    - name: मुख्य ब्रांच में पुश होने पर टेलीग्राम स्क्रिप्ट चलाएं
      run: python scripts/release/location_bot.py --job send_message --message "लोकेशन बॉट के लिए कोड परिवर्तन मुख्य ब्रांच में पुश किए गए।"
      if: github.event_name == 'push'

```python import os import requests from dotenv import load_dotenv import json import subprocess import argparse import math import time # भविष्य में निरंतर मॉनिटरिंग के लिए

load_dotenv()

नया: लोकेशन बॉट के लिए विशिष्ट API कुंजी

TELEGRAM_LOCATION_BOT_API_KEY = os.environ.get(“TELEGRAM_LOCATION_BOT_API_KEY”) # सुनिश्चित करें कि यह आपके .env में सेट है TELEGRAM_CHAT_ID = “610574272” # यह चैट ID नोटिफिकेशन मैसेज भेजने के लिए है

अपने ऑफिस के निर्देशांक परिभाषित करें

OFFICE_LATITUDE = 23.135368 OFFICE_LONGITUDE = 113.32952

निकटता त्रिज्या मीटर में

PROXIMITY_RADIUS_METERS = 300

def send_telegram_message(bot_token, chat_id, message): “"”टेलीग्राम बॉट API का उपयोग करके टेलीग्राम चैट में मैसेज भेजता है।””” url = f”https://api.telegram.org/bot{bot_token}/sendMessage” params = { “chat_id”: chat_id, “text”: message, “parse_mode”: “Markdown” # मैसेज में बोल्ड टेक्स्ट के लिए Markdown का उपयोग कर रहा है } response = requests.post(url, params=params) if response.status_code != 200: print(f”टेलीग्राम मैसेज भेजने में त्रुटि: {response.status_code} - {response.text}”)

def get_latest_location(bot_token): “"”बॉट से नवीनतम लाइव लोकेशन अपडेट प्राप्त करता है।””” url = f”https://api.telegram.org/bot{bot_token}/getUpdates” # केवल नए अपडेट्स प्राप्त करने के लिए ऑफ़सेट (निरंतर पोलिंग के लिए) # एक सरल रन-वन स्क्रिप्ट के लिए, हम केवल नवीनतम प्राप्त करेंगे, लेकिन पोलिंग के लिए आप ऑफ़सेट प्रबंधित करेंगे। params = {“offset”: -1} # अंतिम अपडेट प्राप्त करें response = requests.get(url, params=params) print(“GetUpdates प्रतिक्रिया:”, response) # डिबगिंग if response.status_code == 200: updates = response.json() print(“GetUpdates JSON:”, json.dumps(updates, indent=4)) # डिबगिंग if updates[‘result’]: last_update = updates[‘result’][-1] # लाइव लोकेशन के लिए edited_message को प्राथमिकता दें if ‘edited_message’ in last_update and ‘location’ in last_update[‘edited_message’]: return last_update[‘edited_message’][‘location’], last_update[‘edited_message’][‘chat’][‘id’] elif ‘message’ in last_update and ‘location’ in last_update[‘message’]: # प्रारंभिक लाइव लोकेशन मैसेज या स्थिर लोकेशन शेयर को हैंडल करें return last_update[‘message’][‘location’], last_update[‘message’][‘chat’][‘id’] return None, None

def haversine_distance(lat1, lon1, lat2, lon2): “”” हेवरसाइन फॉर्मूला का उपयोग करके पृथ्वी पर दो बिंदुओं के बीच की दूरी की गणना करें। मीटर में दूरी लौटाता है। “”” R = 6371000 # पृथ्वी की त्रिज्या मीटर में

lat1_rad = math.radians(lat1)
lon1_rad = math.radians(lon1)
lat2_rad = math.radians(lat2)
lon2_rad = math.radians(lon2)

dlon = lon2_rad - lon1_rad
dlat = lat2_rad - lat1_rad

a = math.sin(dlat / 2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(dlon / 2)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

distance = R * c
return distance

def main(): parser = argparse.ArgumentParser(description=”टेलीग्राम बॉट स्क्रिप्ट”) # –job तर्क के लिए अपडेटेड विकल्प parser.add_argument(‘–job’, choices=[‘get_chat_id’, ‘send_message’, ‘check_location’, ‘start_sharing_message’, ‘stop_sharing_message’], required=True, help=”करने के लिए कार्य”) # ‘send_message’ जॉब के लिए –message तर्क जोड़ा गया parser.add_argument(‘–message’, type=str, help=”‘send_message’ जॉब के लिए भेजने के लिए मैसेज”) # ‘check_location’ जॉब के लिए –test तर्क जोड़ा गया parser.add_argument(‘–test’, action=’store_true’, help=”‘check_location’ जॉब के लिए, निकटता की परवाह किए बिना मैसेज भेजें।”) args = parser.parse_args()

if args.job == 'get_chat_id':
    bot_token = TELEGRAM_LOCATION_BOT_API_KEY
    url = f"https://api.telegram.org/bot{bot_token}/getUpdates"
    response = requests.get(url)
    if response.status_code == 200:
        updates = response.json()
        print(json.dumps(updates, indent=4))
        if updates['result']:
            last_update = updates['result'][-1]
            chat_id = None
            if 'message' in last_update and 'chat' in last_update['message']:
                chat_id = last_update['message']['chat']['id']
            elif 'edited_message' in last_update and 'chat' in last_update['edited_message']:
                chat_id = last_update['edited_message']['chat']['id']
            elif 'channel_post' in last_update and 'chat' in last_update['channel_post']:
                chat_id = last_update['channel_post']['chat']['id']
            elif 'edited_channel_post' in last_update and 'chat' in last_update['edited_channel_post']:
                chat_id = last_update['edited_channel_post']['chat']['id']

            if chat_id:
                print(f"चैट ID: {chat_id}")
            else:
                print("अंतिम अपडेट से चैट ID प्राप्त नहीं कर सका।")
        else:
            print("कोई अपडेट नहीं मिला।")
    else:
        print(f"अपडेट फ़ेच करने में त्रुटि: {response.status_code} - {response.text}")

elif args.job == 'send_message':
    if TELEGRAM_LOCATION_BOT_API_KEY and TELEGRAM_CHAT_ID:
        message = args.message if args.message else "यह आपकी टेलीग्राम बॉट स्क्रिप्ट से एक डिफ़ॉल्ट टेस्ट मैसेज है!"
        send_telegram_message(TELEGRAM_LOCATION_BOT_API_KEY, TELEGRAM_CHAT_ID, message)
        print(f"मैसेज सफलतापूर्वक भेजा गया: {message}")
    else:
        print("TELEGRAM_LOCATION_BOT_API_KEY और TELEGRAM_CHAT_ID सेट नहीं हैं।")

elif args.job == 'start_sharing_message':
    if TELEGRAM_LOCATION_BOT_API_KEY and TELEGRAM_CHAT_ID:
        message = "⚠️ *याद दिलाना:* कृपया बॉट को अपना लाइव लोकेशन शेयर करना शुरू करें!"
        send_telegram_message(TELEGRAM_LOCATION_BOT_API_KEY, TELEGRAM_CHAT_ID, message)
        print("शेयरिंग शुरू करने की याद दिलाने वाला मैसेज भेजा गया।")
    else:
        print("TELEGRAM_LOCATION_BOT_API_KEY और TELEGRAM_CHAT_ID सेट नहीं हैं।")

elif args.job == 'stop_sharing_message':
    if TELEGRAM_LOCATION_BOT_API_KEY and TELEGRAM_CHAT_ID:
        message = "✅ *याद दिलाना:* अब आप अपना लाइव लोकेशन शेयरिंग बंद कर सकते हैं।"
        send_telegram_message(TELEGRAM_LOCATION_BOT_API_KEY, TELEGRAM_CHAT_ID, message)
        print("शेयरिंग बंद करने की याद दिलाने वाला मैसेज भेजा गया।")
    else:
        print("TELEGRAM_LOCATION_BOT_API_KEY और TELEGRAM_CHAT_ID सेट नहीं हैं।")

elif args.job == 'check_location':
    if not TELEGRAM_LOCATION_BOT_API_KEY or not TELEGRAM_CHAT_ID:
        print("लोकेशन जांच के लिए TELEGRAM_LOCATION_BOT_API_KEY और TELEGRAM_CHAT_ID सेट होने चाहिए।")
        return

    user_location, location_chat_id = get_latest_location(TELEGRAM_LOCATION_BOT_API_KEY)

    if user_location:
        current_latitude = user_location['latitude']
        current_longitude = user_location['longitude']

        distance = haversine_distance(
            OFFICE_LATITUDE, OFFICE_LONGITUDE,
            current_latitude, current_longitude
        )

        print(f"वर्तमान स्थान: ({current_latitude}, {current_longitude})")
        print(f"ऑफिस से दूरी: {distance:.2f} मीटर")

        needs_punch_card = distance <= PROXIMITY_RADIUS_METERS

        if needs_punch_card:
            print(f"आप ऑफिस के {PROXIMITY_RADIUS_METERS}m के दायरे में हैं!")
            notification_message = (
                f"🎉 *ऑफिस पहुँच गए!* 🎉\n"
                f"WeCom में पंच कार्ड करने का समय आ गया है।\n"
                f"ऑफिस से आपकी वर्तमान दूरी: {distance:.2f}m."
            )
        else:
            print(f"आप ऑफिस के {PROXIMITY_RADIUS_METERS}m के दायरे से बाहर हैं।")
            # त्रिज्या से बाहर होने पर मैसेज
            notification_message = (
                f"📍 आप ऑफिस की निकटता ({PROXIMITY_RADIUS_METERS}m) से *बाहर* हैं।\n"
                f"इस समय पंच कार्ड की आवश्यकता नहीं है।\n"
                f"ऑफिस से आपकी वर्तमान दूरी: {distance:.

Back 2025.06.30 Donate