程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

She said she worked overtime at night and was ruthlessly exposed by a piece of Python code

編輯:Python

Here's the thing

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

python Analyze photos

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

introduce exifread modular

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

Latitude and longitude information

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}

Baidu API take GPS transformation

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))

Python The result is like this

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')

Complete code

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved