Skip to content

Commit 8ca09d5

Browse files
committed
提交代码
1 parent 014405f commit 8ca09d5

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

xianhuan/.DS_Store

6 KB
Binary file not shown.

xianhuan/picinfo/picinfo.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
import json
4+
import re
5+
6+
import exifread
7+
import requests
8+
9+
10+
#转换经纬度格式
11+
def convert_coor(*arg):
12+
return float(arg[0]) + ((float(arg[1]) + (float(arg[2].split('/')[0]) / float(arg[2].split('/')[-1]) / 60)) / 60)
13+
14+
# 读取照片的GPS经纬度信息
15+
def extract_image(pic_path):
16+
GPS = {}
17+
date = ''
18+
with open(pic_path, 'rb') as f:
19+
tags = exifread.process_file(f)
20+
for tag, value in tags.items():
21+
# 纬度
22+
if re.match('GPS GPSLatitudeRef', tag):
23+
GPS['GPSLatitudeRef'] = str(value)
24+
# 经度
25+
elif re.match('GPS GPSLongitudeRef', tag):
26+
GPS['GPSLongitudeRef'] = str(value)
27+
# 海拔
28+
elif re.match('GPS GPSAltitudeRef', tag):
29+
GPS['GPSAltitudeRef'] = str(value)
30+
elif re.match('GPS GPSLatitude', tag):
31+
try:
32+
match_result = re.match('\[(\w*),(\w*),(\w.*)/(\w.*)\]', str(value)).groups()
33+
GPS['GPSLatitude'] = int(match_result[0]), int(match_result[1]), int(match_result[2])
34+
except:
35+
deg, min, sec = [x.replace(' ', '') for x in str(value)[1:-1].split(',')]
36+
GPS['GPSLatitude'] = convert_coor(deg, min, sec)
37+
elif re.match('GPS GPSLongitude', tag):
38+
try:
39+
match_result = re.match('\[(\w*),(\w*),(\w.*)/(\w.*)\]', str(value)).groups()
40+
GPS['GPSLongitude'] = int(match_result[0]), int(match_result[1]), int(match_result[2])
41+
except:
42+
deg, min, sec = [x.replace(' ', '') for x in str(value)[1:-1].split(',')]
43+
GPS['GPSLongitude'] = convert_coor(deg, min, sec)
44+
elif re.match('GPS GPSAltitude', tag):
45+
GPS['GPSAltitude'] = str(value)
46+
elif re.match('.*Date.*', tag):
47+
date = str(value)
48+
return {'GPS_information': GPS, 'date_information': date}
49+
50+
51+
# 通过baidu Map的API将GPS信息转换成地址
52+
def find_address_from_bd(GPS):
53+
secret_key = 'wLyevcXk5QY36hTKmvV5350F'
54+
if not GPS['GPS_information']:
55+
return '该照片无GPS信息'
56+
lat, lng = GPS['GPS_information']['GPSLatitude'], GPS['GPS_information']['GPSLongitude']
57+
baidu_map_api = "http://api.map.baidu.com/geocoder/v2/?ak={0}&callback=renderReverse&location={1},{2}s&output=json&pois=0".format(
58+
secret_key, lat, lng)
59+
response = requests.get(baidu_map_api)
60+
content = response.text.replace("renderReverse&&renderReverse(", "")[:-1]
61+
baidu_map_address = json.loads(content)
62+
formatted_address = baidu_map_address["result"]["formatted_address"]
63+
province = baidu_map_address["result"]["addressComponent"]["province"]
64+
city = baidu_map_address["result"]["addressComponent"]["city"]
65+
district = baidu_map_address["result"]["addressComponent"]["district"]
66+
location = baidu_map_address["result"]["sematic_description"]
67+
return formatted_address, province, city, district, location
68+
69+
70+
if __name__ == '__main__':
71+
gpsinfo = extract_image(pic_path='/Users/xxx/Pictures/66.jpg')
72+
address = find_address_from_bd(GPS=gpsinfo)
73+
print(gpsinfo)
74+
print("拍摄时间:" + gpsinfo.get("date_information"))
75+
print('照片拍摄地址:' + str(address))

xianhuan/wbpic/wbpic.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: 闲欢
5+
"""
6+
7+
import requests
8+
import re
9+
import os
10+
import time
11+
cookie = {
12+
'Cookie': 'your cookie'
13+
}
14+
header = {
15+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4144.2 Safari/537.36'
16+
}
17+
get_order = input('是否启动程序? yes or no: ')
18+
number = 1
19+
store_path = 'your path'
20+
while True:
21+
if get_order != 'no':
22+
print('抓取中......') # 下面的链接填写微博搜索的链接
23+
url = f'https://s.weibo.com/weibo?q=%23%E5%B0%91%E5%A5%B3%E5%86%99%E7%9C%9F%23&wvr=6&b=1&Refer=SWeibo_box&page={number}'
24+
response = requests.get(url, cookies=cookie)
25+
result = response.text
26+
print(result)
27+
detail = re.findall('data="uid=(.*?)&mid=(.*?)&pic_ids=(.*?)">', result)
28+
for part in detail:
29+
uid = part[0]
30+
mid = part[1]
31+
pids = part[2]
32+
for picid in pids.split(','):
33+
url_x = f'https://wx1.sinaimg.cn/large/%s.jpg'%picid # 这里就是大图链接了
34+
response_photo = requests.get(url_x, headers=header)
35+
file_name = url_x[-10:]
36+
if not os.path.exists(store_path+uid):
37+
os.mkdir(store_path+uid)
38+
with open(store_path+uid + '/' + file_name, 'ab') as f: # 保存文件
39+
f.write(response_photo.content)
40+
time.sleep(0.5)
41+
print('获取完毕')
42+
get_order = input('是否继续获取下一页? Y:yes N:no: ')
43+
if get_order != 'no':
44+
number += 1
45+
else:
46+
print('程序结束')
47+
break
48+
else:
49+
print('程序结束')
50+
break

0 commit comments

Comments
 (0)