SoFunction
Updated on 2024-11-07

Girlfriend works overtime in the middle of the night and sends selfies python boyfriend discovers a shocking secret with 30 lines of code

Here's the thing.

The python developer who is getting ready to leave work.

I got a call from my girlfriend that she's working late tonight.

And sent him a selfie with a blurry background

As follows ↓ ↓ ↓

The sensitive little brother was suspicious, could there be a forgiveness hat

And then python jacked up some code to analyze the photos.

Analyze it, emm.

It's actually at the XXX Hotel.

The youngest brother was devastated and said he'd been duped.

python analyze photos

The youngest brother downloaded the original image of the photo sent to him

and wrote a script using python

Read the details of the address where the photo was taken.

Detailed to the point of specific streets and hotel names

Introduction of the exifread module

First install the exifread module for python for photo analysis

pip install exifread Install exfriead module

PS C:\WINDOWS\system32> pip install exifread
Collecting exifread
  Downloading ExifRead-2.3. (38 kB)
Installing collected packages: exifread
Successfully installed exifread-2.3.2
PS C:\WINDOWS\system32> pip install json

GPS latitude and longitude information

In fact, there is a lot of private information hidden in the photos we usually take

Includes time of day, extremely accurate and specific GPS information.

Here is the exifread module to read the latitude and longitude information within the photo.

#Read GPS latitude and longitude information of photos
def find_GPS_image(pic_path):
    GPS = {}
    date = ''
    with open(pic_path, 'rb') as f:
        tags = exifread.process_file(f)
        for tag, value in ():
            #Latitude
            if ('GPS GPSLatitudeRef', tag):
                GPS['GPSLatitudeRef'] = str(value)
            # Longitude
            elif ('GPS GPSLongitudeRef', tag):
                GPS['GPSLongitudeRef'] = str(value)
            # Altitude
            elif ('GPS GPSAltitudeRef', tag):
                GPS['GPSAltitudeRef'] = str(value)
            elif ('GPS GPSLatitude', tag):
                try:
                    match_result = ('\[(\w*),(\w*),(\w.*)/(\w.*)\]', str(value)).groups()
                    GPS['GPSLatitude'] = int(match_result[0]), int(match_result[1]), int(match_result[2])
                except:
                    deg, min, sec = [(' ', '') for x in str(value)[1:-1].split(',')]
                    GPS['GPSLatitude'] = latitude_and_longitude_convert_to_decimal_system(deg, min, sec)
            elif ('GPS GPSLongitude', tag):
                try:
                    match_result = ('\[(\w*),(\w*),(\w.*)/(\w.*)\]', str(value)).groups()
                    GPS['GPSLongitude'] = int(match_result[0]), int(match_result[1]), int(match_result[2])
                except:
                    deg, min, sec = [(' ', '') for x in str(value)[1:-1].split(',')]
                    GPS['GPSLongitude'] = latitude_and_longitude_convert_to_decimal_system(deg, min, sec)
            elif ('GPS GPSAltitude', tag):
                GPS['GPSAltitude'] = str(value)
            elif ('.*Date.*', tag):
                date = str(value)
    return {'GPS_information': GPS, 'date_information': date}

Baidu API will GPS to address

Here you need to use the call to Baidu API to convert GPS latitude and longitude information into specific address information.

Here, you need an ak value to call the Baidu API, this can be obtained by registering a Baidu developer.

Of course, you can also use this ak from the blogger

Once called, you can parse out the shooting time and shooting details.

def find_address_from_GPS(GPS):
    secret_key = 'zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf'
    if not GPS['GPS_information']:
        return 'No GPS information for this photo'
    # Longitude and latitude information
    lat, lng = GPS['GPS_information']['GPSLatitude'], GPS['GPS_information']['GPSLongitude']
    baidu_map_api = "/geocoder/v2/?ak={0}&callback=renderReverse&location={1},{2}s&output=json&pois=0".format(
        secret_key, lat, lng)
    response = (baidu_map_api)
    #Baidu API converted to a specific address
    content = ("renderReverse&&renderReverse(", "")[:-1]
    print(content)
    baidu_map_address = (content)
    # Parsing and organizing the returned json information
    formatted_address = baidu_map_address["result"]["formatted_address"]
    province = baidu_map_address["result"]["addressComponent"]["province"]
    city = baidu_map_address["result"]["addressComponent"]["city"]
    district = baidu_map_address["result"]["addressComponent"]["district"]
    location = baidu_map_address["result"]["sematic_description"]
    return formatted_address,province,city,district,location
 
if __name__ == '__main__':
    GPS_info = find_GPS_image(pic_path='C:/girlfriendselfie.jpg')
    address = find_address_from_GPS(GPS=GPS_info)
    print("Shooting time:" + GPS_info.get("date_information"))
    print('Photo Shooting:' + str(address))

The Python guy got this result

Photo shooting address:('XXXXXXXX County, Yunnan Province', 'Yunnan Province', 'XXXX City', 'XXX County', 'XXXX Hotel')

Yunnan Mile XXXX Hotel, which is clearly not where Lao Wang's girlfriend works

Little brother searched and it was a spa resort.

It was a moment of clarity.

Full Code:Click here to download

To this article on the girlfriend in the middle of the night to work overtime to send a selfie python boyfriend with 30 lines of code to discover the shocking secret of the article is introduced to this, more related python read GPS content, please search for my previous articles or continue to browse the following related articles I hope that you will support me in the future more!