IvanGlinkin/CCTV

'PeerSelfLocated' object has no attribute 'distance'

lucas-strummer opened this issue · 6 comments

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!

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

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**

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

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

Worked as rocket
image

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