女友加班发自拍,男友用几行代码发现惊天秘密...
Python涨薪研究所
共 7616字,需浏览 16分钟
·
2021-06-14 09:08
真实案例
代码验证
exifread
。pip3 install exifread
tags = exifread.process_file(f)
def extract_image(pic_path):
GPS = {}
date = ''
with open(pic_path, 'rb') as f:
tags = exifread.process_file(f)
for tag, value in tags.items():
# 纬度
if re.match('GPS GPSLatitudeRef', tag):
GPS['GPSLatitudeRef'] = str(value)
# 经度
elif re.match('GPS GPSLongitudeRef', tag):
GPS['GPSLongitudeRef'] = str(value)
# 海拔
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'] = convert_coor(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'] = convert_coor(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}
API
来反解坐标了。通过baidu Map的API将GPS信息转换成地址
def find_address_from_bd(GPS):
secret_key = 'wLyevcXk5QY36hTKmvV5350F'
if not GPS['GPS_information']:
return '该照片无GPS信息'
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)
content = response.text.replace("renderReverse&&renderReverse(", "")[:-1]
baidu_map_address = json.loads(content)
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
secret_key
放进去就可以,上面是我的 key ,如果你不想麻烦,可以用我的试试。拍摄时间:2021:05:20 19:33:20
照片拍摄地址:('湖北省武汉市洪山区雄楚大道1070', '湖北省', '武汉市', '洪山区', '立顿酒店-金俊花园东南130米')
总结
好文推荐
施一公:清华70%至80%的高考状元去哪儿了?我认为出了大问题
月薪9万的前员工被查出学历造假,公司要求返还30万,法院判了
国家放开三孩,程序员划水群沸腾了,大家多保重
一键三连「分享」、「点赞」和「在看」
技术干货与你天天见~
评论