IvanGlinkin / CCTV

Close-Circuit Telegram Vision revolutionizes location tracking with its open-source design and Telegram API integration. Offering precise tracking within 50-100 meters, users can monitor others in real-time for logistics or safety, redefining how we navigate our surroundings
GNU General Public License v3.0
2.31k stars 319 forks source link

'PeerSelfLocated' object has no attribute 'distance' #12

Closed lucas-strummer closed 2 months ago

lucas-strummer commented 2 months ago

After successfully adding my coordinates (I'm hiding them unless necessary, but they are well-located) and logging into Telegram through the app, I get the following error:

[ * ] Harvesting information based on the next coordinates:
        [ * * ] Latitude:  -34.XXX
        [ * * ] Longitude: -58.XXXX
        [ * * ] Country:   Argentina
        [ * * ] City:      [Hidden]
        [ * * ] Town:      

[ * ] Overall steps to be performed: 25 , with overall diameter 2000 meters

[ * ] Telegram client initialization...successfully

[ * ] Start harvesting data:
        [ 1 ] Latitude -34.XXXX, Longitude -58.XXXX
Traceback (most recent call last):
  File "/home/lucas/CCTV/start.py", line 156, in <module>
    if peer_located.distance == 500:
       ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PeerSelfLocated' object has no attribute 'distance'

Thanks in advance!

IvanGlinkin commented 2 months ago

hey man. don't know, everything is working fine from my side with the latest updates (git clone) try to get the repository once again and install all of the necessary libraries using the instruction on the main github page

Screenshot 2024-05-03 at 23 09 16
maaxx0 commented 2 months ago

i have same error :

**Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/gehrman/Downloads/CCTV-main/start.py", line 174, in <module>
    if peer_located.distance == 500:
       ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PeerSelfLocated' object has no attribute 'distance**
IvanGlinkin commented 2 months ago

hm, seems like it's mass issue. let me see and come back

IvanGlinkin commented 2 months ago

It seems like there's an error because the code is expecting the distance attribute, but the object being processed is of type PeerSelfLocated, which doesn't have that attribute. To fix this, we need to handle the case when the update is of type PeerSelfLocated. Here's the modified code:

for update in result.updates:
    if isinstance(update, types.UpdatePeerLocated):
        for peer_located in update.peers:
            if isinstance(peer_located, types.PeerLocated):  # Check if the peer_located is of type PeerLocated
                if peer_located.distance == 500:
                    if isinstance(peer_located.peer, types.PeerUser):  # Check if the peer is a PeerUser
                        user_id = peer_located.peer.user_id
                        user_info = next((user for user in result.users if user.id == user_id), None)
                        if user_info:
                            # Get current timestamp
                            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

                            if user_id not in users_data:
                                # If the user is not in the dictionary, add them with initial data
                                username = user_info.username

                                users_data[user_id] = {
                                    "first_name": user_info.first_name,
                                    "last_name": user_info.last_name,
                                    "username": user_info.username,
                                    "phone": user_info.phone,
                                    "photo_id": user_info.photo.photo_id if user_info.photo else None,
                                    "coordinates": [],
                                    "coordinates_average": {"latitude": 0, "longitude": 0, "timestamp": 0}
                                }
                            # Append new coordinates
                            users_data[user_id]["coordinates"].append((latitude, longitude, timestamp))

                            # Calculate average coordinates
                            avg_latitude = sum(coord[0] for coord in users_data[user_id]["coordinates"]) / len(users_data[user_id]["coordinates"])
                            avg_longitude = sum(coord[1] for coord in users_data[user_id]["coordinates"]) / len(users_data[user_id]["coordinates"])

                            # Update the average coordinates
                            users_data[user_id]["coordinates_average"] = {"latitude": avg_latitude, "longitude": avg_longitude}

nevertheless, the Repository has been updated, so you can just git clone again please let me know if the issue is fixed

maaxx0 commented 2 months ago

Worked as rocket image

IvanGlinkin commented 2 months ago

great man) congrats :) any feedback regarding the application?)