I'm getting ready for work python Develop little brother
I got a call from my girlfriend that she's going to work overtime tonight
And send him a self portrait with a blurred background
as follows ↓ ↓ ↓
alive python The little elder brother My heart is tight
Is there a cap of forgiveness
Turn off the live broadcast of Peppa Pig , He rolled his hands for a while python Code
Analyze it emmm
The shooting address is actually XXX Hotel
When my little brother collapsed Yell out for being cheated
The little brother will download the original picture of himself
And use python I wrote a script
Read the detailed information of the photo taken
Detailed to specific hotel
First installation python Of exifread modular , For photo analysis
pip install exifread install exfriead modular
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
In fact, the pictures we usually take
Hiding a lot of information
Include Shooting time 、 Extremely accurate
Specific address information .
Here is the passage exifread modular
To read the latitude and longitude information in the photo
# How to read photos GPS Latitude and longitude information
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)
# At an altitude of
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}
Here you need to call Baidu API
take GPS The longitude and latitude information is converted into specific information
here , You need a call to Baidu API Of ak value
This can be registered as a Baidu developer to get
Of course , You can also use the blogger's ak
After call , You can change the shooting time
All the shooting details are resolved .
def find_address_from_GPS(GPS):
secret_key = ' Their own key'
if not GPS['GPS_information']:
return ' There is no GPS Information '
# Latitude and longitude 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)
# Baidu API Translate to a specific address
content = response.text.replace("renderReverse&&renderReverse(", "")[:-1]
print(content)
baidu_map_address = json.loads(content)
# Will return json The information is analyzed and sorted out
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:/ Self portrait of my girlfriend .jpg')
address = find_address_from_GPS(GPS=GPS_info)
print(" Shooting time :" + GPS_info.get("date_information"))
print(' Photo shooting :' + str(address))
Photo shooting address :('XX province
XXXXXXX county ',
'XX province ', 'XXXX City ', 'XXX county ',
'XXXX')
XXXXXX A holiday Hotel,
This is obviously not where your girlfriend works
The little brother searched
This is a hot spring resort Hotel.
It immediately became clear that
{"status":0,"result":{"location":{"lng": longitude ,"lat": latitude },
"formatted_address":"XX province XXXXXXXX county ",
"business":"",
"addressComponent":{"country":"China",
"country_code":0,
"country_code_iso":"CHN",
"country_code_iso2":"CN",
"province":"XX province ",
"city":"XXXXX City ",
"city_level":2,"district":XXX county ",
"town":"","town_code":"","adcode":"XXXXX",
"street_number":"",
"direction":"","distance":""},
"sematic_description":"XXXXX",
"cityCode":107}}
Shooting time :2021:5:03 20:05:32
Photo shooting address :('XX province XXXXXXX county ', 'XX province ', 'XXXX City ', 'XXX county ', 'XXXXX')
python Determine the exact location of the photo complete code script _Python Mobile phone setting -Python Document resources -CSDN download https://download.csdn.net/download/weixin_42350212/19776215