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

Reduce API calls by downloading avatars directly #7

Closed ask0n closed 2 months ago

ask0n commented 2 months ago

Updated version of https://github.com/IvanGlinkin/CCTV/pull/1 Generated output looks pretty the same to the original code: image

TODO: discovered a rate-limiting on https://t.me too, for some existent avatars it doesn't show them on a first pass

IvanGlinkin commented 2 months ago

ok, let's try this one while everyone is sleeping ;)

IvanGlinkin commented 2 months ago

Man) reverted back once again) idk why, but your collection isn't fully correct. check my output by coordinates Latitude: 25.07841, Longitude: 55.13536

Screenshot 2024-05-03 at 00 46 18

yours is the next

Screenshot 2024-05-03 at 00 47 56

also, I fixed an arisen mistake

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/parallels/Desktop/CCTV/start.py", line 107, in <module>
    pring_city_by_geo(latitude,longitude)
  File "/home/parallels/Desktop/CCTV/backend/banners.py", line 31, in pring_city_by_geo
    town, city, country = get_location_details(lat, lon)
  File "/home/parallels/Desktop/CCTV/backend/functions.py", line 71, in get_location_details
    data = response.json()
  File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

to solve it, need to adjust function.py file (add header - User Agent)

# Get the city based on coordinates
def get_location_details(latitude, longitude):
    url = f"https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json"
    headers = {
    'User-Agent': 'CCTV Bot'
    }
    response = get(url, headers=headers)
    data = response.json()
    if 'address' in data:
        town = data['address'].get('town', '')
        city = data['address'].get('city', '')
        country = data['address'].get('country', '')
        return town, city, country
    else:
        return None, None, None
ask0n commented 2 months ago

Man) reverted back once again) idk why, but your collection isn't fully correct.

This can be caused by actual timeouts between steps. Original script consumes extra time while it downloads avatars from TG with client.download_profile_photo. It looks like actual timesleep is always more than configured 30 seconds. I noticed that if this timeout is too short telegram can just return previous values for the request with different coordinates. That's why I introduced speed_kmh variable to try to guess how fast this functionality is actually allowed to change coordinates. With a small timesleep returned data from TG looks even worse, this parameter directly influence data we get from TG :)

IvanGlinkin commented 2 months ago

correct, i noticed that as well during my developing hence i put timesleep. your idea is brilliant with speed, really liked that. your suggestion could be true regarding short duration between shots. try to increase by 45-50 seconds...

Nevertheless, how can we implement only next features right now:

p.s. idk why, but when i merge the branches you are not showing as contributor ( whan can i do to fix it. text me to TG