My girlfriend worked overtime in the middle of the night and took selfie. My python boyfriend found a shocking secret with 30 lines of code

Posted by beyzad on Wed, 15 Dec 2021 15:33:15 +0100

it happened like this

The little brother of python development who is preparing to leave work

I got a call from my girlfriend to work overtime tonight

And send him a self photo with a blurred background

As follows ↓↓

The sensitive little brother is suspicious. Will there be a forgiveness cap
Then python ran a code analysis photo

Analysis emmm

The shooting address is actually XXX Hotel

When the little brother collapsed, he shouted that he had been deceived

python analysis photos

The little brother will download the original photo sent to him
And wrote a script in python
Read the detailed address of the photo taken
Detailed to the specific street and hotel name

Introduce exifred module

First, install the exifrad module of python for photo analysis

PIP install exifred module

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

GPS longitude and latitude information

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

Including shooting time, extremely accurate and specific GPS information.

The following is to read the longitude and latitude information in the photo through the exifrad module.

#Read GPS longitude and latitude 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 tags.items():
            #latitude
            if re.match('GPS GPSLatitudeRef', tag):
                GPS['GPSLatitudeRef'] = str(value)
            #longitude
            elif re.match('GPS GPSLongitudeRef', tag):
                GPS['GPSLongitudeRef'] = str(value)
            #altitude
            elif re.match('GPS GPSAltitudeRef', tag):
                GPS['GPSAltitudeRef'] = str(value)
            elif re.match('GPS GPSLatitude', tag):
                try:
                    match_result = re.match('\[(\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 = [x.replace(' ', '') for x in str(value)[1:-1].split(',')]
                    GPS['GPSLatitude'] = latitude_and_longitude_convert_to_decimal_system(deg, min, sec)
            elif re.match('GPS GPSLongitude', tag):
                try:
                    match_result = re.match('\[(\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 = [x.replace(' ', '') for x in str(value)[1:-1].split(',')]
                    GPS['GPSLongitude'] = latitude_and_longitude_convert_to_decimal_system(deg, min, sec)
            elif re.match('GPS GPSAltitude', tag):
                GPS['GPSAltitude'] = str(value)
            elif re.match('.*Date.*', tag):
                date = str(value)
    return {'GPS_information': GPS, 'date_information': date}

Baidu API transfers GPS to address

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

Here, you need an ak value to call Baidu API, which can be obtained by registering a Baidu developer. Of course, you can also use the ak value of the blogger

After calling, you can resolve the shooting time and shooting detailed address.

def find_address_from_GPS(GPS):
    secret_key = 'zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf'
    if not GPS['GPS_information']:
        return 'This photo has no GPS information'
    #Longitude and latitude information
    lat, lng = GPS['GPS_information']['GPSLatitude'], GPS['GPS_information']['GPSLongitude']
    baidu_map_api = "http://api.map.baidu.com/geocoder/v2/?ak={0}&callback=renderReverse&location={1},{2}s&output=json&pois=0".format(
        secret_key, lat, lng)
    response = requests.get(baidu_map_api)
    #Convert Baidu API to specific address
    content = response.text.replace("renderReverse&&renderReverse(", "")[:-1]
    print(content)
    baidu_map_address = json.loads(content)
    #Parse and sort out 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:/Girlfriend selfie.jpg')
    address = find_address_from_GPS(GPS=GPS_info)
    print("Shooting time:" + GPS_info.get("date_information"))
    print('Photo shooting address:' + str(address))

Lao Wang got this result

Photo shooting address: ('Mile County, Honghe Hani and Yi Autonomous Prefecture, Yunnan Province', 'Yunnan Province', 'Honghe Hani and Yi Autonomous Prefecture', 'Mile County', 'Lake Spring Hotel - 128 meters southeast of block A')

Maitreya Lake Spring Hotel in Yunnan is obviously not where Lao Wang's girlfriend works. Lao Wang searched and found that this is a hot spring resort hotel.

I immediately understood

{"status":0,"result":{"location":{"lng":103.41424699999998,"lat":24.410461020097278},
"formatted_address":"Mile County, Honghe Hani and Yi Autonomous Prefecture, Yunnan Province",
"business":"",
"addressComponent":{"country":"China",
"country_code":0,
"country_code_iso":"CHN",
"country_code_iso2":"CN",
"province":"Yunnan Province",
"city":"Honghe Hani and Yi Autonomous Prefecture",
"city_level":2,"district":"Maitreya county",
"town":"","town_code":"","adcode":"532526",
"street_number":"",
"direction":"","distance":""},
"sematic_description":"Huquan Hotel-A 128 meters southeast of block",
"cityCode":107}}

Shooting time: 2021:5:03 20:05:32
 Photo shooting address:('Mile County, Honghe Hani and Yi Autonomous Prefecture, Yunnan Province', 'Yunnan Province', 'Honghe Hani and Yi Autonomous Prefecture', 'Maitreya county', 'Huquan Hotel-A 128 meters southeast of block')

👉 Python learning route summary 👈

The technical points in all directions of Python are sorted out to form a summary of knowledge points in various fields. Its usefulness is that you can find corresponding learning resources according to the above knowledge points to ensure that you learn more comprehensively.

>>> 🎁 Python essential development tools<<<

Warm tip: the space is limited. The folder has been packaged. The way to obtain it is at the end of the text

👉 Python essential development tools 👈

👉 Excellent Python learning books 👈

When I learn a certain foundation and have my own understanding ability, I will read some books or handwritten notes compiled by my predecessors. These notes record their understanding of some technical points in detail. These understandings are unique and can learn different ideas

👉 Python learning video 600 collection 👈

Watching zero basic learning video is the quickest and most effective way to learn. It's still easy to get started with the teacher's ideas in the video from basic to in-depth.

👉 Actual combat cases 👈

Optical theory is useless. We should learn to knock together and practice, so as to apply what we have learned to practice. At this time, we can make some practical cases to learn.

👉 100 Python exercises 👈

Check the learning results.

👉 Interview questions 👈

Final ending

In addition to writing code, programmers will not be manual workers if they go to the factory. They know technology and can also have a post of technology R & D. The biggest problem is psychological. From a well-known company in the past to the current factory, it would be good if we passed this pass.

According to the data of the National Bureau of statistics, from January to October this year, the profits of Industrial Enterprises above designated size increased by 42.2% year-on-year. In October, the added value of high-tech manufacturing above designated size increased by 14.7% year-on-year. These young people also see the future of China's manufacturing development.

Big factories are only an experience of that year, and there will certainly be variables in the future. Now the iron rice bowl is becoming more and more popular. As long as the income is stable, it was normal to work overtime in big factories in the past. Now the work content and intensity of the factory are OK, which can be considered and accepted

Topics: Python Back-end