Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lucas-strummer opened this issue May 3, 2024 · 6 comments
Closed

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

lucas-strummer opened this issue May 3, 2024 · 6 comments

Comments

@lucas-strummer
Copy link

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
Copy link
Owner

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
Copy link

maaxx0 commented May 4, 2024

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
Copy link
Owner

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

@IvanGlinkin
Copy link
Owner

IvanGlinkin commented May 4, 2024

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
Copy link

maaxx0 commented May 4, 2024

Worked as rocket
image

@IvanGlinkin
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants